agentgui 1.0.274 → 1.0.275
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +280 -280
- package/IPFS_DOWNLOADER.md +277 -277
- package/TASK_2C_COMPLETION.md +334 -334
- package/bin/gmgui.cjs +54 -54
- package/build-portable.js +3 -42
- package/database.js +1422 -1406
- package/lib/claude-runner.js +1130 -1130
- package/lib/ipfs-downloader.js +459 -459
- package/lib/speech.js +152 -152
- package/package.json +1 -1
- package/readme.md +76 -76
- package/server.js +3787 -3794
- package/setup-npm-token.sh +68 -68
- package/static/app.js +773 -773
- package/static/event-rendering-showcase.html +708 -708
- package/static/index.html +3178 -3180
- package/static/js/agent-auth.js +298 -298
- package/static/js/audio-recorder-processor.js +18 -18
- package/static/js/client.js +2656 -2656
- package/static/js/conversations.js +583 -583
- package/static/js/dialogs.js +267 -267
- package/static/js/event-consolidator.js +101 -101
- package/static/js/event-filter.js +311 -311
- package/static/js/event-processor.js +452 -452
- package/static/js/features.js +413 -413
- package/static/js/kalman-filter.js +67 -67
- package/static/js/progress-dialog.js +130 -130
- package/static/js/script-runner.js +219 -219
- package/static/js/streaming-renderer.js +2123 -2120
- package/static/js/syntax-highlighter.js +269 -269
- package/static/js/tts-websocket-handler.js +152 -152
- package/static/js/ui-components.js +431 -431
- package/static/js/voice.js +849 -849
- package/static/js/websocket-manager.js +596 -596
- package/static/templates/INDEX.html +465 -465
- package/static/templates/README.md +190 -190
- package/static/templates/agent-capabilities.html +56 -56
- package/static/templates/agent-metadata-panel.html +44 -44
- package/static/templates/agent-status-badge.html +30 -30
- package/static/templates/code-annotation-panel.html +155 -155
- package/static/templates/code-suggestion-panel.html +184 -184
- package/static/templates/command-header.html +77 -77
- package/static/templates/command-output-scrollable.html +118 -118
- package/static/templates/elapsed-time.html +54 -54
- package/static/templates/error-alert.html +106 -106
- package/static/templates/error-history-timeline.html +160 -160
- package/static/templates/error-recovery-options.html +109 -109
- package/static/templates/error-stack-trace.html +95 -95
- package/static/templates/error-summary.html +80 -80
- package/static/templates/event-counter.html +48 -48
- package/static/templates/execution-actions.html +97 -97
- package/static/templates/execution-progress-bar.html +80 -80
- package/static/templates/execution-stepper.html +120 -120
- package/static/templates/file-breadcrumb.html +118 -118
- package/static/templates/file-diff-viewer.html +121 -121
- package/static/templates/file-metadata.html +133 -133
- package/static/templates/file-read-panel.html +66 -66
- package/static/templates/file-write-panel.html +120 -120
- package/static/templates/git-branch-remote.html +107 -107
- package/static/templates/git-diff-list.html +101 -101
- package/static/templates/git-log-visualization.html +153 -153
- package/static/templates/git-status-panel.html +115 -115
- package/static/templates/quality-metrics-display.html +170 -170
- package/static/templates/terminal-output-panel.html +87 -87
- package/static/templates/test-results-display.html +144 -144
- package/static/theme.js +72 -72
- package/test-download-progress.js +223 -223
- package/test-websocket-broadcast.js +147 -147
- package/tests/ipfs-downloader.test.js +370 -370
package/static/js/dialogs.js
CHANGED
|
@@ -1,267 +1,267 @@
|
|
|
1
|
-
(function() {
|
|
2
|
-
var activeDialogs = [];
|
|
3
|
-
var dialogZIndex = 10000;
|
|
4
|
-
|
|
5
|
-
function escapeHtml(text) {
|
|
6
|
-
var map = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
|
|
7
|
-
return String(text).replace(/[&<>"']/g, function(c) { return map[c]; });
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function createOverlay() {
|
|
11
|
-
var overlay = document.createElement('div');
|
|
12
|
-
overlay.className = 'dialog-overlay';
|
|
13
|
-
overlay.innerHTML = '<div class="dialog-backdrop"></div>';
|
|
14
|
-
return overlay;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function showDialog(dialog, overlay) {
|
|
18
|
-
dialogZIndex++;
|
|
19
|
-
if (overlay) {
|
|
20
|
-
overlay.style.zIndex = dialogZIndex;
|
|
21
|
-
document.body.appendChild(overlay);
|
|
22
|
-
}
|
|
23
|
-
dialog.style.zIndex = dialogZIndex + 1;
|
|
24
|
-
document.body.appendChild(dialog);
|
|
25
|
-
activeDialogs.push({ dialog: dialog, overlay: overlay });
|
|
26
|
-
|
|
27
|
-
requestAnimationFrame(function() {
|
|
28
|
-
dialog.classList.add('visible');
|
|
29
|
-
if (overlay) overlay.classList.add('visible');
|
|
30
|
-
var input = dialog.querySelector('input, textarea');
|
|
31
|
-
if (input) input.focus();
|
|
32
|
-
else {
|
|
33
|
-
var btn = dialog.querySelector('.dialog-btn-primary');
|
|
34
|
-
if (btn) btn.focus();
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function closeDialog(dialog, overlay) {
|
|
40
|
-
dialog.classList.remove('visible');
|
|
41
|
-
if (overlay) overlay.classList.remove('visible');
|
|
42
|
-
setTimeout(function() {
|
|
43
|
-
if (dialog.parentNode) dialog.remove();
|
|
44
|
-
if (overlay && overlay.parentNode) overlay.remove();
|
|
45
|
-
}, 200);
|
|
46
|
-
activeDialogs = activeDialogs.filter(function(d) {
|
|
47
|
-
return d.dialog !== dialog;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function closeAllDialogs() {
|
|
52
|
-
activeDialogs.forEach(function(d) {
|
|
53
|
-
closeDialog(d.dialog, d.overlay);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
window.UIDialog = {
|
|
58
|
-
alert: function(message, title) {
|
|
59
|
-
return new Promise(function(resolve) {
|
|
60
|
-
var overlay = createOverlay();
|
|
61
|
-
var dialog = document.createElement('div');
|
|
62
|
-
dialog.className = 'dialog-container';
|
|
63
|
-
dialog.innerHTML =
|
|
64
|
-
'<div class="dialog-box">' +
|
|
65
|
-
'<div class="dialog-header">' +
|
|
66
|
-
'<h3 class="dialog-title">' + escapeHtml(title || 'Alert') + '</h3>' +
|
|
67
|
-
'</div>' +
|
|
68
|
-
'<div class="dialog-body">' +
|
|
69
|
-
'<p class="dialog-message">' + escapeHtml(message) + '</p>' +
|
|
70
|
-
'</div>' +
|
|
71
|
-
'<div class="dialog-footer">' +
|
|
72
|
-
'<button class="dialog-btn dialog-btn-primary" data-action="ok">OK</button>' +
|
|
73
|
-
'</div>' +
|
|
74
|
-
'</div>';
|
|
75
|
-
|
|
76
|
-
var okBtn = dialog.querySelector('[data-action="ok"]');
|
|
77
|
-
okBtn.addEventListener('click', function() {
|
|
78
|
-
closeDialog(dialog, overlay);
|
|
79
|
-
resolve(true);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
overlay.querySelector('.dialog-backdrop').addEventListener('click', function() {
|
|
83
|
-
closeDialog(dialog, overlay);
|
|
84
|
-
resolve(true);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
document.addEventListener('keydown', function handler(e) {
|
|
88
|
-
if (e.key === 'Escape' || e.key === 'Enter') {
|
|
89
|
-
document.removeEventListener('keydown', handler);
|
|
90
|
-
closeDialog(dialog, overlay);
|
|
91
|
-
resolve(true);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
showDialog(dialog, overlay);
|
|
96
|
-
});
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
confirm: function(message, title) {
|
|
100
|
-
return new Promise(function(resolve) {
|
|
101
|
-
var overlay = createOverlay();
|
|
102
|
-
var dialog = document.createElement('div');
|
|
103
|
-
dialog.className = 'dialog-container';
|
|
104
|
-
dialog.innerHTML =
|
|
105
|
-
'<div class="dialog-box">' +
|
|
106
|
-
'<div class="dialog-header">' +
|
|
107
|
-
'<h3 class="dialog-title">' + escapeHtml(title || 'Confirm') + '</h3>' +
|
|
108
|
-
'</div>' +
|
|
109
|
-
'<div class="dialog-body">' +
|
|
110
|
-
'<p class="dialog-message">' + escapeHtml(message).replace(/\n/g, '<br>') + '</p>' +
|
|
111
|
-
'</div>' +
|
|
112
|
-
'<div class="dialog-footer">' +
|
|
113
|
-
'<button class="dialog-btn dialog-btn-secondary" data-action="cancel">Cancel</button>' +
|
|
114
|
-
'<button class="dialog-btn dialog-btn-primary dialog-btn-danger" data-action="confirm">Confirm</button>' +
|
|
115
|
-
'</div>' +
|
|
116
|
-
'</div>';
|
|
117
|
-
|
|
118
|
-
var cancelBtn = dialog.querySelector('[data-action="cancel"]');
|
|
119
|
-
var confirmBtn = dialog.querySelector('[data-action="confirm"]');
|
|
120
|
-
|
|
121
|
-
cancelBtn.addEventListener('click', function() {
|
|
122
|
-
closeDialog(dialog, overlay);
|
|
123
|
-
resolve(false);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
confirmBtn.addEventListener('click', function() {
|
|
127
|
-
closeDialog(dialog, overlay);
|
|
128
|
-
resolve(true);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
overlay.querySelector('.dialog-backdrop').addEventListener('click', function() {
|
|
132
|
-
closeDialog(dialog, overlay);
|
|
133
|
-
resolve(false);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
document.addEventListener('keydown', function handler(e) {
|
|
137
|
-
if (e.key === 'Escape') {
|
|
138
|
-
document.removeEventListener('keydown', handler);
|
|
139
|
-
closeDialog(dialog, overlay);
|
|
140
|
-
resolve(false);
|
|
141
|
-
} else if (e.key === 'Enter') {
|
|
142
|
-
document.removeEventListener('keydown', handler);
|
|
143
|
-
closeDialog(dialog, overlay);
|
|
144
|
-
resolve(true);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
showDialog(dialog, overlay);
|
|
149
|
-
});
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
prompt: function(message, defaultValue, title) {
|
|
153
|
-
return new Promise(function(resolve) {
|
|
154
|
-
var overlay = createOverlay();
|
|
155
|
-
var dialog = document.createElement('div');
|
|
156
|
-
dialog.className = 'dialog-container';
|
|
157
|
-
dialog.innerHTML =
|
|
158
|
-
'<div class="dialog-box">' +
|
|
159
|
-
'<div class="dialog-header">' +
|
|
160
|
-
'<h3 class="dialog-title">' + escapeHtml(title || 'Input') + '</h3>' +
|
|
161
|
-
'</div>' +
|
|
162
|
-
'<div class="dialog-body">' +
|
|
163
|
-
'<label class="dialog-label">' + escapeHtml(message) + '</label>' +
|
|
164
|
-
'<input type="text" class="dialog-input" value="' + escapeHtml(defaultValue || '') + '">' +
|
|
165
|
-
'</div>' +
|
|
166
|
-
'<div class="dialog-footer">' +
|
|
167
|
-
'<button class="dialog-btn dialog-btn-secondary" data-action="cancel">Cancel</button>' +
|
|
168
|
-
'<button class="dialog-btn dialog-btn-primary" data-action="ok">OK</button>' +
|
|
169
|
-
'</div>' +
|
|
170
|
-
'</div>';
|
|
171
|
-
|
|
172
|
-
var input = dialog.querySelector('.dialog-input');
|
|
173
|
-
var cancelBtn = dialog.querySelector('[data-action="cancel"]');
|
|
174
|
-
var okBtn = dialog.querySelector('[data-action="ok"]');
|
|
175
|
-
|
|
176
|
-
cancelBtn.addEventListener('click', function() {
|
|
177
|
-
closeDialog(dialog, overlay);
|
|
178
|
-
resolve(null);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
okBtn.addEventListener('click', function() {
|
|
182
|
-
closeDialog(dialog, overlay);
|
|
183
|
-
resolve(input.value);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
input.addEventListener('keydown', function(e) {
|
|
187
|
-
if (e.key === 'Enter') {
|
|
188
|
-
closeDialog(dialog, overlay);
|
|
189
|
-
resolve(input.value);
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
overlay.querySelector('.dialog-backdrop').addEventListener('click', function() {
|
|
194
|
-
closeDialog(dialog, overlay);
|
|
195
|
-
resolve(null);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
document.addEventListener('keydown', function handler(e) {
|
|
199
|
-
if (e.key === 'Escape') {
|
|
200
|
-
document.removeEventListener('keydown', handler);
|
|
201
|
-
closeDialog(dialog, overlay);
|
|
202
|
-
resolve(null);
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
showDialog(dialog, overlay);
|
|
207
|
-
});
|
|
208
|
-
},
|
|
209
|
-
|
|
210
|
-
showProgress: function(config) {
|
|
211
|
-
var overlay = createOverlay();
|
|
212
|
-
var dialog = document.createElement('div');
|
|
213
|
-
dialog.className = 'dialog-container';
|
|
214
|
-
dialog.innerHTML =
|
|
215
|
-
'<div class="dialog-box dialog-box-progress">' +
|
|
216
|
-
'<div class="dialog-header">' +
|
|
217
|
-
'<h3 class="dialog-title">' + escapeHtml(config.title || 'Please wait') + '</h3>' +
|
|
218
|
-
'</div>' +
|
|
219
|
-
'<div class="dialog-body">' +
|
|
220
|
-
'<p class="dialog-message progress-message">' + escapeHtml(config.message || 'Loading...') + '</p>' +
|
|
221
|
-
'<div class="dialog-progress-bar">' +
|
|
222
|
-
'<div class="dialog-progress-fill" style="width: 0%"></div>' +
|
|
223
|
-
'</div>' +
|
|
224
|
-
'<p class="dialog-progress-percent">0%</p>' +
|
|
225
|
-
'</div>' +
|
|
226
|
-
'</div>';
|
|
227
|
-
|
|
228
|
-
showDialog(dialog, overlay);
|
|
229
|
-
|
|
230
|
-
var progressFill = dialog.querySelector('.dialog-progress-fill');
|
|
231
|
-
var progressPercent = dialog.querySelector('.dialog-progress-percent');
|
|
232
|
-
var progressMessage = dialog.querySelector('.progress-message');
|
|
233
|
-
|
|
234
|
-
return {
|
|
235
|
-
update: function(percent, message) {
|
|
236
|
-
progressFill.style.width = percent + '%';
|
|
237
|
-
progressPercent.textContent = Math.round(percent) + '%';
|
|
238
|
-
if (message) progressMessage.textContent = message;
|
|
239
|
-
},
|
|
240
|
-
close: function() {
|
|
241
|
-
closeDialog(dialog, overlay);
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
},
|
|
245
|
-
|
|
246
|
-
showToast: function(message, type, duration) {
|
|
247
|
-
var existing = document.querySelector('.toast-notification');
|
|
248
|
-
if (existing) existing.remove();
|
|
249
|
-
|
|
250
|
-
var toast = document.createElement('div');
|
|
251
|
-
toast.className = 'toast-notification toast-' + (type || 'info');
|
|
252
|
-
toast.innerHTML = '<span class="toast-message">' + escapeHtml(message) + '</span>';
|
|
253
|
-
document.body.appendChild(toast);
|
|
254
|
-
|
|
255
|
-
requestAnimationFrame(function() {
|
|
256
|
-
toast.classList.add('visible');
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
setTimeout(function() {
|
|
260
|
-
toast.classList.remove('visible');
|
|
261
|
-
setTimeout(function() { if (toast.parentNode) toast.remove(); }, 300);
|
|
262
|
-
}, duration || 3000);
|
|
263
|
-
},
|
|
264
|
-
|
|
265
|
-
closeAll: closeAllDialogs
|
|
266
|
-
};
|
|
267
|
-
})();
|
|
1
|
+
(function() {
|
|
2
|
+
var activeDialogs = [];
|
|
3
|
+
var dialogZIndex = 10000;
|
|
4
|
+
|
|
5
|
+
function escapeHtml(text) {
|
|
6
|
+
var map = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
|
|
7
|
+
return String(text).replace(/[&<>"']/g, function(c) { return map[c]; });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function createOverlay() {
|
|
11
|
+
var overlay = document.createElement('div');
|
|
12
|
+
overlay.className = 'dialog-overlay';
|
|
13
|
+
overlay.innerHTML = '<div class="dialog-backdrop"></div>';
|
|
14
|
+
return overlay;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function showDialog(dialog, overlay) {
|
|
18
|
+
dialogZIndex++;
|
|
19
|
+
if (overlay) {
|
|
20
|
+
overlay.style.zIndex = dialogZIndex;
|
|
21
|
+
document.body.appendChild(overlay);
|
|
22
|
+
}
|
|
23
|
+
dialog.style.zIndex = dialogZIndex + 1;
|
|
24
|
+
document.body.appendChild(dialog);
|
|
25
|
+
activeDialogs.push({ dialog: dialog, overlay: overlay });
|
|
26
|
+
|
|
27
|
+
requestAnimationFrame(function() {
|
|
28
|
+
dialog.classList.add('visible');
|
|
29
|
+
if (overlay) overlay.classList.add('visible');
|
|
30
|
+
var input = dialog.querySelector('input, textarea');
|
|
31
|
+
if (input) input.focus();
|
|
32
|
+
else {
|
|
33
|
+
var btn = dialog.querySelector('.dialog-btn-primary');
|
|
34
|
+
if (btn) btn.focus();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function closeDialog(dialog, overlay) {
|
|
40
|
+
dialog.classList.remove('visible');
|
|
41
|
+
if (overlay) overlay.classList.remove('visible');
|
|
42
|
+
setTimeout(function() {
|
|
43
|
+
if (dialog.parentNode) dialog.remove();
|
|
44
|
+
if (overlay && overlay.parentNode) overlay.remove();
|
|
45
|
+
}, 200);
|
|
46
|
+
activeDialogs = activeDialogs.filter(function(d) {
|
|
47
|
+
return d.dialog !== dialog;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function closeAllDialogs() {
|
|
52
|
+
activeDialogs.forEach(function(d) {
|
|
53
|
+
closeDialog(d.dialog, d.overlay);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
window.UIDialog = {
|
|
58
|
+
alert: function(message, title) {
|
|
59
|
+
return new Promise(function(resolve) {
|
|
60
|
+
var overlay = createOverlay();
|
|
61
|
+
var dialog = document.createElement('div');
|
|
62
|
+
dialog.className = 'dialog-container';
|
|
63
|
+
dialog.innerHTML =
|
|
64
|
+
'<div class="dialog-box">' +
|
|
65
|
+
'<div class="dialog-header">' +
|
|
66
|
+
'<h3 class="dialog-title">' + escapeHtml(title || 'Alert') + '</h3>' +
|
|
67
|
+
'</div>' +
|
|
68
|
+
'<div class="dialog-body">' +
|
|
69
|
+
'<p class="dialog-message">' + escapeHtml(message) + '</p>' +
|
|
70
|
+
'</div>' +
|
|
71
|
+
'<div class="dialog-footer">' +
|
|
72
|
+
'<button class="dialog-btn dialog-btn-primary" data-action="ok">OK</button>' +
|
|
73
|
+
'</div>' +
|
|
74
|
+
'</div>';
|
|
75
|
+
|
|
76
|
+
var okBtn = dialog.querySelector('[data-action="ok"]');
|
|
77
|
+
okBtn.addEventListener('click', function() {
|
|
78
|
+
closeDialog(dialog, overlay);
|
|
79
|
+
resolve(true);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
overlay.querySelector('.dialog-backdrop').addEventListener('click', function() {
|
|
83
|
+
closeDialog(dialog, overlay);
|
|
84
|
+
resolve(true);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
document.addEventListener('keydown', function handler(e) {
|
|
88
|
+
if (e.key === 'Escape' || e.key === 'Enter') {
|
|
89
|
+
document.removeEventListener('keydown', handler);
|
|
90
|
+
closeDialog(dialog, overlay);
|
|
91
|
+
resolve(true);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
showDialog(dialog, overlay);
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
confirm: function(message, title) {
|
|
100
|
+
return new Promise(function(resolve) {
|
|
101
|
+
var overlay = createOverlay();
|
|
102
|
+
var dialog = document.createElement('div');
|
|
103
|
+
dialog.className = 'dialog-container';
|
|
104
|
+
dialog.innerHTML =
|
|
105
|
+
'<div class="dialog-box">' +
|
|
106
|
+
'<div class="dialog-header">' +
|
|
107
|
+
'<h3 class="dialog-title">' + escapeHtml(title || 'Confirm') + '</h3>' +
|
|
108
|
+
'</div>' +
|
|
109
|
+
'<div class="dialog-body">' +
|
|
110
|
+
'<p class="dialog-message">' + escapeHtml(message).replace(/\n/g, '<br>') + '</p>' +
|
|
111
|
+
'</div>' +
|
|
112
|
+
'<div class="dialog-footer">' +
|
|
113
|
+
'<button class="dialog-btn dialog-btn-secondary" data-action="cancel">Cancel</button>' +
|
|
114
|
+
'<button class="dialog-btn dialog-btn-primary dialog-btn-danger" data-action="confirm">Confirm</button>' +
|
|
115
|
+
'</div>' +
|
|
116
|
+
'</div>';
|
|
117
|
+
|
|
118
|
+
var cancelBtn = dialog.querySelector('[data-action="cancel"]');
|
|
119
|
+
var confirmBtn = dialog.querySelector('[data-action="confirm"]');
|
|
120
|
+
|
|
121
|
+
cancelBtn.addEventListener('click', function() {
|
|
122
|
+
closeDialog(dialog, overlay);
|
|
123
|
+
resolve(false);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
confirmBtn.addEventListener('click', function() {
|
|
127
|
+
closeDialog(dialog, overlay);
|
|
128
|
+
resolve(true);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
overlay.querySelector('.dialog-backdrop').addEventListener('click', function() {
|
|
132
|
+
closeDialog(dialog, overlay);
|
|
133
|
+
resolve(false);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
document.addEventListener('keydown', function handler(e) {
|
|
137
|
+
if (e.key === 'Escape') {
|
|
138
|
+
document.removeEventListener('keydown', handler);
|
|
139
|
+
closeDialog(dialog, overlay);
|
|
140
|
+
resolve(false);
|
|
141
|
+
} else if (e.key === 'Enter') {
|
|
142
|
+
document.removeEventListener('keydown', handler);
|
|
143
|
+
closeDialog(dialog, overlay);
|
|
144
|
+
resolve(true);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
showDialog(dialog, overlay);
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
prompt: function(message, defaultValue, title) {
|
|
153
|
+
return new Promise(function(resolve) {
|
|
154
|
+
var overlay = createOverlay();
|
|
155
|
+
var dialog = document.createElement('div');
|
|
156
|
+
dialog.className = 'dialog-container';
|
|
157
|
+
dialog.innerHTML =
|
|
158
|
+
'<div class="dialog-box">' +
|
|
159
|
+
'<div class="dialog-header">' +
|
|
160
|
+
'<h3 class="dialog-title">' + escapeHtml(title || 'Input') + '</h3>' +
|
|
161
|
+
'</div>' +
|
|
162
|
+
'<div class="dialog-body">' +
|
|
163
|
+
'<label class="dialog-label">' + escapeHtml(message) + '</label>' +
|
|
164
|
+
'<input type="text" class="dialog-input" value="' + escapeHtml(defaultValue || '') + '">' +
|
|
165
|
+
'</div>' +
|
|
166
|
+
'<div class="dialog-footer">' +
|
|
167
|
+
'<button class="dialog-btn dialog-btn-secondary" data-action="cancel">Cancel</button>' +
|
|
168
|
+
'<button class="dialog-btn dialog-btn-primary" data-action="ok">OK</button>' +
|
|
169
|
+
'</div>' +
|
|
170
|
+
'</div>';
|
|
171
|
+
|
|
172
|
+
var input = dialog.querySelector('.dialog-input');
|
|
173
|
+
var cancelBtn = dialog.querySelector('[data-action="cancel"]');
|
|
174
|
+
var okBtn = dialog.querySelector('[data-action="ok"]');
|
|
175
|
+
|
|
176
|
+
cancelBtn.addEventListener('click', function() {
|
|
177
|
+
closeDialog(dialog, overlay);
|
|
178
|
+
resolve(null);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
okBtn.addEventListener('click', function() {
|
|
182
|
+
closeDialog(dialog, overlay);
|
|
183
|
+
resolve(input.value);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
input.addEventListener('keydown', function(e) {
|
|
187
|
+
if (e.key === 'Enter') {
|
|
188
|
+
closeDialog(dialog, overlay);
|
|
189
|
+
resolve(input.value);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
overlay.querySelector('.dialog-backdrop').addEventListener('click', function() {
|
|
194
|
+
closeDialog(dialog, overlay);
|
|
195
|
+
resolve(null);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
document.addEventListener('keydown', function handler(e) {
|
|
199
|
+
if (e.key === 'Escape') {
|
|
200
|
+
document.removeEventListener('keydown', handler);
|
|
201
|
+
closeDialog(dialog, overlay);
|
|
202
|
+
resolve(null);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
showDialog(dialog, overlay);
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
showProgress: function(config) {
|
|
211
|
+
var overlay = createOverlay();
|
|
212
|
+
var dialog = document.createElement('div');
|
|
213
|
+
dialog.className = 'dialog-container';
|
|
214
|
+
dialog.innerHTML =
|
|
215
|
+
'<div class="dialog-box dialog-box-progress">' +
|
|
216
|
+
'<div class="dialog-header">' +
|
|
217
|
+
'<h3 class="dialog-title">' + escapeHtml(config.title || 'Please wait') + '</h3>' +
|
|
218
|
+
'</div>' +
|
|
219
|
+
'<div class="dialog-body">' +
|
|
220
|
+
'<p class="dialog-message progress-message">' + escapeHtml(config.message || 'Loading...') + '</p>' +
|
|
221
|
+
'<div class="dialog-progress-bar">' +
|
|
222
|
+
'<div class="dialog-progress-fill" style="width: 0%"></div>' +
|
|
223
|
+
'</div>' +
|
|
224
|
+
'<p class="dialog-progress-percent">0%</p>' +
|
|
225
|
+
'</div>' +
|
|
226
|
+
'</div>';
|
|
227
|
+
|
|
228
|
+
showDialog(dialog, overlay);
|
|
229
|
+
|
|
230
|
+
var progressFill = dialog.querySelector('.dialog-progress-fill');
|
|
231
|
+
var progressPercent = dialog.querySelector('.dialog-progress-percent');
|
|
232
|
+
var progressMessage = dialog.querySelector('.progress-message');
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
update: function(percent, message) {
|
|
236
|
+
progressFill.style.width = percent + '%';
|
|
237
|
+
progressPercent.textContent = Math.round(percent) + '%';
|
|
238
|
+
if (message) progressMessage.textContent = message;
|
|
239
|
+
},
|
|
240
|
+
close: function() {
|
|
241
|
+
closeDialog(dialog, overlay);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
showToast: function(message, type, duration) {
|
|
247
|
+
var existing = document.querySelector('.toast-notification');
|
|
248
|
+
if (existing) existing.remove();
|
|
249
|
+
|
|
250
|
+
var toast = document.createElement('div');
|
|
251
|
+
toast.className = 'toast-notification toast-' + (type || 'info');
|
|
252
|
+
toast.innerHTML = '<span class="toast-message">' + escapeHtml(message) + '</span>';
|
|
253
|
+
document.body.appendChild(toast);
|
|
254
|
+
|
|
255
|
+
requestAnimationFrame(function() {
|
|
256
|
+
toast.classList.add('visible');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
setTimeout(function() {
|
|
260
|
+
toast.classList.remove('visible');
|
|
261
|
+
setTimeout(function() { if (toast.parentNode) toast.remove(); }, 300);
|
|
262
|
+
}, duration || 3000);
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
closeAll: closeAllDialogs
|
|
266
|
+
};
|
|
267
|
+
})();
|