-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathapi.ts
More file actions
121 lines (108 loc) · 3.71 KB
/
api.ts
File metadata and controls
121 lines (108 loc) · 3.71 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// api.ts - Public API for external use
import { initDiffEditor, updateDiffContent, getEditor, setEditorTheme, updateDiffStats } from './monaco-diff-editor';
import { updateFileMetadata } from './ui-controller';
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
/**
* Interface for the DiffViewer API
*/
interface DiffViewerAPI {
init: (
originalContent: string,
modifiedContent: string,
path: string | null,
status: string | null,
options?: monaco.editor.IDiffEditorConstructionOptions
) => void;
update: (
originalContent: string,
modifiedContent: string,
path: string | null,
status: string | null
) => void;
handleResize: () => void;
setTheme: (theme: 'light' | 'dark') => void;
followSystemTheme: () => void;
}
/**
* The public API that will be exposed to the global scope
*/
const DiffViewer: DiffViewerAPI = {
/**
* Initialize the diff editor with content
* @param {string} originalContent - Content for the original side
* @param {string} modifiedContent - Content for the modified side
* @param {string} path - File path
* @param {string} status - File edit status
* @param {Object} options - Optional configuration for the diff editor
*/
init: function(
originalContent: string,
modifiedContent: string,
path: string | null,
status: string | null,
options?: monaco.editor.IDiffEditorConstructionOptions
): void {
// Initialize editor
initDiffEditor(originalContent, modifiedContent, options || {});
// Update file metadata and UI
updateFileMetadata(path, status);
},
/**
* Update the diff editor with new content
* @param {string} originalContent - Content for the original side
* @param {string} modifiedContent - Content for the modified side
* @param {string} path - File path
* @param {string} status - File edit status
*/
update: function(
originalContent: string,
modifiedContent: string,
path: string | null,
status: string | null
): void {
// Update editor content
updateDiffContent(originalContent, modifiedContent);
// Update file metadata and UI
updateFileMetadata(path, status);
// Update diff stats
updateDiffStats();
},
/**
* Handle resize events
*/
handleResize: function(): void {
const editor = getEditor();
if (editor) {
const container = document.getElementById('container');
if (container) {
const headerHeight = 40;
const topPadding = 4;
const bottomPadding = 40;
const availableHeight = window.innerHeight - headerHeight - topPadding - bottomPadding;
container.style.height = `${availableHeight}px`;
}
editor.layout();
}
},
/**
* Set the theme for the editor
*/
setTheme: function(theme: 'light' | 'dark'): void {
setEditorTheme(theme);
},
/**
* Follow the system theme
*/
followSystemTheme: function(): void {
// Set initial theme based on system preference
const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
setEditorTheme(isDarkMode ? 'dark' : 'light');
// Add listener for theme changes
if (window.matchMedia) {
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
setEditorTheme(event.matches ? 'dark' : 'light');
});
}
}
};
export default DiffViewer;