Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Add TrackManager component and update timeline track types

Richie McIlroy5cc649a25fc7
diff --git a/apps/desktop/src/routes/editor/Timeline/TrackManager.tsx b/apps/desktop/src/routes/editor/Timeline/TrackManager.tsx
new file mode 100644
index 000000000..7b875de5e
--- /dev/null
+++ b/apps/desktop/src/routes/editor/Timeline/TrackManager.tsx
@@ -0,0 +1,77 @@
+import { LogicalPosition } from "@tauri-apps/api/dpi";
+import { CheckMenuItem, Menu } from "@tauri-apps/api/menu";
+import type { JSX } from "solid-js";
+
+import type { TimelineTrackType } from "../context";
+
+type TrackManagerOption = {
+ type: TimelineTrackType;
+ label: string;
+ icon: JSX.Element;
+ active: boolean;
+ available: boolean;
+};
+
+export function TrackManager(props: {
+ options: TrackManagerOption[];
+ onToggle(type: TimelineTrackType, next: boolean): void;
+}) {
+ let addButton: HTMLButtonElement | undefined;
+
+ const handleOpenMenu = async () => {
+ try {
+ const items = await Promise.all(
+ props.options.map((option) => {
+ if (option.type === "scene") {
+ return CheckMenuItem.new({
+ text: option.label,
+ checked: option.active,
+ enabled: option.available,
+ action: () => props.onToggle(option.type, !option.active),
+ });
+ }
+
+ return CheckMenuItem.new({
+ text: option.label,
+ checked: true,
+ enabled: false,
+ });
+ }),
+ );
+
+ const menu = await Menu.new({ items });
+ const rect = addButton?.getBoundingClientRect();
+ if (rect) {
+ menu.popup(new LogicalPosition(rect.x, rect.y + rect.height + 4));
+ } else {
+ menu.popup();
+ }
+ } catch (error) {
+ console.error("Failed to open track menu", error);
+ }
+ };
+
+ return (
+ <button
+ ref={(el) => {
+ addButton = el;
+ }}
+ class="flex h-8 w-9 items-center justify-center rounded-lg border border-gray-4/80 bg-gray-2 text-sm font-medium text-gray-12 transition-colors duration-150 hover:bg-gray-3 dark:border-gray-5/60 dark:bg-gray-4/50"
+ onClick={handleOpenMenu}
+ onMouseDown={(e) => e.stopPropagation()}
+ >
+ <IconLucidePlus class="size-4" />
+ </button>
+ );
+}
+
+export function TrackIcon(props: { icon: JSX.Element }) {
+ return (
+ <div
+ class="relative z-10 w-[3.5rem] h-[3.25rem] flex items-center justify-center rounded-xl border border-gray-4/70 bg-gray-2/60 text-gray-12 shadow-[0_4px_16px_-12px_rgba(0,0,0,0.8)] dark:border-gray-4/60 dark:bg-gray-3/40"
+ onMouseDown={(e) => e.stopPropagation()}
+ >
+ {props.icon}
+ </div>
+ );
+}
diff --git a/apps/desktop/src/routes/editor/context.ts b/apps/desktop/src/routes/editor/context.ts
index efc0d97d9..3aae121e9 100644
--- a/apps/desktop/src/routes/editor/context.ts
+++ b/apps/desktop/src/routes/editor/context.ts
@@ -50,6 +50,8 @@ export const OUTPUT_SIZE = {
y: 1080,
};
+export type TimelineTrackType = "clip" | "zoom" | "scene";
+
export const MAX_ZOOM_IN = 3;
const PROJECT_SAVE_DEBOUNCE_MS = 250;
@@ -477,7 +479,12 @@ export const [EditorContextProvider, useEditorContext] = createContextProvider(
);
},
},
- hoveredTrack: null as null | "clip" | "zoom" | "scene",
+ tracks: {
+ clip: true,
+ zoom: true,
+ scene: true,
+ },
+ hoveredTrack: null as null | TimelineTrackType,
},
});
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index e0e2b9435..d47dea60b 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -409,7 +409,7 @@ export type CursorType = "pointer" | "circle"
export type Cursors = { [key in string]: string } | { [key in string]: CursorMeta }
export type DeviceOrModelID = { DeviceID: string } | { ModelID: ModelIDType }
export type DisplayId = string
-export type DisplayInformation = { name: string | null; physical_size: PhysicalSize | null; refresh_rate: string }
+export type DisplayInformation = { name: string | null; physical_size: PhysicalSize | null; logical_size: LogicalSize | null; refresh_rate: string }
export type DownloadProgress = { progress: number; message: string }
export type EditorStateChanged = { playhead_position: number }
export type ExportCompression = "Minimal" | "Social" | "Web" | "Potato"
diff --git a/packages/ui-solid/src/auto-imports.d.ts b/packages/ui-solid/src/auto-imports.d.ts
index 930b3ac25..c10b785a8 100644
--- a/packages/ui-solid/src/auto-imports.d.ts
+++ b/packages/ui-solid/src/auto-imports.d.ts
@@ -69,6 +69,7 @@ declare global {
const IconLucideBell: typeof import('~icons/lucide/bell.jsx')['default']
const IconLucideBug: typeof import('~icons/lucide/bug.jsx')['default']
const IconLucideCheck: typeof import('~icons/lucide/check.jsx')['default']
+ const IconLucideClapperboard: typeof import('~icons/lucide/clapperboard.jsx')['default']
const IconLucideClock: typeof import('~icons/lucide/clock.jsx')['default']
const IconLucideDatabase: typeof import('~icons/lucide/database.jsx')['default']
const IconLucideEdit: typeof import('~icons/lucide/edit.jsx')['default']