Svelte
이 콘텐츠는 아직 번역되지 않았습니다.
<script> import { shallowEqual } from "@lumen-timeline/core"; import { editorSelector, setTimelineContext, timeline } from "@lumen-timeline/svelte"; import "@lumen-timeline/timeline/style.css";
const { editor, transport, tiles } = $props(); let snap = $state({ gridTicks: 28224000 }); let view = null; setTimelineContext({ editor, transport }); const clip = editorSelector( 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>
<div {@attach timeline(() => ({ editor, transport, snap, waveforms: tiles, onview: (v) => (view = v) }))}></div><aside>{clip.current ? `${clip.current.name}: ${clip.current.take}` : "No clip selected"}</aside>{@attach timeline(() => options)}mounts the view in its element and disposes it when the element goes. Pass a function that returns the options, so they are read inside the attachment: a changededitor,transportorrenderermounts a new view, and other options reach the mounted view.onviewreceives the view, andnullonce it is disposed.editorSelector(editor, select, isEqual)returns{ current }. Readcurrentin markup, a derived value or an effect. An effect that reads it subscribes, and the subscription ends when no effect reads it.editormay be a function returning it, which a host that switches editors passes.transportSelector(transport, select, isEqual)does the same for a transport’s snapshot.setTimelineContext({ editor, transport })andgetTimelineContext()hand the host’s editor and transport down during component setup. A host that switches them passes an object whose properties are getters of its state.- The attachment uses
$effect, so the package ships it asattach.svelte.jsand the application’s Svelte compiles its runes, as Svelte libraries do. The package’ssvelteexport condition tells Vite so.