-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.html
More file actions
77 lines (67 loc) · 2.39 KB
/
index.html
File metadata and controls
77 lines (67 loc) · 2.39 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Apex Formatter</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
textarea {
width: 100%;
height: 200px;
font-family: monospace;
font-size: 14px;
margin-bottom: 10px;
}
pre {
background-color: #f4f4f4;
padding: 10px;
white-space: pre-wrap;
word-wrap: break-word;
}
button {
padding: 10px 20px;
font-size: 16px;
}
</style>
</head>
<body>
<h1>Salesforce Apex Formatter</h1>
<div id="status">WASM Status: Loading...</div>
<h3>Source Code:</h3>
<textarea id="source-code" placeholder="Enter your Apex source code here..."></textarea>
<button id="format-button">Format Code</button>
<h3>Formatted Code:</h3>
<pre id="formatted-code"></pre>
<script type="module">
// Initialize the WASM module
async function initWasm() {
try {
// Dynamically import the WASM module
const wasm = await import('./pkg/afmt.js');
await wasm.default(); // Initializes the WASM module
// Update status to show WASM loaded
document.getElementById('status').textContent = 'WASM Status: Loaded Successfully!';
// Event listener for the format button
document.getElementById('format-button').addEventListener('click', () => {
const source = document.getElementById('source-code').value;
try {
const formatted = wasm.greet(source);
document.getElementById('formatted-code').textContent = formatted;
} catch (e) {
document.getElementById('formatted-code').textContent = `Error: ${e}`;
console.error('Formatting failed:', e);
}
});
console.log('WASM module loaded and ready.');
} catch (error) {
document.getElementById('status').textContent = 'WASM Status: Failed to Load';
console.error('Failed to load WASM module:', error);
}
}
initWasm();
</script>
</body>
</html>