|
1 | 1 | <template>
|
2 |
| - <div class="va-timeline__wrapper"> |
3 |
| - <!-- --> |
| 2 | + <div class="va-timeline-component"> |
| 3 | + <div class="va-layer__wrapper" :style="{ width: '320px' }"> |
| 4 | + <div class="va-layer__toolbar"></div> |
| 5 | + <div class="va-layer__container"> |
| 6 | + <draggable v-model="elements" v-bind="dragOptions" v-on="dragEventHandlers" item-key="id"> |
| 7 | + <template #item="{ index }"> |
| 8 | + <LayerItem v-model="elements[index]" /> |
| 9 | + </template> |
| 10 | + </draggable> |
| 11 | + </div> |
| 12 | + </div> |
| 13 | + <div class="va-timeline__wrapper"> |
| 14 | + <div class="va-timeline__ruler"> |
| 15 | + <i |
| 16 | + class="va-timeline__indicator__caret icon icon-eject" |
| 17 | + :style="{ |
| 18 | + left: currentTime * 100 + '%', |
| 19 | + }" |
| 20 | + ></i> |
| 21 | + </div> |
| 22 | + <div class="va-timeline__container"> |
| 23 | + <div |
| 24 | + class="va-timeline__indicator__line" |
| 25 | + :style="{ |
| 26 | + left: currentTime * 100 + '%', |
| 27 | + }" |
| 28 | + ></div> |
| 29 | + <TimelineItem |
| 30 | + v-for="(element, index) in elements" |
| 31 | + v-model="elements[index]" |
| 32 | + :key="element.id" |
| 33 | + /> |
| 34 | + </div> |
| 35 | + </div> |
4 | 36 | </div>
|
5 | 37 | </template>
|
6 | 38 |
|
7 | 39 | <script lang="ts">
|
8 |
| -import { defineComponent } from "vue"; |
| 40 | +import { computed, defineComponent, ref, watch } from "vue"; |
| 41 | +import TimelineItem from "./timeline/timeline-item.vue"; |
| 42 | +import LayerItem from "./layer/layer-item.vue"; |
| 43 | +
|
| 44 | +import draggable from "vuedraggable"; |
| 45 | +
|
| 46 | +type Element = { |
| 47 | + id: string; |
| 48 | + name: string; |
| 49 | + keyframes: string[]; |
| 50 | + expanded?: boolean; |
| 51 | + stages: { |
| 52 | + [key: string]: { |
| 53 | + keyframe: number; |
| 54 | + label: string; |
| 55 | + property: string; |
| 56 | + value: any; |
| 57 | + }; |
| 58 | + }; |
| 59 | +}; |
9 | 60 |
|
10 | 61 | export default defineComponent({
|
11 | 62 | name: "AnimationTimeline",
|
12 |
| - components: {}, |
13 |
| - setup() { |
14 |
| - // |
| 63 | + components: { draggable, TimelineItem, LayerItem }, |
| 64 | + props: { |
| 65 | + modelValue: { |
| 66 | + type: Array, |
| 67 | + default: () => [], |
| 68 | + }, |
| 69 | + }, |
| 70 | + emits: ["update:modelValue"], |
| 71 | + setup(props, { emit }) { |
| 72 | + const isDragging = ref(false); |
| 73 | + const dragOptions = computed(() => ({ |
| 74 | + animation: 200, |
| 75 | + group: "description", |
| 76 | + disabled: false, |
| 77 | + ghostClass: "draggable-ghost", |
| 78 | + handle: ".handle", |
| 79 | + })); |
| 80 | + const dragEventHandlers = { |
| 81 | + start() { |
| 82 | + isDragging.value = true; |
| 83 | + }, |
| 84 | + end() { |
| 85 | + isDragging.value = false; |
| 86 | + }, |
| 87 | + }; |
| 88 | +
|
| 89 | + const currentTime = ref(0.5); |
| 90 | + const elements = ref<Element[]>([ |
| 91 | + { |
| 92 | + id: "1jhg1kj23jkh4kj67jh", |
| 93 | + name: "Layer 1", |
| 94 | + keyframes: ["stage-id-168rf9c8f9c88478f9c88038f", "stage-id-268rf9c8f9c88478f9c88038f"], |
| 95 | + expanded: false, |
| 96 | + stages: { |
| 97 | + "stage-id-168rf9c8f9c88478f9c88038f": { |
| 98 | + keyframe: 0, |
| 99 | + label: "Position", |
| 100 | + property: "position", |
| 101 | + value: { x: 150, y: 100 }, |
| 102 | + }, |
| 103 | + "stage-id-268rf9c8f9c88478f9c88038f": { |
| 104 | + keyframe: 0.5, |
| 105 | + label: "Position", |
| 106 | + property: "position", |
| 107 | + value: { x: 200, y: 150 }, |
| 108 | + }, |
| 109 | + }, |
| 110 | + }, |
| 111 | + { |
| 112 | + id: "2jhg1kj23jkh4kj67jh", |
| 113 | + name: "Layer 2", |
| 114 | + keyframes: [ |
| 115 | + "stage-id-168rf9c8f9c88478f9c88038f", |
| 116 | + "stage-id-268rf9c8f9c74478f9c88038f", |
| 117 | + "stage-id-468rf9c8f9c88ỉbf9c88038f", |
| 118 | + "stage-id-568rf9c8f9c88478f9c88038f", |
| 119 | + ], |
| 120 | + expanded: true, |
| 121 | + stages: { |
| 122 | + "stage-id-168rf9c8f9c88478f9c88038f": { |
| 123 | + keyframe: 0, |
| 124 | + label: "Opacity", |
| 125 | + property: "opacity", |
| 126 | + value: 0, |
| 127 | + }, |
| 128 | + "stage-id-268rf9c8f9c74478f9c88038f": { |
| 129 | + keyframe: 0.3, |
| 130 | + label: "Opacity", |
| 131 | + property: "opacity", |
| 132 | + value: 0.9, |
| 133 | + }, |
| 134 | + "stage-id-468rf9c8f9c88ỉbf9c88038f": { |
| 135 | + keyframe: 0.7, |
| 136 | + label: "Opacity", |
| 137 | + property: "opacity", |
| 138 | + value: 0.5, |
| 139 | + }, |
| 140 | + "stage-id-568rf9c8f9c88478f9c88038f": { |
| 141 | + keyframe: 0.5, |
| 142 | + label: "Position", |
| 143 | + property: "position", |
| 144 | + value: { x: 200, y: 150 }, |
| 145 | + }, |
| 146 | + }, |
| 147 | + }, |
| 148 | + ]); |
| 149 | +
|
| 150 | + watch( |
| 151 | + () => elements.value, |
| 152 | + () => { |
| 153 | + emit("update:modelValue", elements.value); |
| 154 | + }, |
| 155 | + { immediate: true, deep: true }, |
| 156 | + ); |
| 157 | +
|
| 158 | + return { |
| 159 | + currentTime, |
| 160 | + elements, |
| 161 | + dragOptions, |
| 162 | + dragEventHandlers, |
| 163 | + }; |
15 | 164 | },
|
16 | 165 | });
|
17 | 166 | </script>
|
18 | 167 |
|
19 |
| -<style lang="scss"> |
20 |
| -.va-timeline { |
21 |
| - &__wrapper { |
22 |
| - width: 100%; |
23 |
| - height: 100%; |
24 |
| - background-color: rgb(32, 32, 32); |
25 |
| - } |
26 |
| -} |
27 |
| -</style> |
| 168 | +<style lang="scss" src="@/styles/main.scss"></style> |
0 commit comments