콘텐츠로 이동

Vue

이 콘텐츠는 아직 번역되지 않았습니다.

<script setup>
import { computed, useTemplateRef } from "vue";
import { shallowEqual } from "@lumen-timeline/core";
import { provideTimeline, Timeline, useEditorSelector } from "@lumen-timeline/vue";
import "@lumen-timeline/timeline/style.css";
const { editor, transport, tiles } = defineProps(["editor", "transport", "tiles"]);
provideTimeline({ editor, transport });
const timeline = useTemplateRef("timeline");
const clip = useEditorSelector(
editor,
({ snapshot, selection }) => {
const found = snapshot.clips.find((c) => c.id === selection.at(-1));
return found ? { name: found.name, take: found.activeTakeId } : null;
},
shallowEqual,
);
</script>
<template>
<Timeline ref="timeline" :editor="editor" :transport="transport" :waveforms="tiles" />
<aside>{{ clip ? `${clip.name}: ${clip.take}` : "No clip selected" }}</aside>
</template>
  • <Timeline v-bind="options"> renders a div and mounts the view in it on mount. class and style fall through to the div. The template ref exposes view, the TimelineView or null. Props are read raw, so an editor kept in a deep ref still reaches the view as the object the host made.
  • useEditorSelector(editor, select, isEqual) returns a read-only shallow reference. In a component it subscribes from mount until unmount; elsewhere, from the call until its effect scope ends. editor may be a ref or a getter, and a new editor is followed.
  • useTransportSelector(transport, select, isEqual) does the same for a transport’s snapshot.
  • provideTimeline(value) and useTimelineContext() hand the host’s editor and transport down. value may be a ref or a getter, and useTimelineContext returns a computed reference. It throws without a provider.