Skip to content

Commit

Permalink
Merge pull request #47 from vangleer/animate
Browse files Browse the repository at this point in the history
chore: fix some ux problem
  • Loading branch information
vangleer authored Jul 24, 2024
2 parents 9818de7 + 3161a05 commit fa8574e
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 17 deletions.
4 changes: 3 additions & 1 deletion packages/common/i18n/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
},
"common": {
"code": "Code",
"editorDemo": "ES Drager Editor"
"editorDemo": "ES Drager Editor",
"copy": "Copy",
"basicDemo": "Basic Demo"
},
"examples": {
"move": "Move",
Expand Down
4 changes: 3 additions & 1 deletion packages/common/i18n/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
},
"common": {
"code": "代码",
"editorDemo": "编辑器案例"
"editorDemo": "编辑器案例",
"copy": "复制",
"basicDemo": "基础案例"
},
"examples": {
"move": "移动",
Expand Down
6 changes: 3 additions & 3 deletions packages/docs/src/components/layout/Header.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="es-header">
<h1 class="es-logo">
<img class="es-logo-img" src="/logo/logo4.png" alt="ES Drager">
<img class="es-logo-img" src="/logo/logo4.png" alt="ES Drager" />
<span @click="router.replace('/')">{{ title }}</span>
</h1>
<slot />
Expand Down Expand Up @@ -67,8 +67,8 @@ watch(
padding: 0 24px;
border-bottom: var(--es-border);
transition:
border-color 0.2s,
background-color 0.2s;
border-color 0.2s,
background-color 0.2s;
.es-logo {
display: flex;
align-items: center;
Expand Down
35 changes: 34 additions & 1 deletion packages/docs/src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@
</div>

<el-drawer v-model="showCode" :title="t('common.code')">
<div
style="
display: flex;
justify-content: space-between;
align-items: center;
"
>
<div />
<el-tooltip :content="t('common.copy')" placement="top">
<el-button
type="text"
:icon="CopyDocument"
@click="copyCode"
style="color: #aabbcc; font-size: 20px"
/>
</el-tooltip>
</div>
<pre><code v-html="codeHtml"></code></pre>
</el-drawer>
</div>
Expand All @@ -58,9 +75,11 @@ import { menuRoutes } from '@/router'
import 'highlight.js/styles/panda-syntax-light.css'
import hljs from 'highlight.js'
import { langs, t, useLocaleStore } from '@es-drager/common/i18n'
import { CopyDocument } from '@element-plus/icons-vue'
import Header from '@/components/layout/Header.vue'
import Aside from '@/components/layout/Aside.vue'
import { ElMessage } from 'element-plus'
const examplesSource = import.meta.glob('../examples/*.vue', {
eager: true,
as: 'raw'
Expand All @@ -69,6 +88,21 @@ const examplesSource = import.meta.glob('../examples/*.vue', {
const router = useRouter()
const route = useRoute()
const useLocale = useLocaleStore()
// copy code set
const copyCode = async () => {
try {
const tempElement = document.createElement('div')
tempElement.innerHTML = codeHtml.value
const plainText = tempElement.innerText
await navigator.clipboard.writeText(plainText)
ElMessage.success('复制成功')
} catch (err) {
ElMessage.error(err as string)
}
}
// set lang
let curLocale = useLocale.locale
let currentLan = ref(langs.find(cur => cur.key === curLocale)?.title || '')
Expand Down Expand Up @@ -187,4 +221,3 @@ watch(
}
}
</style>

22 changes: 17 additions & 5 deletions packages/docs/src/views/editor/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,30 @@
<el-button :icon="item.icon">{{ item.label }}</el-button>
</div>
</div>
<!-- todo -->
<a class="es-header-cube" @click.prevent="router.push('/basic')">{{
t('common.basicDemo')
}}</a>
</Header>
<ESEditor ref="editorRef" :data="data" :theme="appStore.theme" />
</div>
</template>

<script setup lang="ts">
import Header from '@/components/layout/Header.vue'
import { t } from '@es-drager/common/i18n'
import { useAppStore } from '@/store'
import { ESEditor, ToolType, EditorDataType } from '@es-drager/editor'
import { onMounted } from 'vue';
import { onMounted } from 'vue'
import { computed, ref } from 'vue'
import { useRouter } from 'vue-router'
const title = 'ES Drager Editor 开发中...'
const router = useRouter()
// editorRef.value?.getData() // 获取最新数据
const editorRef = ref<InstanceType<typeof ESEditor> | null>(null)
const appStore = useAppStore()
// 初始数据
Expand All @@ -43,7 +51,7 @@ const data = ref<EditorDataType>({
},
elements: [
{
id: '1',
id: 'one',
component: 'div',
width: 100,
height: 100,
Expand All @@ -56,7 +64,7 @@ const data = ref<EditorDataType>({
}
},
{
id: '2',
id: 'two',
component: 'div',
width: 100,
height: 100,
Expand All @@ -71,7 +79,11 @@ const data = ref<EditorDataType>({
]
})
const tools = computed(() => (editorRef.value as any)?.tools || [])
const returnToBasic = () => {
router.push('/basic')
}
const tools = computed(() => [...((editorRef.value as any)?.tools || [])])
function handleToolClick(item: ToolType) {
if (typeof item.handler === 'function') {
Expand Down
5 changes: 4 additions & 1 deletion packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"name": "@es-drager/editor",
"private": true,
"version": "0.0.0",
"type": "module"
"type": "module",
"devDependencies": {
"gsap": "^3.12.5"
}
}
200 changes: 196 additions & 4 deletions packages/editor/src/components/layout/info/Animation.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,204 @@
<template>
<div>
动画
<div class="animation-container">
<div class="animation-options">
<el-radio-group v-model="selectedAnimation" class="animation-radio-group">
<el-radio
v-for="animation in animations"
:key="animation.value"
:label="animation.value"
>
{{ animation.label }}
</el-radio>
</el-radio-group>
<div class="button-group">
<el-button class="action-button" @click="applyAnimation"
>应用动画</el-button
>
<el-button class="action-button danger" @click="stopAnimation"
>停止动画</el-button
>
</div>
</div>
</div>
</template>

<script setup lang='ts'>
<script setup lang="ts">
import { ref } from 'vue'
import gsap from 'gsap'
import { useEditorStore } from '@es-drager/editor/src/store'
const store = useEditorStore()
const applyAnimation = () => {
switch (selectedAnimation.value) {
case 'from':
gsap.from(`#${store.current.id!}`, {
x: 250,
repeat: -1,
yoyo: true,
rotation: 360,
duration: 2,
ease: 'power1.inOut'
})
break
case 'fromTo':
gsap.fromTo(
`#${store.current.id!}`,
{
x: 0,
rotation: 0,
borderRadius: '0%'
},
{
x: 250,
repeat: -1,
yoyo: true,
rotation: 360,
duration: 2,
borderRadius: '100%',
ease: 'bounce.out'
}
)
break
case 'scrollTrigger':
gsap.to(`#${store.current.id!}`, {
x: 150,
rotation: 360,
borderRadius: '100%',
scale: 1.5,
scrollTrigger: {
trigger: `#${store.current.id!}`,
start: 'bottom, bottom',
end: 'top 10%',
scrub: true
},
ease: 'power1.inOut'
})
break
case 'stagger':
gsap.to(`#${store.current.id!}`, {
y: 250,
rotation: 360,
yoyo: true,
repeat: -1,
borderRadius: '100%',
stagger: {
amount: 1.5,
grid: [2, 1],
axis: 'y',
ease: 'circ.inOut',
from: 'center'
}
})
break
case 'to':
gsap.to(`#${store.current.id!}`, {
x: 250,
repeat: -1,
yoyo: true,
rotation: 360,
duration: 2,
ease: 'elastic'
})
break
case 'timeline':
const tl = gsap.timeline()
tl.to(`#${store.current.id!}`, {
x: 250,
rotation: 360,
duration: 2,
ease: 'power1.inOut'
})
.to(`#${store.current.id!}`, {
x: 0,
rotation: 0,
duration: 2,
ease: 'power1.inOut'
})
.to(`#${store.current.id!}`, {
x: -250,
rotation: -360,
duration: 2,
ease: 'power1.inOut'
})
.to(`#${store.current.id!}`, {
x: 0,
rotation: 0,
duration: 2,
ease: 'power1.inOut'
})
break
default:
break
}
}
const stopAnimation = () => {
gsap.killTweensOf(`#${store.current.id!}`)
}
const selectedAnimation = ref<string | null>(null)
const animations = [
{ label: 'GsapFrom', value: 'from' },
{ label: 'GsapFromTo', value: 'fromTo' },
{ label: 'GsapScrollTrigger', value: 'scrollTrigger' },
{ label: 'GsapStagger', value: 'stagger' },
{ label: 'GsapTo', value: 'to' },
{ label: 'GsapTimeline', value: 'timeline' }
]
</script>

<style lang='scss' scoped>
<style lang="scss" scoped>
.animation-container {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
background-color: #f0f0f0;
padding: 20px;
.animation-options {
display: flex;
flex-direction: column;
align-items: flex-start;
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
.animation-radio-group {
display: flex;
flex-direction: column;
align-items: flex-start;
margin-bottom: 20px;
.el-radio {
margin-bottom: 10px;
align-self: flex-start;
}
}
.button-group {
display: flex;
justify-content: center;
width: 100%;
gap: 10px;
}
.action-button {
padding: 10px;
background-color: #00ced1;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
.danger {
background-color: #ff4500;
}
}
}
</style>
Loading

0 comments on commit fa8574e

Please sign in to comment.