cloud-ide-element 1.0.57 → 1.0.59
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/fesm2022/cloud-ide-element.mjs +106 -23
- package/fesm2022/cloud-ide-element.mjs.map +1 -1
- package/index.d.ts +13 -2
- package/package.json +1 -1
|
@@ -2835,6 +2835,19 @@ class CideEleFileManagerService {
|
|
|
2835
2835
|
this._error.set(errorMessage);
|
|
2836
2836
|
return throwError(() => new Error(errorMessage));
|
|
2837
2837
|
}
|
|
2838
|
+
/**
|
|
2839
|
+
* Get file details by ID
|
|
2840
|
+
* @param fileId The file ID to fetch details for
|
|
2841
|
+
* @returns Observable with file details
|
|
2842
|
+
*/
|
|
2843
|
+
getFileDetails(fileId) {
|
|
2844
|
+
console.log('🔍 [FileManagerService] Fetching file details for ID:', fileId.cyfm_id);
|
|
2845
|
+
// Create a GET request payload similar to the upload structure
|
|
2846
|
+
const payload = {
|
|
2847
|
+
core_file_manager_get: [fileId]
|
|
2848
|
+
};
|
|
2849
|
+
return this.http.post(`${this._baseUrl()}`, payload).pipe(retry(2), catchError(this.handleError.bind(this)), takeUntilDestroyed(this.destroyRef));
|
|
2850
|
+
}
|
|
2838
2851
|
/**
|
|
2839
2852
|
* Angular 20: Service utility methods
|
|
2840
2853
|
*/
|
|
@@ -3151,7 +3164,7 @@ class CideEleFileInputComponent {
|
|
|
3151
3164
|
return Math.round(this.uploadProgress() ** 1); // Simple power operation
|
|
3152
3165
|
}, ...(ngDevMode ? [{ debugName: "uploadProgressPercentage" }] : []));
|
|
3153
3166
|
// ControlValueAccessor callbacks
|
|
3154
|
-
onChange = (
|
|
3167
|
+
onChange = (value) => { };
|
|
3155
3168
|
onTouched = () => { };
|
|
3156
3169
|
onValidatorChange = () => { };
|
|
3157
3170
|
// Computed values
|
|
@@ -3175,11 +3188,31 @@ class CideEleFileInputComponent {
|
|
|
3175
3188
|
console.log('🎯 [FileInput] Component rendered and DOM is ready');
|
|
3176
3189
|
});
|
|
3177
3190
|
}
|
|
3178
|
-
writeValue(
|
|
3179
|
-
console.log('📝 [FileInput] writeValue called with:',
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3191
|
+
writeValue(value) {
|
|
3192
|
+
console.log('📝 [FileInput] writeValue called with:', value);
|
|
3193
|
+
if (typeof value === 'string') {
|
|
3194
|
+
// Value is an uploaded file ID - fetch file details and set preview
|
|
3195
|
+
console.log('📝 [FileInput] Value is uploaded file ID:', value);
|
|
3196
|
+
this.files.set(null);
|
|
3197
|
+
this.fileNames.set([]);
|
|
3198
|
+
this.clearPreviews();
|
|
3199
|
+
// Fetch file details to get base64 and set preview
|
|
3200
|
+
this.loadFileDetailsFromId(value);
|
|
3201
|
+
}
|
|
3202
|
+
else if (value instanceof FileList) {
|
|
3203
|
+
// Value is a FileList
|
|
3204
|
+
console.log('📝 [FileInput] Value is FileList:', Array.from(value).map(f => f.name));
|
|
3205
|
+
this.files.set(value);
|
|
3206
|
+
this.fileNames.set(Array.from(value).map(f => f.name));
|
|
3207
|
+
this.generatePreviews();
|
|
3208
|
+
}
|
|
3209
|
+
else {
|
|
3210
|
+
// Value is null
|
|
3211
|
+
console.log('📝 [FileInput] Value is null');
|
|
3212
|
+
this.files.set(null);
|
|
3213
|
+
this.fileNames.set([]);
|
|
3214
|
+
this.clearPreviews();
|
|
3215
|
+
}
|
|
3183
3216
|
}
|
|
3184
3217
|
registerOnChange(fn) {
|
|
3185
3218
|
this.onChange = fn;
|
|
@@ -3209,7 +3242,6 @@ class CideEleFileInputComponent {
|
|
|
3209
3242
|
this.onChange(selectedFiles);
|
|
3210
3243
|
this.fileChange.emit(selectedFiles);
|
|
3211
3244
|
this.onTouched();
|
|
3212
|
-
this.onValidatorChange();
|
|
3213
3245
|
// Auto upload if enabled
|
|
3214
3246
|
if (this.autoUpload() && selectedFiles && selectedFiles.length > 0) {
|
|
3215
3247
|
console.log('🚀 [FileInput] Auto upload enabled, starting upload for:', selectedFiles[0].name);
|
|
@@ -3228,7 +3260,6 @@ class CideEleFileInputComponent {
|
|
|
3228
3260
|
console.log('🔄 [FileInput] Upload status reset to:', this.uploadStatus());
|
|
3229
3261
|
this.onChange(null);
|
|
3230
3262
|
this.fileChange.emit(null);
|
|
3231
|
-
this.onValidatorChange();
|
|
3232
3263
|
}
|
|
3233
3264
|
uploadFile(file) {
|
|
3234
3265
|
console.log('📤 [FileInput] uploadFile called for:', file.name, 'Size:', file.size, 'bytes');
|
|
@@ -3238,9 +3269,6 @@ class CideEleFileInputComponent {
|
|
|
3238
3269
|
// Set upload status to 'start' before starting upload
|
|
3239
3270
|
this.uploadStatus.set('start');
|
|
3240
3271
|
console.log('🔄 [FileInput] Upload status set to:', this.uploadStatus());
|
|
3241
|
-
// Trigger validation update to show upload in progress error
|
|
3242
|
-
this.onValidatorChange();
|
|
3243
|
-
console.log('✅ [FileInput] Validation triggered - should show upload in progress error');
|
|
3244
3272
|
this.isUploading.set(true);
|
|
3245
3273
|
this.uploadProgress.set(0);
|
|
3246
3274
|
this.uploadProgressChange.emit(0);
|
|
@@ -3261,8 +3289,6 @@ class CideEleFileInputComponent {
|
|
|
3261
3289
|
if (this.uploadStatus() === 'start') {
|
|
3262
3290
|
this.uploadStatus.set('uploading');
|
|
3263
3291
|
console.log('🔄 [FileInput] Upload status changed to:', this.uploadStatus());
|
|
3264
|
-
this.onValidatorChange();
|
|
3265
|
-
console.log('✅ [FileInput] Validation triggered after status change to uploading');
|
|
3266
3292
|
}
|
|
3267
3293
|
// Update progress notification with spinner
|
|
3268
3294
|
const notificationId = this.uploadNotificationId();
|
|
@@ -3313,8 +3339,10 @@ class CideEleFileInputComponent {
|
|
|
3313
3339
|
const uploadedId = response?.data?.core_file_manager?.[0]?.cyfm_id;
|
|
3314
3340
|
if (uploadedId) {
|
|
3315
3341
|
console.log('✅ [FileInput] File uploaded successfully with ID:', uploadedId);
|
|
3342
|
+
// Set the uploaded ID as the form control value
|
|
3343
|
+
this.onChange(uploadedId);
|
|
3344
|
+
console.log('📝 [FileInput] Form control value set to uploaded ID:', uploadedId);
|
|
3316
3345
|
this.uploadSuccess.emit(uploadedId);
|
|
3317
|
-
// Note: Form control value remains as FileList - uploaded ID is emitted separately
|
|
3318
3346
|
console.log('📝 [FileInput] Upload success event emitted with file ID:', uploadedId);
|
|
3319
3347
|
}
|
|
3320
3348
|
else {
|
|
@@ -3323,9 +3351,6 @@ class CideEleFileInputComponent {
|
|
|
3323
3351
|
}
|
|
3324
3352
|
this.isUploading.set(false);
|
|
3325
3353
|
console.log('🔄 [FileInput] isUploading set to false');
|
|
3326
|
-
// Trigger validation update to clear upload in progress error
|
|
3327
|
-
this.onValidatorChange();
|
|
3328
|
-
console.log('✅ [FileInput] Validation triggered - should clear upload in progress error');
|
|
3329
3354
|
},
|
|
3330
3355
|
error: (error) => {
|
|
3331
3356
|
console.error('💥 [FileInput] Upload FAILED:', error);
|
|
@@ -3348,9 +3373,6 @@ class CideEleFileInputComponent {
|
|
|
3348
3373
|
this.uploadProgress.set(0);
|
|
3349
3374
|
this.uploadProgressChange.emit(0);
|
|
3350
3375
|
console.log('🔄 [FileInput] Upload state reset - isUploading: false, progress: 0%');
|
|
3351
|
-
// Trigger validation update to clear upload in progress error
|
|
3352
|
-
this.onValidatorChange();
|
|
3353
|
-
console.log('✅ [FileInput] Validation triggered - should clear upload in progress error');
|
|
3354
3376
|
}
|
|
3355
3377
|
});
|
|
3356
3378
|
}
|
|
@@ -3384,10 +3406,63 @@ class CideEleFileInputComponent {
|
|
|
3384
3406
|
isImageFile(file) {
|
|
3385
3407
|
return file.type.startsWith('image/');
|
|
3386
3408
|
}
|
|
3409
|
+
loadFileDetailsFromId(fileId) {
|
|
3410
|
+
console.log('🔍 [FileInput] Loading file details for ID:', fileId);
|
|
3411
|
+
this.fileManagerService?.getFileDetails({ cyfm_id: fileId })?.pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
|
|
3412
|
+
next: (fileDetails) => {
|
|
3413
|
+
console.log('📋 [FileInput] File details received:', fileDetails);
|
|
3414
|
+
if (fileDetails?.data?.length) {
|
|
3415
|
+
const fileData = fileDetails.data[0];
|
|
3416
|
+
console.log('📁 [FileInput] File data:', fileData);
|
|
3417
|
+
// Set file name from the details
|
|
3418
|
+
if (fileData.cyfm_name) {
|
|
3419
|
+
this.fileNames.set([fileData.cyfm_name]);
|
|
3420
|
+
console.log('📝 [FileInput] File name set:', fileData.cyfm_name);
|
|
3421
|
+
}
|
|
3422
|
+
// If it's an image and we have base64 data, set preview
|
|
3423
|
+
if (this.showPreview() && fileData.cyfm_file_base64) {
|
|
3424
|
+
// Check if it's an image file based on file name or type
|
|
3425
|
+
const isImage = this.isImageFileFromName(fileData.cyfm_name) ||
|
|
3426
|
+
this.isImageFileFromType(fileData.cyfm_type);
|
|
3427
|
+
if (isImage) {
|
|
3428
|
+
// Add data URL prefix if not already present
|
|
3429
|
+
let base64Data = fileData.cyfm_file_base64;
|
|
3430
|
+
if (!base64Data.startsWith('data:')) {
|
|
3431
|
+
const mimeType = fileData.cyfm_type || 'image/jpeg';
|
|
3432
|
+
base64Data = `data:${mimeType};base64,${base64Data}`;
|
|
3433
|
+
}
|
|
3434
|
+
this.previewUrls.set([base64Data]);
|
|
3435
|
+
console.log('🖼️ [FileInput] Preview set from base64 data');
|
|
3436
|
+
}
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3439
|
+
else {
|
|
3440
|
+
console.warn('⚠️ [FileInput] No file data found for ID:', fileId);
|
|
3441
|
+
}
|
|
3442
|
+
},
|
|
3443
|
+
error: (error) => {
|
|
3444
|
+
console.error('❌ [FileInput] Error loading file details:', error);
|
|
3445
|
+
this.notificationService.error(`Failed to load file details: ${error.message || 'Unknown error'}`, { duration: 0 });
|
|
3446
|
+
}
|
|
3447
|
+
});
|
|
3448
|
+
}
|
|
3449
|
+
isImageFileFromName(fileName) {
|
|
3450
|
+
if (!fileName)
|
|
3451
|
+
return false;
|
|
3452
|
+
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg'];
|
|
3453
|
+
const lowerFileName = fileName.toLowerCase();
|
|
3454
|
+
return imageExtensions.some(ext => lowerFileName.endsWith(ext));
|
|
3455
|
+
}
|
|
3456
|
+
isImageFileFromType(fileType) {
|
|
3457
|
+
if (!fileType)
|
|
3458
|
+
return false;
|
|
3459
|
+
return fileType.startsWith('image/');
|
|
3460
|
+
}
|
|
3387
3461
|
removePreview(index) {
|
|
3388
3462
|
const currentFiles = this.files();
|
|
3463
|
+
const currentUrls = this.previewUrls();
|
|
3389
3464
|
if (currentFiles && currentFiles.length > index) {
|
|
3390
|
-
//
|
|
3465
|
+
// Handle FileList case - remove file from FileList
|
|
3391
3466
|
const dt = new DataTransfer();
|
|
3392
3467
|
Array.from(currentFiles).forEach((file, i) => {
|
|
3393
3468
|
if (i !== index) {
|
|
@@ -3398,7 +3473,6 @@ class CideEleFileInputComponent {
|
|
|
3398
3473
|
this.files.set(newFiles);
|
|
3399
3474
|
this.fileNames.set(Array.from(newFiles).map(f => f.name));
|
|
3400
3475
|
// Remove the preview URL
|
|
3401
|
-
const currentUrls = this.previewUrls();
|
|
3402
3476
|
if (currentUrls[index] && currentUrls[index].startsWith('blob:')) {
|
|
3403
3477
|
URL.revokeObjectURL(currentUrls[index]);
|
|
3404
3478
|
}
|
|
@@ -3406,6 +3480,16 @@ class CideEleFileInputComponent {
|
|
|
3406
3480
|
this.onChange(newFiles);
|
|
3407
3481
|
this.fileChange.emit(newFiles);
|
|
3408
3482
|
}
|
|
3483
|
+
else if (currentUrls.length > index) {
|
|
3484
|
+
// Handle uploaded file ID case - clear the preview and set control value to null
|
|
3485
|
+
console.log('🗑️ [FileInput] Removing preview for uploaded file ID');
|
|
3486
|
+
// Clear preview
|
|
3487
|
+
this.previewUrls.update(urls => urls.filter((_, i) => i !== index));
|
|
3488
|
+
this.fileNames.set([]);
|
|
3489
|
+
// Set control value to null since we're removing the uploaded file
|
|
3490
|
+
this.onChange(null);
|
|
3491
|
+
this.fileChange.emit(null);
|
|
3492
|
+
}
|
|
3409
3493
|
}
|
|
3410
3494
|
ngOnDestroy() {
|
|
3411
3495
|
// Clean up preview URLs to prevent memory leaks
|
|
@@ -3506,7 +3590,6 @@ class CideEleFileInputComponent {
|
|
|
3506
3590
|
this.onChange(files);
|
|
3507
3591
|
this.fileChange.emit(files);
|
|
3508
3592
|
this.onTouched();
|
|
3509
|
-
this.onValidatorChange();
|
|
3510
3593
|
// Auto upload if enabled
|
|
3511
3594
|
if (this.autoUpload() && files.length > 0) {
|
|
3512
3595
|
console.log('🚀 [FileInput] Auto upload enabled, starting upload for:', files[0].name);
|