forked from AutomaApp/automa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): add 'open website' block
- Loading branch information
Showing
13 changed files
with
433 additions
and
420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,7 @@ export default { | |
300, | ||
'trigger', | ||
{ type: 'manual' }, | ||
'BlockBase', | ||
'BlockBasic', | ||
'vue' | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.