-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathfile-upload.html
More file actions
127 lines (108 loc) · 3.83 KB
/
file-upload.html
File metadata and controls
127 lines (108 loc) · 3.83 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
122
123
124
125
126
127
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OverType - File Upload Example</title>
<style>
body {
font-family: system-ui, -apple-system, sans-serif;
max-width: 900px;
margin: 0 auto;
padding: 40px 20px;
background: #f5f5f5;
}
h1 {
color: #333;
margin-bottom: 10px;
}
.subtitle {
color: #666;
margin-bottom: 30px;
}
.editor-container {
height: 400px;
background: white;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
overflow: hidden;
}
.info {
margin-top: 20px;
padding: 15px;
background: #fff;
border: 1px solid #e0e0e0;
border-radius: 4px;
font-size: 14px;
color: #555;
line-height: 1.6;
}
.info strong {
color: #333;
}
.log {
margin-top: 20px;
padding: 15px;
background: #1a1a2e;
border-radius: 4px;
font-family: monospace;
font-size: 13px;
color: #a0e0a0;
max-height: 150px;
overflow-y: auto;
}
.log:empty::before {
content: 'Upload log will appear here...';
color: #555;
}
</style>
</head>
<body>
<h1>OverType File Upload</h1>
<p class="subtitle">Paste or drag-and-drop files into the editor. Click the upload button in the toolbar.</p>
<div id="editor" class="editor-container"></div>
<div class="info">
<strong>Try it:</strong> Drag an image into the editor, paste from clipboard, or click the upload icon in the toolbar.
Uploads are simulated with a 1.5s delay. In production, replace the <code>onInsertFile</code> callback with a real upload to your server.
</div>
<div id="log" class="log"></div>
<script src="../dist/overtype.js"></script>
<script>
const logEl = document.getElementById('log');
function log(msg) {
const line = document.createElement('div');
line.textContent = `[${new Date().toLocaleTimeString()}] ${msg}`;
logEl.appendChild(line);
logEl.scrollTop = logEl.scrollHeight;
}
const OT = window.OverType?.default || window.OverType;
const [editor] = new OT('#editor', {
toolbar: true,
placeholder: 'Drop a file here, paste an image, or click the upload button...',
value: `# File Upload Demo
Try uploading files to see them inserted as markdown links.
**Images** get inserted as \`\` so they render inline.
**Other files** get inserted as \`[name](url)\` as regular links.
`,
fileUpload: {
enabled: true,
maxSize: 10 * 1024 * 1024,
onInsertFile: async (file) => {
log(`Uploading: ${file.name} (${(file.size / 1024).toFixed(1)} KB)`);
// Simulate upload delay
await new Promise(r => setTimeout(r, 1500));
const fakeUrl = `/uploads/${encodeURIComponent(file.name)}`;
const isImage = file.type.startsWith('image/');
log(`Done: ${file.name} → ${fakeUrl}`);
return isImage
? ``
: `[${file.name}](${fakeUrl})`;
},
onRemoveFile: ({ url, filename, file }) => {
log(`Removed: ${filename} → ${url} (clean up backend file here)`);
}
}
});
</script>
</body>
</html>