Skip to content

SolidJS

import { createSignal } from "solid-js";
import { shallowEqual } from "@lumen-timeline/core";
import { createEditorSelector, createTimeline, TimelineContext } from "@lumen-timeline/solid";
import "@lumen-timeline/timeline/style.css";
export function Workspace(props) {
const [element, setElement] = createSignal();
const [snap] = createSignal({ gridTicks: 28224000 });
const view = createTimeline(element, () => ({
editor: props.editor,
transport: props.transport,
snap: snap(),
}));
const clip = createEditorSelector(
() => props.editor,
({ snapshot, selection }) => {
const found = snapshot.clips.find((c) => c.id === selection.at(-1));
return found ? { name: found.name, take: found.activeTakeId } : null;
},
shallowEqual,
);
return (
<TimelineContext value={{ editor: props.editor, transport: props.transport }}>
<div ref={setElement} />
<aside>{clip() ? `${clip().name}: ${clip().take}` : "No clip selected"}</aside>
</TimelineContext>
);
}
  • createTimeline(element, options) mounts the view in element once the render has settled, and disposes it with its owner. Give the element as a signal, with its setter as the ref, and the options as an accessor. It returns an accessor of the view, undefined until it mounts.
  • createEditorSelector(editor, select, isEqual) returns an accessor of the field. It subscribes from its first effect run until its owner is disposed. editor may be an accessor, which a host that switches editors passes.
  • createTransportSelector(transport, select, isEqual) does the same for a transport’s snapshot.
  • <TimelineContext value={{ editor, transport }}> and useTimelineContext() hand the host’s editor and transport down. A host that switches them passes an object whose properties are getters of its signals. useTimelineContext throws without a provider.
  • SolidJS 2’s JSX compiler was published only under next tags when this was tested. The package has no JSX and does not depend on it; an application compiles its own.