Skip to content

Commit

Permalink
feat(editor): add 'open website' block
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 committed Sep 30, 2021
1 parent e2f54b6 commit c81e53b
Show file tree
Hide file tree
Showing 13 changed files with 433 additions and 420 deletions.
54 changes: 27 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,56 +24,56 @@
"@vuex-orm/core": "^0.36.4",
"dayjs": "^1.10.7",
"drawflow": "^0.0.49",
"nanoid": "^3.1.25",
"nanoid": "3.1.28",
"tiny-emitter": "^2.1.0",
"tippy.js": "^6.3.1",
"v-remixicon": "^0.1.1",
"vue": "^3.2.11",
"vue": "3.2.19",
"vue-router": "^4.0.11",
"vuedraggable": "^4.1.0",
"vuex": "^4.0.2",
"webext-bridge": "^4.1.1",
"webext-bridge": "5.0.0",
"webextension-polyfill": "^0.8.0"
},
"devDependencies": {
"@babel/core": "^7.12.17",
"@babel/eslint-parser": "^7.15.4",
"@babel/plugin-proposal-class-properties": "^7.12.13",
"@babel/preset-env": "^7.12.17",
"@vue/compiler-sfc": "^3.2.11",
"autoprefixer": "^10.3.4",
"@babel/core": "7.15.5",
"@babel/eslint-parser": "7.15.7",
"@babel/plugin-proposal-class-properties": "7.14.5",
"@babel/preset-env": "7.15.6",
"@vue/compiler-sfc": "3.2.19",
"autoprefixer": "10.3.6",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.2",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^7.0.0",
"clean-webpack-plugin": "4.0.0",
"copy-webpack-plugin": "9.0.1",
"core-js": "3",
"css-loader": "^5.0.2",
"eslint": "^7.20.0",
"css-loader": "5.2.7",
"eslint": "7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-friendly-formatter": "^4.0.1",
"eslint-import-resolver-webpack": "^0.13.1",
"eslint-plugin-flowtype": "^5.2.2",
"eslint-plugin-flowtype": "6.1.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-vue": "^7.17.0",
"eslint-plugin-vue": "7.18.0",
"file-loader": "^6.2.0",
"fs-extra": "^9.1.0",
"html-loader": "^2.1.0",
"html-webpack-plugin": "^5.2.0",
"fs-extra": "10.0.0",
"html-loader": "2.1.2",
"html-webpack-plugin": "5.3.2",
"lint-staged": "^11.1.2",
"mini-css-extract-plugin": "^2.3.0",
"postcss": "^8.3.6",
"postcss": "8.3.8",
"postcss-loader": "^6.1.1",
"prettier": "^2.4.1",
"simple-git-hooks": "^2.6.1",
"source-map-loader": "^2.0.1",
"style-loader": "^2.0.0",
"tailwindcss": "^2.2.15",
"terser-webpack-plugin": "^5.1.1",
"vue-loader": "^16.5.0",
"webpack": "^5.23.0",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.11.2"
"source-map-loader": "3.0.0",
"style-loader": "3.3.0",
"tailwindcss": "2.2.16",
"terser-webpack-plugin": "5.2.4",
"vue-loader": "16.8.1",
"webpack": "5.55.1",
"webpack-cli": "4.8.0",
"webpack-dev-server": "3.11.2"
}
}
5 changes: 3 additions & 2 deletions src/assets/css/drawflow.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.drawflow-node.selected .menu {
@apply translate-y-16;
.drawflow-node.selected .menu,
.drawflow-node .block-base:hover .menu {
@apply translate-y-11;
}

.drawflow .drawflow-node.comparison .outputs {
Expand Down
94 changes: 26 additions & 68 deletions src/components/block/BlockBase.vue
Original file line number Diff line number Diff line change
@@ -1,89 +1,47 @@
<template>
<div :id="componentId" class="group relative">
<div class="block-base relative">
<div
class="
z-10
flex
items-center
bg-white
relative
rounded-lg
overflow-hidden
p-4
"
:class="contentClass"
class="z-10 bg-white relative rounded-lg overflow-hidden w-full p-4"
>
<span
:class="block.category.color"
class="inline-block p-2 mr-2 rounded-lg bg-green-200"
>
<v-remixicon :path="icons[block.details.icon] || icons.riGlobalLine" />
</span>
<div style="max-width: 200px">
<p class="font-semibold leading-none whitespace-nowrap">
{{ block.details.name }}
</p>
<p class="text-gray-600 text-overflow leading-tight">
{{ block.data.description }}
</p>
<input
type="text"
class="hidden trigger"
disabled="true"
@change="handleDataChange"
/>
</div>
<slot></slot>
</div>
<div
class="
absolute
top-0
transition-transform
duration-300
group-hover:translate-y-16
pt-4
ml-1
menu
"
class="absolute bottom-0 transition-transform duration-300 pt-4 ml-1 menu"
>
<div class="bg-accent px-4 py-2 text-white rounded-lg flex items-center">
<button class="-ml-1" @click="editBlock">
<div class="bg-accent px-3 py-2 text-white rounded-lg flex items-center">
<button v-if="!hideEdit" @click="$emit('edit')">
<v-remixicon size="20" :path="icons.riPencilLine" />
</button>
<hr class="border-r border-gray-600 h-5 mx-3" />
<button class="-mr-1" @click="editor.removeNodeId(`node-${block.id}`)">
<hr
v-if="!hideDelete && !hideEdit"
class="border-r border-gray-600 h-5 mx-3"
/>
<button v-if="!hideDelete" @click="$emit('delete')">
<v-remixicon size="20" :path="icons.riDeleteBin7Line" />
</button>
<slot name="action" />
</div>
</div>
</div>
</template>
<script setup>
import { VRemixIcon as VRemixicon } from 'v-remixicon';
import emitter from 'tiny-emitter/instance';
import { icons } from '@/lib/v-remixicon';
import { useEditorBlock } from '@/composable/editorBlock';
import { useComponentId } from '@/composable/componentId';
const props = defineProps({
editor: {
type: Object,
default: () => ({}),
defineProps({
hideDelete: {
type: Boolean,
default: false,
},
hideEdit: {
type: Boolean,
default: false,
},
contentClass: {
type: String,
default: '',
},
});
const componentId = useComponentId('block-base');
const block = useEditorBlock(`#${componentId}`, props.editor);
function editBlock() {
emitter.emit('editor:edit-block', {
...block.details,
data: block.data,
blockId: block.id,
});
}
function handleDataChange() {
const { data } = props.editor.getNodeFromId(block.id);
block.data = data;
}
defineEmits(['delete', 'edit']);
</script>
60 changes: 60 additions & 0 deletions src/components/block/BlockBasic.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<template>
<block-base
:id="componentId"
content-class="flex items-center"
@edit="editBlock"
@delete="editor.removeNodeId(`node-${block.id}`)"
>
<span
:class="block.category.color"
class="inline-block p-2 mr-2 rounded-lg bg-green-200"
>
<v-remixicon :path="icons[block.details.icon] || icons.riGlobalLine" />
</span>
<div style="max-width: 200px">
<p class="font-semibold leading-none whitespace-nowrap">
{{ block.details.name }}
</p>
<p class="text-gray-600 text-overflow leading-tight">
{{ block.data.description }}
</p>
<input
type="text"
class="hidden trigger"
disabled="true"
@change="handleDataChange"
/>
</div>
</block-base>
</template>
<script setup>
import { VRemixIcon as VRemixicon } from 'v-remixicon';
import emitter from 'tiny-emitter/instance';
import { icons } from '@/lib/v-remixicon';
import { useEditorBlock } from '@/composable/editorBlock';
import { useComponentId } from '@/composable/componentId';
import BlockBase from './BlockBase.vue';
const props = defineProps({
editor: {
type: Object,
default: () => ({}),
},
});
const componentId = useComponentId('block-base');
const block = useEditorBlock(`#${componentId}`, props.editor);
function editBlock() {
emitter.emit('editor:edit-block', {
...block.details,
data: block.data,
blockId: block.id,
});
}
function handleDataChange() {
const { data } = props.editor.getNodeFromId(block.id);
block.data = data;
}
</script>
8 changes: 4 additions & 4 deletions src/components/block/BlockComparison.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :id="componentId" class="p-4">
<div :id="componentId">
<div class="flex items-center">
<div
:class="block.category.color"
Expand Down Expand Up @@ -73,9 +73,9 @@
v-if="block.data.comparison && block.data.comparison.length !== 0"
class="text-right text-gray-600"
>
<span title="Execute when all comparisons don't meet the requirement"
>&#9432;</span
>
<span title="Execute when all comparisons don't meet the requirement">
&#9432;
</span>
Fallback
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/block/BlockDelay.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div :id="componentId" class="p-4">
<div class="flex items-center mb-4">
<div class="flex items-center mb-2">
<div
:class="block.category.color"
class="inline-block text-sm mr-4 p-2 rounded-lg"
Expand Down
61 changes: 61 additions & 0 deletions src/components/block/BlockOpenWebsite.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<template>
<div :id="componentId" class="p-4">
<div class="flex items-center mb-2">
<div
:class="block.category.color"
class="inline-block text-sm mr-4 p-2 rounded-lg"
>
<v-remixicon
:path="icons.riGlobalLine"
size="20"
class="inline-block mr-1"
/>
<span>Open website</span>
</div>
<div class="flex-grow"></div>
<v-remixicon
:path="icons.riDeleteBin7Line"
class="cursor-pointer"
@click="editor.removeNodeId(`node-${block.id}`)"
/>
</div>
<input
:value="block.data.url"
class="px-4 py-2 rounded-lg w-48 bg-input"
placeholder="http://example.com"
type="url"
required
@input="handleInput"
/>
</div>
</template>
<script setup>
import { VRemixIcon as VRemixicon } from 'v-remixicon';
import { icons } from '@/lib/v-remixicon';
import { debounce } from '@/utils/helper';
import { useComponentId } from '@/composable/componentId';
import { useEditorBlock } from '@/composable/editorBlock';
const props = defineProps({
editor: {
type: Object,
default: () => ({}),
},
});
const componentId = useComponentId('open-website');
const block = useEditorBlock(`#${componentId}`, props.editor);
const handleInput = debounce(({ target }) => {
target.reportValidity();
const res = target.value.match(
/* eslint-disable-next-line */
/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g
);
if (!res) return;
props.editor.updateNodeDataFromId(block.id, { url: res[0] });
}, 250);
</script>
2 changes: 1 addition & 1 deletion src/components/newtab/workflow/WorkflowBuilder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default {
300,
'trigger',
{ type: 'manual' },
'BlockBase',
'BlockBasic',
'vue'
);
}
Expand Down
7 changes: 0 additions & 7 deletions src/components/newtab/workflow/WorkflowEditBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
</p>
</div>
<hr class="mb-4 mt-5 w-full border-gray-100" />
<ui-textarea
:model-value="blockData.description"
autoresize
placeholder="Description"
class="w-full mb-2"
@change="$emit('update', { ...blockData, description: $event })"
/>
<component :is="data.editComponent" v-model:data="blockData" />
</div>
</template>
Expand Down
7 changes: 7 additions & 0 deletions src/components/newtab/workflow/edit/EditTrigger.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<template>
<ui-textarea
:model-value="blockData.description"
autoresize
placeholder="Description"
class="w-full mb-2"
@change="updateData({ description: $event })"
/>
<ui-select
:model-value="data.type || 'manual'"
placeholder="Trigger workflow"
Expand Down
Loading

0 comments on commit c81e53b

Please sign in to comment.