Events and the controller

Listening

<VideoEditor
  onEvent={(event) => {
    switch (event.type) {
      case 'change': // an edit, undo or redo; event.label names it ("Split", "Add text"…)
      case 'selection': // event.ids
      case 'playback': // event.playing
      case 'command': // event.id — a menu or shortcut command ran
      case 'import': // event.assetId, event.name
      case 'export': // event.phase: 'start' | 'done' | 'cancelled' | 'error'
      case 'panel': // event.id — a left-menu panel opened (null: closed)
    }
  }}
/>

The controller

onReady hands you the editor's controller: the project, playback, selection and every action the UI uses.

import { updateItem } from '@video-ultra/core';

<VideoEditor
  onReady={(ctl) => {
    ctl.seek(0);
    ctl.play();
    // Edits: a recipe on a draft of the project — one undo step, saved like any edit.
    ctl.run('Mute everything', (draft) => {
      for (const track of draft.tracks)
        for (const item of track.items)
          if ('muted' in item) updateItem(draft, item.id, { muted: true });
    });
    const off = ctl.on((event) => console.log(event.type)); // call off() to stop
  }}
/>

Inside the editor (your own panels, or components under it) the hooks useController, useProject(selector), useUi(selector) and useHistory give the same controller and re-render only when what they select changes.

Edit operations

@video-ultra/core exports the operations the editor uses — insertMain, addToLane, splitItem, trimItem, setSpeed, updateItem, setTransition, combineItems and more. Each keeps the project valid or throws an EditError with a reason, so they're safe to call from your code, on the server too.