summaryrefslogtreecommitdiff
path: root/apps/web/src/lib/clipboard/handlers/elements.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2026-04-13 04:40:56 +0200
committerMaze Winther <mazewinther@gmail.com>2026-04-13 05:03:10 +0200
commit2272598d420cf078aaa3928246bfa3a414f6eddb (patch)
treeb52460a2e3576c9e517ef8a9dd86959a68f31b69 /apps/web/src/lib/clipboard/handlers/elements.ts
parent5a2aaf3601b6b050603f51e487a31fb07862a21f (diff)
downloadopencut-2272598d420cf078aaa3928246bfa3a414f6eddb.tar.gz
feat: clipboard with keyframe paste
Made-with: Cursor
Diffstat (limited to 'apps/web/src/lib/clipboard/handlers/elements.ts')
-rw-r--r--apps/web/src/lib/clipboard/handlers/elements.ts48
1 files changed, 48 insertions, 0 deletions
diff --git a/apps/web/src/lib/clipboard/handlers/elements.ts b/apps/web/src/lib/clipboard/handlers/elements.ts
new file mode 100644
index 00000000..1b58ac78
--- /dev/null
+++ b/apps/web/src/lib/clipboard/handlers/elements.ts
@@ -0,0 +1,48 @@
+import { PasteCommand } from "@/lib/commands/timeline";
+import type { ClipboardHandler } from "../types";
+
+export const ElementsClipboardHandler = {
+ type: "elements",
+
+ canCopy({ selectedElements }) {
+ return selectedElements.length > 0;
+ },
+
+ copy({ editor, selectedElements }) {
+ if (selectedElements.length === 0) {
+ return null;
+ }
+
+ const results = editor.timeline.getElementsWithTracks({
+ elements: selectedElements,
+ });
+ const items = results.map(({ track, element }) => {
+ const { id: _elementId, ...elementWithoutId } = element;
+ return {
+ trackId: track.id,
+ trackType: track.type,
+ element: elementWithoutId,
+ };
+ });
+
+ if (items.length === 0) {
+ return null;
+ }
+
+ return {
+ type: "elements",
+ items,
+ };
+ },
+
+ paste(entry, context) {
+ if (entry.items.length === 0) {
+ return null;
+ }
+
+ return new PasteCommand({
+ time: context.time,
+ clipboardItems: entry.items,
+ });
+ },
+} satisfies ClipboardHandler<"elements">;