1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
import { PasteCommand } from "@/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">;
|