@dmitryvim/form-builder 0.1.24 → 0.1.27

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.
@@ -1366,7 +1366,7 @@ function renderSelectElement(element, ctx, wrapper, pathKey) {
1366
1366
  // Common file preview rendering function for readonly mode
1367
1367
  function renderFilePreviewReadonly(resourceId, fileName) {
1368
1368
  const meta = state.resourceIndex.get(resourceId);
1369
- const actualFileName = fileName || meta?.name || "file";
1369
+ const actualFileName = fileName || meta?.name || resourceId.split("/").pop() || "file";
1370
1370
 
1371
1371
  // Individual file result container
1372
1372
  const fileResult = document.createElement("div");
@@ -1377,46 +1377,58 @@ function renderFilePreviewReadonly(resourceId, fileName) {
1377
1377
  previewContainer.className =
1378
1378
  "bg-gray-100 rounded-lg overflow-hidden cursor-pointer hover:opacity-90 transition-opacity";
1379
1379
 
1380
- // Check file type and render appropriate preview
1381
- if (
1382
- meta?.type?.startsWith("image/") ||
1383
- actualFileName.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/)
1384
- ) {
1385
- // Image preview
1380
+ // Determine if this looks like an image file
1381
+ const isImage = meta?.type?.startsWith("image/") ||
1382
+ actualFileName.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/);
1383
+
1384
+ // Determine if this looks like a video file
1385
+ const isVideo = meta?.type?.startsWith("video/") ||
1386
+ actualFileName.toLowerCase().match(/\.(mp4|webm|avi|mov)$/);
1387
+
1388
+ if (isImage) {
1389
+ // Image preview - try getThumbnail first
1386
1390
  if (state.config.getThumbnail) {
1387
- const thumbnailUrl = state.config.getThumbnail(resourceId);
1388
- if (thumbnailUrl) {
1389
- previewContainer.innerHTML = `<img src="${thumbnailUrl}" alt="${actualFileName}" class="w-full h-auto">`;
1390
- } else {
1391
+ try {
1392
+ const thumbnailUrl = state.config.getThumbnail(resourceId);
1393
+ if (thumbnailUrl) {
1394
+ previewContainer.innerHTML = `<img src="${thumbnailUrl}" alt="${actualFileName}" class="w-full h-auto">`;
1395
+ } else {
1396
+ // Fallback to icon if getThumbnail returns null/undefined
1397
+ previewContainer.innerHTML = `<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">🖼️</div><div class="text-sm">${actualFileName}</div></div></div>`;
1398
+ }
1399
+ } catch (error) {
1400
+ console.warn("getThumbnail failed for", resourceId, error);
1391
1401
  previewContainer.innerHTML = `<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">🖼️</div><div class="text-sm">${actualFileName}</div></div></div>`;
1392
1402
  }
1393
1403
  } else {
1394
1404
  previewContainer.innerHTML = `<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">🖼️</div><div class="text-sm">${actualFileName}</div></div></div>`;
1395
1405
  }
1396
- } else if (
1397
- meta?.type?.startsWith("video/") ||
1398
- actualFileName.toLowerCase().match(/\.(mp4|webm|avi|mov)$/)
1399
- ) {
1400
- // Video preview
1406
+ } else if (isVideo) {
1407
+ // Video preview - try getThumbnail for video URL
1401
1408
  if (state.config.getThumbnail) {
1402
- const thumbnailUrl = state.config.getThumbnail(resourceId);
1403
- if (thumbnailUrl) {
1404
- previewContainer.innerHTML = `
1405
- <div class="relative group">
1406
- <video class="w-full h-auto" controls preload="auto" muted>
1407
- <source src="${thumbnailUrl}" type="${meta?.type || "video/mp4"}">
1408
- Ваш браузер не поддерживает видео.
1409
- </video>
1410
- <div class="absolute inset-0 bg-black bg-opacity-20 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center pointer-events-none">
1411
- <div class="bg-white bg-opacity-90 rounded-full p-3">
1412
- <svg class="w-8 h-8 text-gray-800" fill="currentColor" viewBox="0 0 24 24">
1413
- <path d="M8 5v14l11-7z"/>
1414
- </svg>
1409
+ try {
1410
+ const videoUrl = state.config.getThumbnail(resourceId);
1411
+ if (videoUrl) {
1412
+ previewContainer.innerHTML = `
1413
+ <div class="relative group">
1414
+ <video class="w-full h-auto" controls preload="auto" muted>
1415
+ <source src="${videoUrl}" type="${meta?.type || "video/mp4"}">
1416
+ Ваш браузер не поддерживает видео.
1417
+ </video>
1418
+ <div class="absolute inset-0 bg-black bg-opacity-20 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center pointer-events-none">
1419
+ <div class="bg-white bg-opacity-90 rounded-full p-3">
1420
+ <svg class="w-8 h-8 text-gray-800" fill="currentColor" viewBox="0 0 24 24">
1421
+ <path d="M8 5v14l11-7z"/>
1422
+ </svg>
1423
+ </div>
1415
1424
  </div>
1416
1425
  </div>
1417
- </div>
1418
- `;
1419
- } else {
1426
+ `;
1427
+ } else {
1428
+ previewContainer.innerHTML = `<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">🎥</div><div class="text-sm">${actualFileName}</div></div></div>`;
1429
+ }
1430
+ } catch (error) {
1431
+ console.warn("getThumbnail failed for video", resourceId, error);
1420
1432
  previewContainer.innerHTML = `<div class="aspect-video flex items-center justify-center text-gray-400"><div class="text-center"><div class="text-4xl mb-2">🎥</div><div class="text-sm">${actualFileName}</div></div></div>`;
1421
1433
  }
1422
1434
  } else {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.24",
6
+ "version": "0.1.27",
7
7
  "description": "A reusable JSON schema form builder library",
8
8
  "main": "dist/form-builder.js",
9
9
  "module": "dist/form-builder.js",