File size: 1,880 Bytes
2ec5eb1
 
 
 
 
 
 
 
9f072e4
 
 
2ec5eb1
 
9f072e4
 
2ec5eb1
 
 
 
9f072e4
 
 
 
 
 
 
 
2ec5eb1
9f072e4
 
 
 
 
 
 
2ec5eb1
 
 
9f072e4
2ec5eb1
 
 
 
9f072e4
 
 
 
 
 
 
2ec5eb1
 
 
9f072e4
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
49
50
51
52
53
54
55
import { TLUiOverrides } from 'tldraw'
import { exportToImage } from './utils/exportUtils'

export const getUiOverrides = (roomId: string): TLUiOverrides => {
    return {
        actions: (editor, actions) => {
            const newActions = { ...actions }

            const safeExport = async (format: 'png' | 'svg' | 'pdf' = 'png') => {
                console.log(`Intercepted export action for format: ${format}`)
                await exportToImage(editor, roomId, format)
            }

            // Override PNG export actions
            const pngActions = [
                'export-as-png',
                'export-all-as-png',
                'export-selected-as-png',
            ]
            pngActions.forEach(id => {
                if (newActions[id]) {
                    newActions[id] = {
                        ...newActions[id],
                        onSelect: async () => await safeExport('png')
                    }
                }
            })

            // Override SVG export actions
            const svgActions = [
                'export-as-svg',
                'export-all-as-svg',
                'export-selected-as-svg'
            ]
            svgActions.forEach(id => {
                if (newActions[id]) {
                    newActions[id] = {
                        ...newActions[id],
                        onSelect: async () => await safeExport('svg')
                    }
                }
            })

            // JSON export (leave as default or handle if needed)
            if (newActions['export-as-json']) {
                 // For now, let default JSON export happen or redirect if you want native share
                 // If you want to use the new "Download File" logic instead:
                 // newActions['export-as-json'] = { ... }
            }

            return newActions
        },
    }
}