imcp 0.0.12 → 0.0.14

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.
Files changed (81) hide show
  1. package/dist/core/ConfigurationProvider.d.ts +2 -1
  2. package/dist/core/ConfigurationProvider.js +20 -24
  3. package/dist/core/InstallationService.d.ts +17 -0
  4. package/dist/core/InstallationService.js +127 -61
  5. package/dist/core/MCPManager.d.ts +1 -0
  6. package/dist/core/MCPManager.js +3 -0
  7. package/dist/core/RequirementService.d.ts +4 -4
  8. package/dist/core/RequirementService.js +11 -7
  9. package/dist/core/ServerSchemaProvider.d.ts +1 -1
  10. package/dist/core/ServerSchemaProvider.js +15 -10
  11. package/dist/core/constants.d.ts +3 -0
  12. package/dist/core/constants.js +4 -1
  13. package/dist/core/installers/clients/ClientInstaller.js +58 -40
  14. package/dist/core/installers/requirements/PipInstaller.js +10 -5
  15. package/dist/core/onboard/FeedOnboardService.d.ts +35 -0
  16. package/dist/core/onboard/FeedOnboardService.js +137 -0
  17. package/dist/core/types.d.ts +6 -1
  18. package/dist/core/validators/FeedValidator.d.ts +13 -0
  19. package/dist/core/validators/FeedValidator.js +27 -0
  20. package/dist/services/ServerService.d.ts +5 -0
  21. package/dist/services/ServerService.js +15 -0
  22. package/dist/utils/githubAuth.js +0 -10
  23. package/dist/utils/githubUtils.d.ts +16 -0
  24. package/dist/utils/githubUtils.js +55 -39
  25. package/dist/web/contract/serverContract.d.ts +64 -0
  26. package/dist/web/contract/serverContract.js +2 -0
  27. package/dist/web/public/css/detailsWidget.css +157 -32
  28. package/dist/web/public/css/onboard.css +44 -0
  29. package/dist/web/public/css/serverDetails.css +35 -19
  30. package/dist/web/public/index.html +16 -10
  31. package/dist/web/public/js/detailsWidget.js +43 -40
  32. package/dist/web/public/js/modal/index.js +58 -0
  33. package/dist/web/public/js/modal/installHandler.js +227 -0
  34. package/dist/web/public/js/modal/installModal.js +163 -0
  35. package/dist/web/public/js/modal/installation.js +281 -0
  36. package/dist/web/public/js/modal/loadingModal.js +52 -0
  37. package/dist/web/public/js/modal/loadingUI.js +74 -0
  38. package/dist/web/public/js/modal/messageQueue.js +112 -0
  39. package/dist/web/public/js/modal/modalSetup.js +512 -0
  40. package/dist/web/public/js/modal/modalUI.js +214 -0
  41. package/dist/web/public/js/modal/modalUtils.js +49 -0
  42. package/dist/web/public/js/modal/version.js +20 -0
  43. package/dist/web/public/js/modal/versionUtils.js +20 -0
  44. package/dist/web/public/js/modal.js +25 -1041
  45. package/dist/web/public/js/onboard/formProcessor.js +309 -0
  46. package/dist/web/public/js/onboard/index.js +131 -0
  47. package/dist/web/public/js/onboard/state.js +32 -0
  48. package/dist/web/public/js/onboard/templates.js +375 -0
  49. package/dist/web/public/js/onboard/uiHandlers.js +196 -0
  50. package/dist/web/public/js/serverCategoryDetails.js +211 -123
  51. package/dist/web/public/onboard.html +150 -0
  52. package/dist/web/server.js +25 -0
  53. package/package.json +3 -4
  54. package/src/core/ConfigurationProvider.ts +37 -29
  55. package/src/core/InstallationService.ts +176 -62
  56. package/src/core/MCPManager.ts +4 -0
  57. package/src/core/RequirementService.ts +12 -8
  58. package/src/core/ServerSchemaLoader.ts +48 -0
  59. package/src/core/ServerSchemaProvider.ts +137 -0
  60. package/src/core/constants.ts +4 -1
  61. package/src/core/installers/clients/ClientInstaller.ts +66 -49
  62. package/src/core/installers/requirements/PipInstaller.ts +10 -5
  63. package/src/core/types.ts +6 -1
  64. package/src/services/ServerService.ts +15 -0
  65. package/src/utils/githubAuth.ts +14 -27
  66. package/src/utils/githubUtils.ts +84 -47
  67. package/src/web/public/css/detailsWidget.css +235 -0
  68. package/src/web/public/css/serverDetails.css +126 -0
  69. package/src/web/public/index.html +16 -10
  70. package/src/web/public/js/detailsWidget.js +264 -0
  71. package/src/web/public/js/modal/index.js +58 -0
  72. package/src/web/public/js/modal/installModal.js +163 -0
  73. package/src/web/public/js/modal/installation.js +281 -0
  74. package/src/web/public/js/modal/loadingModal.js +52 -0
  75. package/src/web/public/js/modal/messageQueue.js +112 -0
  76. package/src/web/public/js/modal/modalSetup.js +512 -0
  77. package/src/web/public/js/modal/modalUtils.js +49 -0
  78. package/src/web/public/js/modal/versionUtils.js +20 -0
  79. package/src/web/public/js/modal.js +25 -1041
  80. package/src/web/public/js/serverCategoryDetails.js +211 -123
  81. package/src/web/server.ts +31 -0
@@ -0,0 +1,512 @@
1
+ import { showToast, showConfirm } from '../notifications.js';
2
+ import { showInstallLoadingModal } from './loadingModal.js';
3
+ import { delayedAppendInstallLoadingMessage } from './messageQueue.js';
4
+ import { uninstallTools } from './installation.js';
5
+ import { handleBulkClientInstall } from './installation.js';
6
+ import { compareVersions } from './versionUtils.js';
7
+
8
+ /**
9
+ * Set up client items in the modal
10
+ */
11
+ export function setupClientItems(targets, serverStatus, categoryName, serverName, targetDiv) {
12
+ targets.forEach(target => {
13
+ const operationStatus = serverStatus.installedStatus[target] || { status: 'not-installed', type: 'check', target: 'server' };
14
+
15
+ // Determine client status
16
+ let statusText = '';
17
+ let statusClass = '';
18
+
19
+ if (operationStatus.status === 'completed' && operationStatus.type === 'install') {
20
+ statusText = 'Installed';
21
+ statusClass = 'installed';
22
+ } else if (operationStatus.status === 'pending') {
23
+ statusText = 'Pending Requirements';
24
+ statusClass = 'pending';
25
+ } else if (operationStatus.status === 'in-progress') {
26
+ statusText = 'In Progress';
27
+ statusClass = 'pending';
28
+ } else if (operationStatus.status === 'failed') {
29
+ statusText = 'Failed';
30
+ statusClass = 'not-installed';
31
+ }
32
+
33
+ const isConfigured = operationStatus.status === 'completed' && operationStatus.type === 'install';
34
+ const isInProgress = operationStatus.status === 'in-progress';
35
+ const isSelectable = !isConfigured && !isInProgress;
36
+
37
+ const clientItem = createClientItem(target, statusText, statusClass, isSelectable, isConfigured, isInProgress);
38
+ setupClientItemListeners(clientItem, target, isSelectable);
39
+ setupUninstallButton(clientItem, statusText, operationStatus, target, categoryName, serverName, statusClass);
40
+ targetDiv.appendChild(clientItem);
41
+ });
42
+
43
+ addSectionTitle(targetDiv);
44
+ }
45
+
46
+ /**
47
+ * Set up environment variables section in the modal
48
+ */
49
+ export function setupEnvironmentVariables(mcpServer, envInputsDiv, targetData) {
50
+ // For SSE mode, don't show env section at all
51
+ if (mcpServer.mode === 'sse') {
52
+ envInputsDiv.style.display = 'none';
53
+ return;
54
+ }
55
+
56
+ const envRequirements = mcpServer.installation?.['env'] || mcpServer.installation?.env || {};
57
+ addEnvironmentTitle(envInputsDiv);
58
+
59
+ if (Object.keys(envRequirements).length === 0) {
60
+ addNoEnvMessage(envInputsDiv);
61
+ } else {
62
+ createEnvironmentInputs(envRequirements, envInputsDiv, targetData.clientMcpSettings, mcpServer.name);
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Set up installation arguments section in the modal
68
+ */
69
+ export function setupInstallationArguments(installation, modalArguments, mcpServer) {
70
+ // For SSE mode, don't show arguments section at all
71
+ if (mcpServer?.mode === 'sse') {
72
+ modalArguments.style.display = 'none';
73
+ return;
74
+ }
75
+
76
+ if (!installation) return;
77
+
78
+ addArgumentsTitle(modalArguments);
79
+ const container = createArgumentsContainer();
80
+ modalArguments.appendChild(container);
81
+
82
+ if (installation.args && Array.isArray(installation.args)) {
83
+ installation.args.forEach(arg => {
84
+ container.appendChild(createArgumentInput(arg));
85
+ });
86
+ } else {
87
+ container.appendChild(createArgumentInput());
88
+ }
89
+
90
+ if (installation.command === 'python' || installation.command.includes('python')) {
91
+ addPythonEnvironmentInput(modalArguments);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Set up server requirements section in the modal
97
+ */
98
+ export function setupServerRequirements(mcpServer, serverData, categoryName, serverName, modalRequirements) {
99
+ // For SSE mode, don't show requirements section at all
100
+ if (mcpServer.mode === 'sse') {
101
+ modalRequirements.style.display = 'none';
102
+ return;
103
+ }
104
+
105
+ const serverRequirements = mcpServer.dependencies?.requirements || [];
106
+ const requirements = serverData.data.installationStatus?.requirementsStatus || {};
107
+
108
+ if (serverRequirements.length > 0) {
109
+ const reqHtml = renderRequirements(serverRequirements, requirements, categoryName, serverName);
110
+ modalRequirements.innerHTML = `
111
+ <h3 class="text-lg font-semibold text-gray-700 mb-3">Dependencies</h3>
112
+ <p class="text-sm text-gray-600 mb-4">These dependencies will be automatically installed when installing the server</p>
113
+ ${reqHtml}
114
+ `;
115
+
116
+ setupUpdateToggles(modalRequirements);
117
+ } else {
118
+ modalRequirements.innerHTML = '<p class="text-gray-600">No additional dependencies required.</p>';
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Set up the form submit handler
124
+ */
125
+ export function setupFormSubmitHandler(form, envInputsDiv, modalArguments, modalRequirements, categoryName, serverName, serverStatuses, serverData, mcpServer) {
126
+ form.onsubmit = (e) => {
127
+ e.preventDefault();
128
+
129
+ const envVars = {};
130
+ const args = [];
131
+ const requirementsToUpdate = [];
132
+
133
+ // Only collect env, args and requirements if not in SSE mode
134
+ if (mcpServer?.mode !== 'sse') {
135
+ const inputs = envInputsDiv.querySelectorAll('input');
136
+ inputs.forEach(input => {
137
+ if (input.name && input.value) {
138
+ envVars[input.name] = input.value;
139
+ }
140
+ });
141
+
142
+ const argInputs = modalArguments.querySelectorAll('.arg-input');
143
+ args.push(...Array.from(argInputs)
144
+ .map(input => input.value.trim())
145
+ .filter(val => val !== ''));
146
+
147
+ const pythonEnvInput = document.getElementById('python_env');
148
+ const pythonEnv = pythonEnvInput?.value?.trim();
149
+
150
+ const updateToggles = modalRequirements.querySelectorAll('.toggle-update:checked');
151
+ updateToggles.forEach(toggle => {
152
+ requirementsToUpdate.push({
153
+ name: toggle.dataset.name,
154
+ version: toggle.dataset.version
155
+ });
156
+ });
157
+ }
158
+
159
+ const hasRequirementsToUpdate = requirementsToUpdate.length > 0;
160
+
161
+ const uninstallBtn = document.querySelector('.uninstall-btn');
162
+ if (!uninstallBtn || !uninstallBtn.matches(':active')) {
163
+ const selectedTargets = window.selectedClients;
164
+ if (selectedTargets.length === 0 && !hasRequirementsToUpdate) {
165
+ showToast('Please select at least one client to configure.', 'error');
166
+ return;
167
+ }
168
+
169
+ let installingMessage = "Starting installation...";
170
+ const serverStatus = serverStatuses[serverName] || { installedStatus: {} };
171
+ if (selectedTargets.length > 0) {
172
+ const target = selectedTargets[0];
173
+ const msg = serverStatus.installedStatus?.[target]?.message;
174
+ if (msg) installingMessage = msg;
175
+ }
176
+
177
+ const serverInstallOptions = {
178
+ targetClients: selectedTargets,
179
+ env: envVars,
180
+ args: args,
181
+ settings: {}
182
+ };
183
+
184
+ if (requirementsToUpdate.length > 0) {
185
+ serverInstallOptions.requirements = requirementsToUpdate;
186
+ }
187
+
188
+ handleBulkClientInstall(categoryName, serverName, selectedTargets, envVars, installingMessage, serverData, serverInstallOptions);
189
+ }
190
+ };
191
+ }
192
+
193
+ // Helper functions
194
+ function createClientItem(target, statusText, statusClass, isSelectable, isConfigured, isInProgress) {
195
+ const clientItem = document.createElement('div');
196
+ clientItem.className = 'client-item';
197
+ clientItem.dataset.target = target;
198
+ clientItem.dataset.selected = 'false';
199
+
200
+ // Create client info (name)
201
+ const clientInfo = document.createElement('div');
202
+ clientInfo.className = 'client-info';
203
+
204
+ // Client name label
205
+ const clientName = document.createElement('span');
206
+ clientName.className = 'text-sm font-medium text-gray-900';
207
+ clientName.textContent = target;
208
+
209
+ // Add elements to client info
210
+ clientInfo.appendChild(clientName);
211
+
212
+ // Add client info to client item
213
+ clientItem.appendChild(clientInfo);
214
+
215
+ if (!isSelectable) {
216
+ clientItem.classList.add('non-selectable');
217
+ if (isConfigured) {
218
+ clientItem.classList.add('installed-item');
219
+ clientItem.title = 'Already installed';
220
+ } else if (isInProgress) {
221
+ clientItem.classList.add('in-progress-item');
222
+ clientItem.title = 'Installation in progress';
223
+ }
224
+ }
225
+
226
+ return clientItem;
227
+ }
228
+
229
+ function setupClientItemListeners(clientItem, target, isSelectable) {
230
+ if (isSelectable) {
231
+ clientItem.addEventListener('click', () => {
232
+ const isSelected = clientItem.dataset.selected === 'true';
233
+ clientItem.dataset.selected = isSelected ? 'false' : 'true';
234
+
235
+ if (isSelected) {
236
+ clientItem.classList.remove('selected');
237
+ window.selectedClients = window.selectedClients.filter(c => c !== target);
238
+ } else {
239
+ clientItem.classList.add('selected');
240
+ if (!window.selectedClients.includes(target)) {
241
+ window.selectedClients.push(target);
242
+ }
243
+ }
244
+ });
245
+ }
246
+ }
247
+
248
+ function setupUninstallButton(clientItem, statusText, operationStatus, target, categoryName, serverName, statusClass) {
249
+ if (statusText) {
250
+ const statusContainer = document.createElement('div');
251
+ statusContainer.className = 'status-container';
252
+
253
+ const statusBadge = document.createElement('span');
254
+ statusBadge.className = `status-badge ${statusClass}`;
255
+ statusBadge.textContent = statusText;
256
+ statusContainer.appendChild(statusBadge);
257
+
258
+ if (operationStatus.status === 'completed' && operationStatus.type === 'install') {
259
+ const uninstallBtn = createUninstallButton(target, categoryName, serverName);
260
+ statusContainer.appendChild(uninstallBtn);
261
+ }
262
+
263
+ clientItem.appendChild(statusContainer);
264
+ }
265
+ }
266
+
267
+ function createUninstallButton(target, categoryName, serverName) {
268
+ const uninstallBtn = document.createElement('button');
269
+ uninstallBtn.className = 'uninstall-btn text-red-600 hover:text-red-800 ml-2';
270
+ uninstallBtn.innerHTML = '<i class="bx bx-trash"></i>';
271
+ uninstallBtn.title = 'Uninstall from this client';
272
+
273
+ uninstallBtn.onclick = async (e) => {
274
+ e.stopPropagation();
275
+ e.preventDefault();
276
+
277
+ const confirmed = await showConfirm('Uninstall Confirmation',
278
+ `Are you sure you want to uninstall ${serverName} from ${target}?`);
279
+
280
+ if (confirmed) {
281
+ window.selectedClients = [target];
282
+ showInstallLoadingModal('Uninstalling');
283
+ const serverList = {
284
+ [serverName]: {
285
+ removeData: true
286
+ }
287
+ };
288
+
289
+ try {
290
+ delayedAppendInstallLoadingMessage(`Uninstalling ${serverName} from ${target}...`);
291
+ await uninstallTools(categoryName, serverList, [target]);
292
+ } catch (error) {
293
+ delayedAppendInstallLoadingMessage(`Error: ${error.message}`);
294
+ throw error;
295
+ }
296
+ }
297
+ return false;
298
+ };
299
+
300
+ return uninstallBtn;
301
+ }
302
+
303
+ function addSectionTitle(targetDiv) {
304
+ if (!targetDiv.querySelector('.section-title')) {
305
+ const titleElement = document.createElement('h3');
306
+ titleElement.className = 'section-title text-lg font-semibold text-gray-700 mb-3';
307
+ titleElement.textContent = 'Client Status';
308
+ targetDiv.insertBefore(titleElement, targetDiv.firstChild);
309
+ }
310
+ }
311
+
312
+ function addEnvironmentTitle(envInputsDiv) {
313
+ if (!envInputsDiv.querySelector('.section-title')) {
314
+ const envTitle = document.createElement('h3');
315
+ envTitle.className = 'section-title text-lg font-semibold text-gray-700 mb-3';
316
+ envTitle.textContent = 'Environment Variables';
317
+ envInputsDiv.insertBefore(envTitle, envInputsDiv.firstChild);
318
+ }
319
+ }
320
+
321
+ function addNoEnvMessage(envInputsDiv) {
322
+ const noEnvMessage = document.createElement('p');
323
+ noEnvMessage.className = 'text-gray-600';
324
+ noEnvMessage.textContent = 'No environment variables required for this MCP server.';
325
+ envInputsDiv.appendChild(noEnvMessage);
326
+ }
327
+
328
+ function createEnvironmentInputs(envRequirements, envInputsDiv, clientSettings, serverName) {
329
+ Object.keys(envRequirements).forEach(key => {
330
+ const req = envRequirements[key];
331
+ const inputId = `env_${key}`;
332
+ const inputWrapper = document.createElement('div');
333
+ inputWrapper.className = 'mb-3';
334
+
335
+ const label = document.createElement('label');
336
+ label.htmlFor = inputId;
337
+ label.className = 'block text-sm font-medium text-gray-700 mb-1';
338
+ label.innerHTML = `${key} ${req.Required ? '<span class="text-red-500">*</span>' : ''}`;
339
+
340
+ const input = document.createElement('input');
341
+ input.type = req.isSecret ? 'password' : 'text';
342
+ input.id = inputId;
343
+ input.name = key;
344
+ input.placeholder = req.Description || key;
345
+ input.required = req.Required;
346
+ input.className = 'input-field';
347
+
348
+ // For default value, first check settings for the target server, then use the provided default
349
+ let defaultValue = req.Default || '';
350
+
351
+ // Check if we have settings from client configuration
352
+ if (clientSettings && clientSettings.MSRooCode &&
353
+ clientSettings.MSRooCode.mcpServers &&
354
+ clientSettings.MSRooCode.mcpServers[serverName] &&
355
+ clientSettings.MSRooCode.mcpServers[serverName].env &&
356
+ clientSettings.MSRooCode.mcpServers[serverName].env[key]) {
357
+ defaultValue = clientSettings.MSRooCode.mcpServers[serverName].env[key];
358
+ }
359
+
360
+ input.value = defaultValue;
361
+
362
+ inputWrapper.appendChild(label);
363
+ inputWrapper.appendChild(input);
364
+
365
+ if (req.Description) {
366
+ const description = document.createElement('p');
367
+ description.className = 'text-xs text-gray-500 mt-1';
368
+ description.textContent = req.Description;
369
+ inputWrapper.appendChild(description);
370
+ }
371
+
372
+ envInputsDiv.appendChild(inputWrapper);
373
+ });
374
+ }
375
+
376
+ function addArgumentsTitle(modalArguments) {
377
+ const argsTitle = document.createElement('h3');
378
+ argsTitle.className = 'section-title text-lg font-semibold text-gray-700 mb-3';
379
+ argsTitle.textContent = 'Arguments';
380
+ modalArguments.appendChild(argsTitle);
381
+ }
382
+
383
+ function createArgumentsContainer() {
384
+ const container = document.createElement('div');
385
+ container.className = 'args-container mb-3';
386
+
387
+ const addButton = document.createElement('button');
388
+ addButton.type = 'button';
389
+ addButton.className = 'add-arg-button px-3 py-1 text-sm text-blue-600 hover:text-blue-800 border border-blue-600 hover:border-blue-800 rounded-md mb-2';
390
+ addButton.innerHTML = '<i class="bx bx-plus"></i> Add Argument';
391
+ addButton.onclick = () => container.appendChild(createArgumentInput());
392
+
393
+ container.appendChild(addButton);
394
+ return container;
395
+ }
396
+
397
+ function createArgumentInput(value = '') {
398
+ const argWrapper = document.createElement('div');
399
+ argWrapper.className = 'arg-wrapper flex items-center gap-2 mb-2';
400
+
401
+ const input = document.createElement('input');
402
+ input.type = 'text';
403
+ input.className = 'arg-input flex-grow';
404
+ input.value = value;
405
+ input.placeholder = 'Enter argument value';
406
+
407
+ const removeButton = document.createElement('button');
408
+ removeButton.type = 'button';
409
+ removeButton.className = 'remove-arg-button text-red-600 hover:text-red-800';
410
+ removeButton.innerHTML = '<i class="bx bx-trash"></i>';
411
+ removeButton.onclick = () => argWrapper.remove();
412
+
413
+ argWrapper.appendChild(input);
414
+ argWrapper.appendChild(removeButton);
415
+ return argWrapper;
416
+ }
417
+
418
+ function addPythonEnvironmentInput(modalArguments) {
419
+ const pythonEnvWrapper = document.createElement('div');
420
+ pythonEnvWrapper.className = 'mt-4';
421
+
422
+ const pythonEnvLabel = document.createElement('label');
423
+ pythonEnvLabel.htmlFor = 'python_env';
424
+ pythonEnvLabel.className = 'block text-sm font-medium text-gray-700 mb-1';
425
+ pythonEnvLabel.textContent = 'Python Environment';
426
+
427
+ const pythonEnvInput = document.createElement('input');
428
+ pythonEnvInput.type = 'text';
429
+ pythonEnvInput.id = 'python_env';
430
+ pythonEnvInput.className = 'input-field';
431
+ pythonEnvInput.placeholder = 'Enter Python environment path (optional)';
432
+
433
+ const envDescription = document.createElement('p');
434
+ envDescription.className = 'text-xs text-gray-500 mt-1';
435
+ envDescription.textContent = 'Specify the Python executable file(e.g. C:/python312/python) to use for installation. Leave empty to use system default.';
436
+
437
+ pythonEnvWrapper.appendChild(pythonEnvLabel);
438
+ pythonEnvWrapper.appendChild(pythonEnvInput);
439
+ pythonEnvWrapper.appendChild(envDescription);
440
+ modalArguments.appendChild(pythonEnvWrapper);
441
+ }
442
+
443
+ function renderRequirements(serverRequirements, requirements, categoryName, serverName) {
444
+ return serverRequirements.map(req => {
445
+ const status = requirements[req.name] || {};
446
+ let statusClass = status.installed
447
+ ? 'text-green-600 bg-green-50'
448
+ : 'text-yellow-600 bg-yellow-50';
449
+ let statusText = status.installed ? 'Installed' : 'Required';
450
+ let versionDisplay = status.version ? ` • <span class="font-medium">${status.version}</span>` : '';
451
+ let updateToggle = '';
452
+
453
+ // Check if there's an available update
454
+ if (status.installed && status.availableUpdate && status.availableUpdate.version) {
455
+ if (status.version && compareVersions(status.availableUpdate.version, status.version) > 0) {
456
+ // Show version update information with yellow color and icon
457
+ statusClass = 'text-yellow-600 bg-yellow-50';
458
+ statusText = `<span style="color: #f59e0b; font-weight: bold; margin-right: 5px;">↑</span>${status.availableUpdate.version}`;
459
+
460
+ // Create a toggle switch for update
461
+ updateToggle = `
462
+ <label class="inline-flex items-center cursor-pointer ml-2">
463
+ <input type="checkbox" class="toggle-update sr-only"
464
+ data-name="${req.name}"
465
+ data-version="${status.availableUpdate.version}"
466
+ data-category="${categoryName}"
467
+ data-server="${serverName}">
468
+ <div class="relative w-10 h-5 bg-gray-200 rounded-full toggle-bg">
469
+ <div class="absolute inset-y-0 left-0 w-5 h-5 bg-white rounded-full transition-transform duration-300 transform"></div>
470
+ </div>
471
+ <span class="ml-2 text-sm text-gray-700">Update</span>
472
+ </label>
473
+ `;
474
+ }
475
+ }
476
+
477
+ return `
478
+ <div class="border border-gray-200 p-3 rounded-lg mb-2 hover:bg-gray-50">
479
+ <div class="flex justify-between items-center">
480
+ <div>
481
+ <div class="font-semibold text-gray-800">${req.name}</div>
482
+ <div class="text-sm text-gray-600 shadow-sm p-1 rounded bg-gray-50">
483
+ <span class="font-medium">${status.type || 'package'}</span>${versionDisplay}
484
+ </div>
485
+ </div>
486
+ <div class="flex items-center">
487
+ <span class="${statusClass} inline-flex items-center px-3 py-1 rounded-full text-sm">
488
+ ${statusText}
489
+ </span>
490
+ ${updateToggle}
491
+ </div>
492
+ </div>
493
+ </div>
494
+ `;
495
+ }).join('');
496
+ }
497
+
498
+ function setupUpdateToggles(modalRequirements) {
499
+ const updateToggles = modalRequirements.querySelectorAll('.toggle-update');
500
+ updateToggles.forEach(toggle => {
501
+ toggle.addEventListener('change', function () {
502
+ const toggleBg = this.parentElement.querySelector('.toggle-bg');
503
+ if (this.checked) {
504
+ toggleBg.classList.add('bg-blue-500');
505
+ toggleBg.querySelector('div').classList.add('translate-x-5');
506
+ } else {
507
+ toggleBg.classList.remove('bg-blue-500');
508
+ toggleBg.querySelector('div').classList.remove('translate-x-5');
509
+ }
510
+ });
511
+ });
512
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Close modal and ensure selected category persists
3
+ */
4
+ export function closeModal() {
5
+ document.getElementById('installModal').style.display = "none";
6
+
7
+ // Get the last selected category from localStorage
8
+ const lastSelected = localStorage.getItem('lastSelectedCategory');
9
+
10
+ // Refresh page and restore selection
11
+ if (lastSelected) {
12
+ setTimeout(() => {
13
+ window.location.href = window.location.pathname + '?category=' + encodeURIComponent(lastSelected);
14
+ }, 100);
15
+ } else {
16
+ location.reload();
17
+ }
18
+ }
19
+
20
+ /**
21
+ * Close modal if clicked outside content
22
+ */
23
+ export function setupModalOutsideClick() {
24
+ window.onclick = function (event) {
25
+ const installModal = document.getElementById('installModal');
26
+ if (event.target == installModal) {
27
+ closeModal();
28
+ }
29
+ };
30
+ }
31
+
32
+ /**
33
+ * Setup toggle switch styles
34
+ */
35
+ export function setupToggleStyles() {
36
+ const styleElement = document.createElement('style');
37
+ styleElement.textContent = `
38
+ .toggle-bg.bg-blue-500 {
39
+ background-color: #3b82f6;
40
+ }
41
+ .toggle-bg {
42
+ transition: background-color 0.3s;
43
+ }
44
+ .toggle-bg div {
45
+ transition: transform 0.3s;
46
+ }
47
+ `;
48
+ document.head.appendChild(styleElement);
49
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Simple version comparison function
3
+ * @param {string} v1 First version
4
+ * @param {string} v2 Second version
5
+ * @returns {number} 1 if v1 > v2, -1 if v1 < v2, 0 if equal
6
+ */
7
+ export function compareVersions(v1, v2) {
8
+ const v1Parts = v1.split('.').map(Number);
9
+ const v2Parts = v2.split('.').map(Number);
10
+
11
+ for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
12
+ const v1Part = v1Parts[i] || 0;
13
+ const v2Part = v2Parts[i] || 0;
14
+
15
+ if (v1Part > v2Part) return 1;
16
+ if (v1Part < v2Part) return -1;
17
+ }
18
+
19
+ return 0;
20
+ }