Skip to content

The VS Code of video editing, built for agents.

TypeScript

Enhance clip naming logic with fallback options

konstantin-paulus94af336eebdc
diff --git a/apps/web/src/components/timeline/layers/node.tsx b/apps/web/src/components/timeline/layers/node.tsx
index e0c0f1d3..6e440a6d 100644
--- a/apps/web/src/components/timeline/layers/node.tsx
+++ b/apps/web/src/components/timeline/layers/node.tsx
@@ -37,7 +37,7 @@ import {
} from '@/components/ui/context-menu';
import { Tooltip, TooltipContent, TooltipPortal, TooltipTrigger } from '@/components/ui/tooltip';
import { useEditor } from '@/engine/hooks';
-import { DEFAULT_CLIP_HEIGHT, MAX_CLIP_HEIGHT, MIN_CLIP_HEIGHT } from '@/engine/timeline';
+import { DEFAULT_CLIP_HEIGHT, MAX_CLIP_HEIGHT, MIN_CLIP_HEIGHT, getClipFallbackName } from '@/engine/timeline';
import { NESTED_INDENT_PX } from './config';
import { useLayerContext } from './context';
import { setRowHover } from './hover';
@@ -69,7 +69,7 @@ export function NodeLayer(props: LayerRowProps) {
let originalName = '';
const nameTrait = useTrait(entity, Name);
- const name = createMemo(() => nameTrait()?.value ?? 'Layer');
+ const name = createMemo(() => nameTrait()?.value || getClipFallbackName(world, entity()));
const icon = createMemo(() => getLayerIcon(world, props.layer));
const toggleMuted = (e?: Event) => {
diff --git a/apps/web/src/engine/timeline/render/clip.ts b/apps/web/src/engine/timeline/render/clip.ts
index eefeb56c..943138de 100644
--- a/apps/web/src/engine/timeline/render/clip.ts
+++ b/apps/web/src/engine/timeline/render/clip.ts
@@ -15,7 +15,7 @@ import {
TRIM_HANDLE_WIDTH,
} from '../config';
import { applyClipDrag, applyTrim, beginClipDrag, beginTrim } from '../drag';
-import { getClipAsset, getClipStyle } from '../style';
+import { getClipAsset, getClipFallbackName, getClipStyle } from '../style';
import { truncateText } from '../text';
import { framesToPixels, getResolution, getViewport } from '../view';
import { renderCaption } from './caption';
@@ -85,10 +85,11 @@ export function renderClip(
{
let label = entity.get(Name)?.value ?? '';
- if (error) label = error;
- if (generating) label = 'Generating...';
if (isCaption(entity)) label = label || `${CAPTION_PRESETS[entity.get(Caption)?.type ?? CaptionType.CLASSIC]} Captions`;
if (isText(entity)) label = entity.get(Chars)?.value ?? label ?? '';
+ if (!label) label = getClipFallbackName(world, entity);
+ if (generating) label = 'Generating...';
+ if (error) label = error;
const [viewportLeft] = getViewport(world, scene, surface.layout.width);
const x = Math.max(left, viewportLeft);
diff --git a/apps/web/src/engine/timeline/style.ts b/apps/web/src/engine/timeline/style.ts
index 65f41739..d50cd57c 100644
--- a/apps/web/src/engine/timeline/style.ts
+++ b/apps/web/src/engine/timeline/style.ts
@@ -11,7 +11,9 @@ import {
isCaption,
isGroup,
isMask,
+ isRect,
isScene,
+ isSequence,
isText,
} from '@diffusionstudio/runtime';
@@ -49,6 +51,41 @@ export function getClipStyle(entity: Entity, asset: Asset | null, errored = fals
}
}
+/**
+ * What to call a clip that was never named. A name is only ever authored —
+ * the reconciler adds `Name` when the JSX asks for one — so most clips have
+ * none, and a column of rows all reading "Layer" says no more than a column
+ * of blank ones does. What a clip is, is the next best thing to what it is
+ * called. This is only what the timeline shows; nothing is written back to
+ * the document, so an unnamed clip stays unnamed.
+ *
+ * The cascade follows `getClipStyle`, so the word and the colour agree on
+ * what the clip is.
+ */
+export function getClipFallbackName(world: World, entity: Entity): string {
+ if (isCaption(entity)) return 'Captions';
+ if (isText(entity)) return 'Text';
+ if (isScene(entity)) return 'Scene';
+ if (isSequence(entity)) return 'Sequence';
+ if (isGroup(entity)) return 'Group';
+ if (isMask(entity)) return 'Mask';
+ if (isAdjustmentLayer(entity)) return 'Adjustment';
+ if (hasHtmlPaint(entity)) return 'HTML';
+ if (hasSurfacePaint(entity)) return 'Surface';
+
+ switch (getClipAsset(world, entity)?.type) {
+ case 'VIDEO':
+ case 'SEQUENCE':
+ return 'Video';
+ case 'IMAGE':
+ return 'Image';
+ case 'AUDIO':
+ return 'Audio';
+ }
+
+ return isRect(entity) ? 'Rectangle' : 'Layer';
+}
+
/** The asset a clip shows, whether it is the clip's own or one of its fills. */
export function getClipAsset(world: World, entity: Entity): Asset | null {
return findGeometryAsset(world, entity);