verben-workflow-ui 0.7.9 → 0.8.2

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 (33) hide show
  1. package/esm2022/public-api.mjs +3 -1
  2. package/esm2022/src/lib/components/file-render/excel-parser.util.mjs +239 -0
  3. package/esm2022/src/lib/components/file-render/file-preview.component.mjs +361 -0
  4. package/esm2022/src/lib/components/file-render/file-render.component.mjs +78 -10
  5. package/esm2022/src/lib/components/file-render/file-render.module.mjs +11 -7
  6. package/esm2022/src/lib/components/file-render/public-api.mjs +2 -1
  7. package/esm2022/src/lib/components/file-upload/file-upload.component.mjs +37 -3
  8. package/esm2022/src/lib/components/form-control/form-control.component.mjs +1 -1
  9. package/esm2022/src/lib/components/task-history/task-history.component.mjs +5 -4
  10. package/esm2022/src/lib/components/task-history/task-history.module.mjs +19 -4
  11. package/esm2022/src/lib/components/workflow-designer/designer-canvas/designer-canvas.component.mjs +15 -5
  12. package/esm2022/src/lib/components/workflow-designer/workflow-designer.component.mjs +2 -1
  13. package/fesm2022/verben-workflow-ui-src-lib-components-file-render.mjs +681 -17
  14. package/fesm2022/verben-workflow-ui-src-lib-components-file-render.mjs.map +1 -1
  15. package/fesm2022/verben-workflow-ui-src-lib-components-file-upload.mjs +36 -2
  16. package/fesm2022/verben-workflow-ui-src-lib-components-file-upload.mjs.map +1 -1
  17. package/fesm2022/verben-workflow-ui-src-lib-components-form-control.mjs +1 -1
  18. package/fesm2022/verben-workflow-ui-src-lib-components-form-control.mjs.map +1 -1
  19. package/fesm2022/verben-workflow-ui-src-lib-components-task-history.mjs +22 -6
  20. package/fesm2022/verben-workflow-ui-src-lib-components-task-history.mjs.map +1 -1
  21. package/fesm2022/verben-workflow-ui-src-lib-components-workflow-designer.mjs +15 -4
  22. package/fesm2022/verben-workflow-ui-src-lib-components-workflow-designer.mjs.map +1 -1
  23. package/fesm2022/verben-workflow-ui.mjs +2 -0
  24. package/fesm2022/verben-workflow-ui.mjs.map +1 -1
  25. package/package.json +46 -46
  26. package/public-api.d.ts +2 -0
  27. package/src/lib/components/file-render/excel-parser.util.d.ts +12 -0
  28. package/src/lib/components/file-render/file-preview.component.d.ts +66 -0
  29. package/src/lib/components/file-render/file-render.component.d.ts +17 -4
  30. package/src/lib/components/file-render/file-render.module.d.ts +5 -4
  31. package/src/lib/components/file-render/public-api.d.ts +1 -0
  32. package/src/lib/components/file-upload/file-upload.component.d.ts +7 -1
  33. package/src/lib/components/task-history/task-history.module.d.ts +4 -3
@@ -1,41 +1,700 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { EventEmitter, Component, Input, Output, NgModule } from '@angular/core';
3
3
  import * as i1 from 'verben-workflow-ui/src/lib/services';
4
- import * as i2 from '@angular/common';
4
+ import * as i3 from '@angular/common';
5
5
  import { CommonModule } from '@angular/common';
6
- import * as i3 from 'verben-ng-ui';
7
- import { SvgModule, VerbenaButtonModule } from 'verben-ng-ui';
6
+ import * as i4 from 'verben-ng-ui';
7
+ import { SvgModule, VerbenaButtonModule, VerbenDialogueModule } from 'verben-ng-ui';
8
+ import * as i2 from '@angular/platform-browser';
8
9
  import { FormsModule, ReactiveFormsModule } from '@angular/forms';
9
10
 
11
+ /**
12
+ * Parses CSV or TSV text into a single-sheet table using RFC-4180 quoting rules.
13
+ */
14
+ function parseDelimitedText(text, delimiter = ',', sheetName = 'Sheet1') {
15
+ const rows = [];
16
+ let row = [];
17
+ let cell = '';
18
+ let inQuotes = false;
19
+ for (let i = 0; i < text.length; i++) {
20
+ const ch = text[i];
21
+ const next = text[i + 1];
22
+ if (inQuotes) {
23
+ if (ch === '"' && next === '"') {
24
+ cell += '"';
25
+ i++;
26
+ }
27
+ else if (ch === '"') {
28
+ inQuotes = false;
29
+ }
30
+ else {
31
+ cell += ch;
32
+ }
33
+ }
34
+ else if (ch === '"') {
35
+ inQuotes = true;
36
+ }
37
+ else if (ch === delimiter) {
38
+ row.push(cell);
39
+ cell = '';
40
+ }
41
+ else if (ch === '\r' && next === '\n') {
42
+ row.push(cell);
43
+ rows.push(row);
44
+ row = [];
45
+ cell = '';
46
+ i++;
47
+ }
48
+ else if (ch === '\n' || ch === '\r') {
49
+ row.push(cell);
50
+ rows.push(row);
51
+ row = [];
52
+ cell = '';
53
+ }
54
+ else {
55
+ cell += ch;
56
+ }
57
+ }
58
+ if (cell.length > 0 || row.length > 0) {
59
+ row.push(cell);
60
+ rows.push(row);
61
+ }
62
+ return [{ name: sheetName, rows }];
63
+ }
64
+ /**
65
+ * Parses an OOXML `.xlsx` ArrayBuffer into worksheets without external dependencies.
66
+ */
67
+ async function parseXlsxBuffer(buffer) {
68
+ const entries = await extractZipEntries(buffer);
69
+ const decoder = new TextDecoder('utf-8');
70
+ const parser = new DOMParser();
71
+ const sharedStringsXml = entries.get('xl/sharedStrings.xml');
72
+ const sharedStrings = [];
73
+ if (sharedStringsXml) {
74
+ const doc = parser.parseFromString(decoder.decode(sharedStringsXml), 'application/xml');
75
+ const siNodes = Array.from(doc.getElementsByTagName('si'));
76
+ for (const si of siNodes) {
77
+ const tNodes = Array.from(si.getElementsByTagName('t'));
78
+ sharedStrings.push(tNodes.map((t) => t.textContent || '').join(''));
79
+ }
80
+ }
81
+ const relsMap = new Map();
82
+ const relsXml = entries.get('xl/_rels/workbook.xml.rels');
83
+ if (relsXml) {
84
+ const doc = parser.parseFromString(decoder.decode(relsXml), 'application/xml');
85
+ const rels = Array.from(doc.getElementsByTagName('Relationship'));
86
+ for (const rel of rels) {
87
+ const id = rel.getAttribute('Id');
88
+ const target = rel.getAttribute('Target');
89
+ if (id && target) {
90
+ const normalized = target.startsWith('/')
91
+ ? target.slice(1)
92
+ : target.startsWith('xl/')
93
+ ? target
94
+ : `xl/${target}`;
95
+ relsMap.set(id, normalized);
96
+ }
97
+ }
98
+ }
99
+ const sheetTargets = [];
100
+ const workbookXml = entries.get('xl/workbook.xml');
101
+ if (workbookXml) {
102
+ const doc = parser.parseFromString(decoder.decode(workbookXml), 'application/xml');
103
+ const sheetNodes = Array.from(doc.getElementsByTagName('sheet'));
104
+ sheetNodes.forEach((node, idx) => {
105
+ const name = node.getAttribute('name') || `Sheet${idx + 1}`;
106
+ const rId = node.getAttribute('r:id') ||
107
+ node.getAttributeNS('http://schemas.openxmlformats.org/officeDocument/2006/relationships', 'id');
108
+ const path = (rId && relsMap.get(rId)) || `xl/worksheets/sheet${idx + 1}.xml`;
109
+ sheetTargets.push({ name, path });
110
+ });
111
+ }
112
+ if (sheetTargets.length === 0) {
113
+ for (const key of Array.from(entries.keys()).sort()) {
114
+ if (/^xl\/worksheets\/sheet\d+\.xml$/i.test(key)) {
115
+ sheetTargets.push({
116
+ name: `Sheet${sheetTargets.length + 1}`,
117
+ path: key,
118
+ });
119
+ }
120
+ }
121
+ }
122
+ const sheets = [];
123
+ for (const target of sheetTargets) {
124
+ const sheetBytes = entries.get(target.path);
125
+ if (!sheetBytes)
126
+ continue;
127
+ const doc = parser.parseFromString(decoder.decode(sheetBytes), 'application/xml');
128
+ const rows = parseWorksheetXml(doc, sharedStrings);
129
+ sheets.push({ name: target.name, rows });
130
+ }
131
+ return sheets;
132
+ }
133
+ function parseWorksheetXml(doc, sharedStrings) {
134
+ const rowNodes = Array.from(doc.getElementsByTagName('row'));
135
+ const rows = [];
136
+ let maxCols = 0;
137
+ for (const rowNode of rowNodes) {
138
+ const cells = Array.from(rowNode.getElementsByTagName('c'));
139
+ const rowValues = [];
140
+ let fallbackCol = 0;
141
+ for (const c of cells) {
142
+ const ref = c.getAttribute('r');
143
+ const colIndex = ref ? columnRefToIndex(ref) : fallbackCol;
144
+ fallbackCol = colIndex + 1;
145
+ while (rowValues.length <= colIndex) {
146
+ rowValues.push('');
147
+ }
148
+ const type = c.getAttribute('t');
149
+ if (type === 'inlineStr') {
150
+ const tNodes = Array.from(c.getElementsByTagName('t'));
151
+ rowValues[colIndex] = tNodes.map((t) => t.textContent || '').join('');
152
+ }
153
+ else {
154
+ const vNode = c.getElementsByTagName('v')[0];
155
+ const raw = vNode?.textContent ?? '';
156
+ if (type === 's') {
157
+ const idx = parseInt(raw, 10);
158
+ rowValues[colIndex] = !isNaN(idx) ? (sharedStrings[idx] ?? '') : raw;
159
+ }
160
+ else if (type === 'b') {
161
+ rowValues[colIndex] = raw === '1' ? 'TRUE' : 'FALSE';
162
+ }
163
+ else {
164
+ rowValues[colIndex] = raw;
165
+ }
166
+ }
167
+ }
168
+ maxCols = Math.max(maxCols, rowValues.length);
169
+ rows.push(rowValues);
170
+ }
171
+ // Normalize row lengths so the table grid renders evenly
172
+ for (const r of rows) {
173
+ while (r.length < maxCols) {
174
+ r.push('');
175
+ }
176
+ }
177
+ return rows;
178
+ }
179
+ function columnRefToIndex(ref) {
180
+ const letters = ref.replace(/[^A-Za-z]/g, '').toUpperCase();
181
+ let col = 0;
182
+ for (let i = 0; i < letters.length; i++) {
183
+ col = col * 26 + (letters.charCodeAt(i) - 64);
184
+ }
185
+ return Math.max(0, col - 1);
186
+ }
187
+ async function extractZipEntries(buffer) {
188
+ const bytes = new Uint8Array(buffer);
189
+ const view = new DataView(buffer);
190
+ const decoder = new TextDecoder('utf-8');
191
+ const entries = new Map();
192
+ // Locate End of Central Directory (0x06054b50)
193
+ let eocdOffset = -1;
194
+ const minOffset = Math.max(0, bytes.length - 65557);
195
+ for (let i = bytes.length - 22; i >= minOffset; i--) {
196
+ if (view.getUint32(i, true) === 0x06054b50) {
197
+ eocdOffset = i;
198
+ break;
199
+ }
200
+ }
201
+ if (eocdOffset === -1) {
202
+ throw new Error('Invalid XLSX/ZIP archive');
203
+ }
204
+ const cdOffset = view.getUint32(eocdOffset + 16, true);
205
+ const totalEntries = view.getUint16(eocdOffset + 10, true);
206
+ let ptr = cdOffset;
207
+ for (let i = 0; i < totalEntries && ptr + 46 <= bytes.length; i++) {
208
+ if (view.getUint32(ptr, true) !== 0x02014b50)
209
+ break;
210
+ const compression = view.getUint16(ptr + 10, true);
211
+ const compressedSize = view.getUint32(ptr + 20, true);
212
+ const nameLen = view.getUint16(ptr + 28, true);
213
+ const extraLen = view.getUint16(ptr + 30, true);
214
+ const commentLen = view.getUint16(ptr + 32, true);
215
+ const localHeaderOffset = view.getUint32(ptr + 42, true);
216
+ const name = decoder.decode(bytes.subarray(ptr + 46, ptr + 46 + nameLen));
217
+ ptr += 46 + nameLen + extraLen + commentLen;
218
+ if (name.endsWith('/') || localHeaderOffset + 30 > bytes.length)
219
+ continue;
220
+ if (view.getUint32(localHeaderOffset, true) !== 0x04034b50)
221
+ continue;
222
+ const lfhNameLen = view.getUint16(localHeaderOffset + 26, true);
223
+ const lfhExtraLen = view.getUint16(localHeaderOffset + 28, true);
224
+ const dataStart = localHeaderOffset + 30 + lfhNameLen + lfhExtraLen;
225
+ const compressed = bytes.subarray(dataStart, dataStart + compressedSize);
226
+ if (compression === 0) {
227
+ entries.set(name, compressed);
228
+ }
229
+ else if (compression === 8) {
230
+ const decompressed = await inflateRaw(compressed);
231
+ entries.set(name, decompressed);
232
+ }
233
+ }
234
+ return entries;
235
+ }
236
+ async function inflateRaw(compressed) {
237
+ if (typeof DecompressionStream === 'undefined') {
238
+ throw new Error('DecompressionStream is not supported in this browser');
239
+ }
240
+ const ds = new DecompressionStream('deflate-raw');
241
+ const writer = ds.writable.getWriter();
242
+ const copy = new Uint8Array(compressed.byteLength);
243
+ copy.set(compressed);
244
+ writer.write(copy);
245
+ writer.close();
246
+ const ab = await new Response(ds.readable).arrayBuffer();
247
+ return new Uint8Array(ab);
248
+ }
249
+
250
+ class FilePreviewComponent {
251
+ envService;
252
+ sanitizer;
253
+ isVisible = false;
254
+ file = null;
255
+ files = [];
256
+ initialIndex = 0;
257
+ fileUrl = null;
258
+ fileName = null;
259
+ confirmMode = false;
260
+ confirmText = 'Proceed';
261
+ closed = new EventEmitter();
262
+ confirmed = new EventEmitter();
263
+ openExternal = new EventEmitter();
264
+ activeIndex = 0;
265
+ isLoading = false;
266
+ errorMessage = null;
267
+ previewKind = 'unsupported';
268
+ resolvedName = '';
269
+ fileSizeLabel = '';
270
+ extensionLabel = '';
271
+ imageSrc = null;
272
+ safePdfUrl = null;
273
+ textContent = '';
274
+ sheets = [];
275
+ activeSheetIndex = 0;
276
+ imageZoom = 100;
277
+ objectUrl = null;
278
+ constructor(envService, sanitizer) {
279
+ this.envService = envService;
280
+ this.sanitizer = sanitizer;
281
+ }
282
+ ngOnChanges(changes) {
283
+ if (this.isVisible &&
284
+ (changes['isVisible'] ||
285
+ changes['file'] ||
286
+ changes['files'] ||
287
+ changes['initialIndex'] ||
288
+ changes['fileUrl'] ||
289
+ changes['fileName'])) {
290
+ if (this.files && this.files.length > 0) {
291
+ this.activeIndex = Math.min(Math.max(0, this.initialIndex || 0), this.files.length - 1);
292
+ }
293
+ else {
294
+ this.activeIndex = 0;
295
+ }
296
+ this.loadPreview();
297
+ }
298
+ else if (changes['isVisible'] && !this.isVisible) {
299
+ this.revokeObjectUrl();
300
+ }
301
+ }
302
+ isRealFile(candidate) {
303
+ return typeof Blob !== 'undefined' && candidate instanceof Blob;
304
+ }
305
+ get currentEntry() {
306
+ if (this.files && this.files.length > 0) {
307
+ return this.files[this.activeIndex] || null;
308
+ }
309
+ return this.file;
310
+ }
311
+ get currentFile() {
312
+ const entry = this.currentEntry;
313
+ return this.isRealFile(entry) ? entry : null;
314
+ }
315
+ get currentSavedPath() {
316
+ const entry = this.currentEntry;
317
+ if (this.isRealFile(entry)) {
318
+ return null;
319
+ }
320
+ return entry?.name || this.fileUrl || null;
321
+ }
322
+ get hasMultipleFiles() {
323
+ return (this.files?.length || 0) > 1;
324
+ }
325
+ selectFile(index) {
326
+ if (!this.files ||
327
+ index < 0 ||
328
+ index >= this.files.length ||
329
+ index === this.activeIndex) {
330
+ return;
331
+ }
332
+ this.activeIndex = index;
333
+ this.loadPreview();
334
+ }
335
+ prevFile() {
336
+ if (this.activeIndex > 0) {
337
+ this.selectFile(this.activeIndex - 1);
338
+ }
339
+ }
340
+ nextFile() {
341
+ if (this.files && this.activeIndex < this.files.length - 1) {
342
+ this.selectFile(this.activeIndex + 1);
343
+ }
344
+ }
345
+ ngOnDestroy() {
346
+ this.revokeObjectUrl();
347
+ }
348
+ get activeSheet() {
349
+ return this.sheets[this.activeSheetIndex] || null;
350
+ }
351
+ get isSavedFile() {
352
+ return !this.currentFile && !!this.currentSavedPath;
353
+ }
354
+ get canOpenExternal() {
355
+ return !!this.currentFile || !!this.currentSavedPath;
356
+ }
357
+ close() {
358
+ this.revokeObjectUrl();
359
+ this.closed.emit();
360
+ }
361
+ confirm() {
362
+ this.revokeObjectUrl();
363
+ this.confirmed.emit();
364
+ }
365
+ onModalClose() {
366
+ this.close();
367
+ }
368
+ openInNewTab() {
369
+ if (!this.hasMultipleFiles && this.openExternal.observed) {
370
+ this.openExternal.emit();
371
+ return;
372
+ }
373
+ const url = this.resolveTargetUrl();
374
+ if (url) {
375
+ window.open(url, '_blank');
376
+ }
377
+ }
378
+ zoomIn() {
379
+ this.imageZoom = Math.min(200, this.imageZoom + 25);
380
+ }
381
+ zoomOut() {
382
+ this.imageZoom = Math.max(50, this.imageZoom - 25);
383
+ }
384
+ resetZoom() {
385
+ this.imageZoom = 100;
386
+ }
387
+ selectSheet(index) {
388
+ this.activeSheetIndex = index;
389
+ }
390
+ async loadPreview() {
391
+ this.revokeObjectUrl();
392
+ this.isLoading = true;
393
+ this.errorMessage = null;
394
+ this.imageSrc = null;
395
+ this.safePdfUrl = null;
396
+ this.textContent = '';
397
+ this.sheets = [];
398
+ this.activeSheetIndex = 0;
399
+ this.imageZoom = 100;
400
+ const activeFile = this.currentFile;
401
+ const savedPath = this.currentSavedPath;
402
+ this.resolvedName =
403
+ activeFile?.name ||
404
+ (!this.hasMultipleFiles ? this.fileName : null) ||
405
+ savedPath?.split('/').pop()?.split('?')[0]?.split('#')[0] ||
406
+ 'File';
407
+ this.fileSizeLabel = activeFile ? this.formatBytes(activeFile.size) : '';
408
+ const ext = this.getExtension(this.resolvedName);
409
+ this.extensionLabel = ext ? ext.toUpperCase() : 'FILE';
410
+ this.previewKind = this.detectKind(ext, activeFile?.type);
411
+ try {
412
+ if (this.previewKind === 'image') {
413
+ if (activeFile) {
414
+ this.imageSrc = this.resolveTargetUrl();
415
+ }
416
+ else {
417
+ const url = this.resolveTargetUrl();
418
+ if (!url)
419
+ throw new Error('Image source is unavailable.');
420
+ try {
421
+ const response = await fetch(url);
422
+ if (!response.ok) {
423
+ throw new Error(`Failed to fetch file (${response.status})`);
424
+ }
425
+ const blob = await response.blob();
426
+ this.objectUrl = URL.createObjectURL(blob);
427
+ this.imageSrc = this.objectUrl;
428
+ }
429
+ catch {
430
+ // Fallback to direct URL if fetch is blocked by CORS
431
+ this.imageSrc = url;
432
+ }
433
+ }
434
+ }
435
+ else if (this.previewKind === 'pdf') {
436
+ if (activeFile) {
437
+ const src = this.resolveTargetUrl();
438
+ if (!src)
439
+ throw new Error('PDF source is unavailable.');
440
+ this.safePdfUrl = this.sanitizer.bypassSecurityTrustResourceUrl(src);
441
+ }
442
+ else {
443
+ const url = this.resolveTargetUrl();
444
+ if (!url)
445
+ throw new Error('PDF source is unavailable.');
446
+ try {
447
+ const response = await fetch(url);
448
+ if (!response.ok) {
449
+ throw new Error(`Failed to fetch file (${response.status})`);
450
+ }
451
+ const blob = await response.blob();
452
+ this.objectUrl = URL.createObjectURL(blob);
453
+ this.safePdfUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.objectUrl);
454
+ }
455
+ catch {
456
+ this.safePdfUrl = this.sanitizer.bypassSecurityTrustResourceUrl(url);
457
+ }
458
+ }
459
+ }
460
+ else if (this.previewKind === 'excel') {
461
+ if (ext === 'xls') {
462
+ this.previewKind = 'unsupported';
463
+ this.errorMessage =
464
+ 'Legacy binary .xls files cannot be parsed inline. Use "Open in New Tab" to view or download.';
465
+ }
466
+ else {
467
+ const buffer = await this.readAsArrayBuffer();
468
+ if (ext === 'csv' || ext === 'tsv') {
469
+ const text = new TextDecoder('utf-8').decode(buffer);
470
+ this.sheets = parseDelimitedText(text, ext === 'tsv' ? '\t' : ',', this.resolvedName);
471
+ }
472
+ else {
473
+ this.sheets = await parseXlsxBuffer(buffer);
474
+ }
475
+ if (this.sheets.length === 0) {
476
+ this.errorMessage = 'No worksheet data found in this file.';
477
+ }
478
+ }
479
+ }
480
+ else if (this.previewKind === 'text') {
481
+ const buffer = await this.readAsArrayBuffer();
482
+ const rawText = new TextDecoder('utf-8').decode(buffer);
483
+ if (ext === 'json') {
484
+ try {
485
+ this.textContent = JSON.stringify(JSON.parse(rawText), null, 2);
486
+ }
487
+ catch {
488
+ this.textContent = rawText;
489
+ }
490
+ }
491
+ else {
492
+ this.textContent = rawText;
493
+ }
494
+ }
495
+ }
496
+ catch (err) {
497
+ this.errorMessage =
498
+ err?.message ||
499
+ 'Unable to render inline preview for this file. You can still open it in a new tab.';
500
+ }
501
+ finally {
502
+ this.isLoading = false;
503
+ }
504
+ }
505
+ async readAsArrayBuffer() {
506
+ const activeFile = this.currentFile;
507
+ if (activeFile) {
508
+ return activeFile.arrayBuffer();
509
+ }
510
+ const url = this.resolveTargetUrl();
511
+ if (!url) {
512
+ throw new Error('File URL is unavailable.');
513
+ }
514
+ const response = await fetch(url);
515
+ if (!response.ok) {
516
+ throw new Error(`Failed to fetch file (${response.status})`);
517
+ }
518
+ return response.arrayBuffer();
519
+ }
520
+ resolveTargetUrl() {
521
+ const activeFile = this.currentFile;
522
+ if (activeFile) {
523
+ if (!this.objectUrl) {
524
+ this.objectUrl = URL.createObjectURL(activeFile);
525
+ }
526
+ return this.objectUrl;
527
+ }
528
+ const savedPath = this.currentSavedPath;
529
+ if (!savedPath)
530
+ return null;
531
+ if (/^(https?:|blob:|data:)/i.test(savedPath)) {
532
+ return savedPath;
533
+ }
534
+ return `${this.envService.environment.FILE_URL || ''}${savedPath}`;
535
+ }
536
+ revokeObjectUrl() {
537
+ if (this.objectUrl) {
538
+ URL.revokeObjectURL(this.objectUrl);
539
+ this.objectUrl = null;
540
+ }
541
+ }
542
+ getExtension(name) {
543
+ const clean = name.split('?')[0].split('#')[0];
544
+ const dot = clean.lastIndexOf('.');
545
+ return dot > -1 ? clean.slice(dot + 1).toLowerCase() : '';
546
+ }
547
+ detectKind(ext, mimeType) {
548
+ if (mimeType?.startsWith('image/') ||
549
+ ['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg', 'bmp', 'avif'].includes(ext)) {
550
+ return 'image';
551
+ }
552
+ if (['xlsx', 'xls', 'csv', 'tsv'].includes(ext) ||
553
+ mimeType ===
554
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
555
+ mimeType === 'text/csv') {
556
+ return 'excel';
557
+ }
558
+ if (ext === 'pdf' || mimeType === 'application/pdf') {
559
+ return 'pdf';
560
+ }
561
+ if (mimeType?.startsWith('text/') ||
562
+ ['txt', 'json', 'xml', 'md', 'log', 'yml', 'yaml'].includes(ext)) {
563
+ return 'text';
564
+ }
565
+ return 'unsupported';
566
+ }
567
+ formatBytes(bytes) {
568
+ if (bytes < 1024)
569
+ return `${bytes} B`;
570
+ if (bytes < 1024 * 1024)
571
+ return `${(bytes / 1024).toFixed(1)} KB`;
572
+ return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
573
+ }
574
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: FilePreviewComponent, deps: [{ token: i1.EnvironmentService }, { token: i2.DomSanitizer }], target: i0.ɵɵFactoryTarget.Component });
575
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.14", type: FilePreviewComponent, selector: "verben-file-preview", inputs: { isVisible: "isVisible", file: "file", files: "files", initialIndex: "initialIndex", fileUrl: "fileUrl", fileName: "fileName", confirmMode: "confirmMode", confirmText: "confirmText" }, outputs: { closed: "closed", confirmed: "confirmed", openExternal: "openExternal" }, usesOnChanges: true, ngImport: i0, template: "<verben-dialogue\n [showCloseIcon]=\"false\"\n [dismissOutsideClick]=\"true\"\n [closeOnEscape]=\"true\"\n [size]=\"'large'\"\n [mode]=\"'dialogue'\"\n [padding]=\"'16px 20px'\"\n [customClass]=\"'file-preview-dialogue'\"\n [disableFooter]=\"true\"\n [isVisible]=\"isVisible\"\n [bodyTemplate]=\"previewBodyTemplate\"\n (closeModal)=\"onModalClose()\"\n>\n <ng-template #previewBodyTemplate>\n <div class=\"preview-shell flex flex-col gap-3\">\n <!-- Header -->\n <div\n class=\"preview-header flex flex-wrap items-center justify-between gap-2 pb-2 border-b border-[#9A9FBF44]\"\n >\n <div class=\"flex items-center gap-2 min-w-0 flex-1\">\n <span class=\"preview-badge\">{{ extensionLabel }}</span>\n <div class=\"min-w-0\">\n <div\n class=\"text-sm font-semibold text-gray-800 truncate\"\n [title]=\"resolvedName\"\n >\n {{ resolvedName }}\n </div>\n <div class=\"text-xs text-gray-500 flex items-center gap-2\">\n <span *ngIf=\"fileSizeLabel\">{{ fileSizeLabel }}</span>\n <span *ngIf=\"isSavedFile\">Saved file</span>\n <span *ngIf=\"currentFile\" class=\"text-amber-600 font-medium\">\n Unsaved preview\n </span>\n </div>\n </div>\n </div>\n\n <div class=\"flex items-center gap-2 flex-shrink-0\">\n <!-- Image Zoom Controls -->\n <div\n *ngIf=\"previewKind === 'image' && imageSrc && !isLoading\"\n class=\"flex items-center gap-1 bg-gray-100 rounded-lg px-1.5 py-1 text-xs\"\n >\n <button\n type=\"button\"\n class=\"preview-icon-btn\"\n (click)=\"zoomOut()\"\n [disabled]=\"imageZoom <= 50\"\n title=\"Zoom out\"\n >\n \u2212\n </button>\n <button\n type=\"button\"\n class=\"px-1.5 font-medium text-gray-700 hover:text-primary cursor-pointer\"\n (click)=\"resetZoom()\"\n title=\"Reset zoom\"\n >\n {{ imageZoom }}%\n </button>\n <button\n type=\"button\"\n class=\"preview-icon-btn\"\n (click)=\"zoomIn()\"\n [disabled]=\"imageZoom >= 200\"\n title=\"Zoom in\"\n >\n +\n </button>\n </div>\n\n <!-- Open in new tab (Chrome preview) -->\n <button\n *ngIf=\"canOpenExternal\"\n type=\"button\"\n class=\"preview-action-btn\"\n (click)=\"openInNewTab()\"\n title=\"Open in new tab\"\n >\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n >\n <path\n d=\"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6\"\n ></path>\n <polyline points=\"15 3 21 3 21 9\"></polyline>\n <line x1=\"10\" y1=\"14\" x2=\"21\" y2=\"3\"></line>\n </svg>\n <span class=\"hidden sm:inline\">Open in tab</span>\n </button>\n </div>\n </div>\n\n <!-- Multi-file switcher (when multiple files are uploaded) -->\n <div\n *ngIf=\"hasMultipleFiles\"\n class=\"flex items-center justify-between gap-2 px-1 py-1 bg-gray-50 rounded-lg border border-gray-200\"\n >\n <div class=\"flex items-center gap-1.5 overflow-x-auto py-0.5 flex-1 min-w-0\">\n <button\n *ngFor=\"let f of files; let idx = index\"\n type=\"button\"\n (click)=\"selectFile(idx)\"\n class=\"sheet-tab whitespace-nowrap max-w-[160px] truncate\"\n [class.sheet-tab-active]=\"idx === activeIndex\"\n [title]=\"f.name\"\n >\n {{ f.name }}\n </button>\n </div>\n <div class=\"flex items-center gap-1 flex-shrink-0 text-xs text-gray-600\">\n <button\n type=\"button\"\n class=\"preview-icon-btn\"\n (click)=\"prevFile()\"\n [disabled]=\"activeIndex <= 0\"\n title=\"Previous file\"\n >\n \u2039\n </button>\n <span class=\"px-1 font-medium tabular-nums\">\n {{ activeIndex + 1 }} / {{ files.length }}\n </span>\n <button\n type=\"button\"\n class=\"preview-icon-btn\"\n (click)=\"nextFile()\"\n [disabled]=\"activeIndex >= files.length - 1\"\n title=\"Next file\"\n >\n \u203A\n </button>\n </div>\n </div>\n\n <!-- Body (scrollable for smaller screens) -->\n <div class=\"preview-scroll-body\">\n <!-- Loading -->\n <div\n *ngIf=\"isLoading\"\n class=\"flex flex-col items-center justify-center py-12 gap-2 text-sm text-gray-500\"\n >\n <div class=\"preview-spinner\"></div>\n <span>Loading preview...</span>\n </div>\n\n <!-- Error / Fallback -->\n <div\n *ngIf=\"!isLoading && errorMessage\"\n class=\"flex flex-col items-center justify-center py-10 px-4 text-center gap-3\"\n >\n <p class=\"text-sm text-gray-600 max-w-md\">{{ errorMessage }}</p>\n <verbena-button\n *ngIf=\"canOpenExternal\"\n text=\"Open in New Tab\"\n class=\"verben-primary-button\"\n (click)=\"openInNewTab()\"\n ></verbena-button>\n </div>\n\n <!-- Image Preview -->\n <div\n *ngIf=\"!isLoading && !errorMessage && previewKind === 'image' && imageSrc\"\n class=\"preview-image-stage\"\n >\n <img\n [src]=\"imageSrc\"\n [alt]=\"resolvedName\"\n [style.transform]=\"'scale(' + imageZoom / 100 + ')'\"\n class=\"preview-image\"\n />\n </div>\n\n <!-- Excel / CSV Preview -->\n <div\n *ngIf=\"!isLoading && !errorMessage && previewKind === 'excel' && activeSheet\"\n class=\"flex flex-col gap-2\"\n >\n <div class=\"flex flex-wrap items-center justify-between gap-2\">\n <div class=\"flex flex-wrap gap-1.5\" *ngIf=\"sheets.length > 1\">\n <button\n *ngFor=\"let sheet of sheets; let idx = index\"\n type=\"button\"\n (click)=\"selectSheet(idx)\"\n class=\"sheet-tab\"\n [class.sheet-tab-active]=\"idx === activeSheetIndex\"\n >\n {{ sheet.name }}\n </button>\n </div>\n <span class=\"text-xs text-gray-500 ml-auto\">\n {{ activeSheet.rows.length }} rows \u00D7\n {{ activeSheet.rows.length ? activeSheet.rows[0].length : 0 }} cols\n </span>\n </div>\n\n <div class=\"excel-table-wrap\">\n <table class=\"excel-table\">\n <thead *ngIf=\"activeSheet.rows.length > 0\">\n <tr>\n <th class=\"excel-row-num\">#</th>\n <th *ngFor=\"let header of activeSheet.rows[0]\">\n {{ header }}\n </th>\n </tr>\n </thead>\n <tbody>\n <tr\n *ngFor=\"\n let row of activeSheet.rows | slice: 1;\n let rIdx = index\n \"\n >\n <td class=\"excel-row-num\">{{ rIdx + 2 }}</td>\n <td *ngFor=\"let cell of row\" [title]=\"cell\">{{ cell }}</td>\n </tr>\n </tbody>\n </table>\n </div>\n </div>\n\n <!-- PDF Preview -->\n <div\n *ngIf=\"!isLoading && !errorMessage && previewKind === 'pdf' && safePdfUrl\"\n class=\"w-full\"\n >\n <iframe\n [src]=\"safePdfUrl\"\n class=\"w-full rounded-lg border border-gray-200\"\n style=\"height: 62vh\"\n title=\"PDF Preview\"\n ></iframe>\n </div>\n\n <!-- Text / JSON Preview -->\n <pre\n *ngIf=\"!isLoading && !errorMessage && previewKind === 'text'\"\n class=\"preview-text-pre\"\n >{{ textContent }}</pre\n >\n\n <!-- Unsupported Format -->\n <div\n *ngIf=\"!isLoading && !errorMessage && previewKind === 'unsupported'\"\n class=\"flex flex-col items-center justify-center py-10 px-4 text-center gap-3\"\n >\n <p class=\"text-sm text-gray-600\">\n Inline preview is not available for\n <strong>.{{ extensionLabel.toLowerCase() }}</strong> files.\n </p>\n <verbena-button\n *ngIf=\"canOpenExternal\"\n text=\"Open in New Tab\"\n class=\"verben-primary-button\"\n (click)=\"openInNewTab()\"\n ></verbena-button>\n </div>\n </div>\n\n <!-- Footer -->\n <div class=\"flex justify-end gap-2 pt-1\" *ngIf=\"!confirmMode; else confirmFooter\">\n <verbena-button\n width=\"100%\"\n class=\"verben-primary-button\"\n [text]=\"'Close'\"\n (click)=\"close()\"\n ></verbena-button>\n </div>\n <ng-template #confirmFooter>\n <div class=\"flex justify-end gap-2 pt-1\">\n <verbena-button\n [text]=\"'Cancel'\"\n bgColor=\"#f1f5f9\"\n textColor=\"#334155\"\n borderRadius=\"8px\"\n (click)=\"close()\"\n ></verbena-button>\n <verbena-button\n class=\"verben-primary-button\"\n [text]=\"confirmText\"\n (click)=\"confirm()\"\n ></verbena-button>\n </div>\n </ng-template>\n </div>\n </ng-template>\n</verben-dialogue>\n", styles: [".preview-shell{width:100%;max-width:min(880px,90vw)}.preview-badge{display:inline-flex;align-items:center;padding:3px 8px;border-radius:6px;font-size:11px;font-weight:700;background:#1a237e1a;color:var(--vbn-color-primary, #1a237e);flex-shrink:0}.preview-icon-btn{width:24px;height:24px;display:inline-flex;align-items:center;justify-content:center;border-radius:6px;font-weight:600;color:#334155;cursor:pointer}.preview-icon-btn:hover:not(:disabled){background:#e2e8f0}.preview-icon-btn:disabled{opacity:.4;cursor:not-allowed}.preview-action-btn{display:inline-flex;align-items:center;gap:6px;padding:6px 10px;border-radius:8px;border:1px solid #cbd5e1;background:#fff;color:#334155;font-size:12px;font-weight:500;cursor:pointer}.preview-action-btn:hover{border-color:var(--vbn-color-primary, #1a237e);color:var(--vbn-color-primary, #1a237e)}.preview-scroll-body{max-height:66vh;overflow:auto;border-radius:10px;background:#f8fafc;border:1px solid #e2e8f0;padding:12px}.preview-image-stage{display:flex;align-items:center;justify-content:center;min-height:220px;overflow:auto;background:repeating-conic-gradient(#eef2f6 0% 25%,#fff 0% 50%) 50% / 16px 16px;border-radius:8px;padding:12px}.preview-image{max-width:100%;max-height:58vh;object-fit:contain;transition:transform .15s ease}.sheet-tab{padding:4px 10px;font-size:12px;font-weight:500;border-radius:6px;border:1px solid #cbd5e1;background:#fff;color:#475569;cursor:pointer}.sheet-tab-active{background:var(--vbn-color-primary, #1a237e);border-color:var(--vbn-color-primary, #1a237e);color:#fff}.excel-table-wrap{max-height:54vh;overflow:auto;border:1px solid #cbd5e1;border-radius:8px;background:#fff}.excel-table{width:100%;border-collapse:collapse;font-size:12px}.excel-table th,.excel-table td{border:1px solid #e2e8f0;padding:6px 10px;text-align:left;white-space:nowrap;max-width:240px;overflow:hidden;text-overflow:ellipsis}.excel-table thead th{position:sticky;top:0;z-index:1;background:#f1f5f9;font-weight:600}.excel-table tbody tr:nth-child(2n){background:#f8fafc}.excel-row-num{width:40px;text-align:center!important;color:#64748b;background:#f1f5f9}.preview-text-pre{margin:0;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap;word-break:break-word;max-height:58vh;overflow:auto}.preview-spinner{width:28px;height:28px;border:3px solid #e2e8f0;border-top-color:var(--vbn-color-primary, #1a237e);border-radius:50%;animation:preview-spin .8s linear infinite}@keyframes preview-spin{to{transform:rotate(360deg)}}\n"], dependencies: [{ kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i4.VerbenaButtonComponent, selector: "verbena-button", inputs: ["type", "text", "styleType", "size", "block", "disable", "disabled", "isLoading", "spinnerSize", "spinnerColor", "svg", "svgPosition", "svgWidth", "svgHeight", "svgSize", "svgColor", "icon", "useIcon", "iconPosition", "iconColor", "variant", "weight", "bgColor", "textColor", "border", "borderRadius", "pd", "width", "height", "fontSize", "fontWeight", "buttonClass", "buttonTextClass"] }, { kind: "component", type: i4.VerbenDialogueComponent, selector: "verben-dialogue", inputs: ["dialogueWidth", "headerTemplate", "bodyTemplate", "footerTemplate", "showCloseIcon", "dismissOutsideClick", "closeOnEscape", "isVisible", "size", "backdropColor", "customClass", "disableFooter", "margin", "padding", "borderRadius", "dialogueBgColor", "width", "closeIconClass", "boxShadow", "enableTransition", "modalData", "mode", "position", "drawerWidth"], outputs: ["openModal", "closeModal"] }, { kind: "pipe", type: i3.SlicePipe, name: "slice" }] });
576
+ }
577
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: FilePreviewComponent, decorators: [{
578
+ type: Component,
579
+ args: [{ selector: 'verben-file-preview', template: "<verben-dialogue\n [showCloseIcon]=\"false\"\n [dismissOutsideClick]=\"true\"\n [closeOnEscape]=\"true\"\n [size]=\"'large'\"\n [mode]=\"'dialogue'\"\n [padding]=\"'16px 20px'\"\n [customClass]=\"'file-preview-dialogue'\"\n [disableFooter]=\"true\"\n [isVisible]=\"isVisible\"\n [bodyTemplate]=\"previewBodyTemplate\"\n (closeModal)=\"onModalClose()\"\n>\n <ng-template #previewBodyTemplate>\n <div class=\"preview-shell flex flex-col gap-3\">\n <!-- Header -->\n <div\n class=\"preview-header flex flex-wrap items-center justify-between gap-2 pb-2 border-b border-[#9A9FBF44]\"\n >\n <div class=\"flex items-center gap-2 min-w-0 flex-1\">\n <span class=\"preview-badge\">{{ extensionLabel }}</span>\n <div class=\"min-w-0\">\n <div\n class=\"text-sm font-semibold text-gray-800 truncate\"\n [title]=\"resolvedName\"\n >\n {{ resolvedName }}\n </div>\n <div class=\"text-xs text-gray-500 flex items-center gap-2\">\n <span *ngIf=\"fileSizeLabel\">{{ fileSizeLabel }}</span>\n <span *ngIf=\"isSavedFile\">Saved file</span>\n <span *ngIf=\"currentFile\" class=\"text-amber-600 font-medium\">\n Unsaved preview\n </span>\n </div>\n </div>\n </div>\n\n <div class=\"flex items-center gap-2 flex-shrink-0\">\n <!-- Image Zoom Controls -->\n <div\n *ngIf=\"previewKind === 'image' && imageSrc && !isLoading\"\n class=\"flex items-center gap-1 bg-gray-100 rounded-lg px-1.5 py-1 text-xs\"\n >\n <button\n type=\"button\"\n class=\"preview-icon-btn\"\n (click)=\"zoomOut()\"\n [disabled]=\"imageZoom <= 50\"\n title=\"Zoom out\"\n >\n \u2212\n </button>\n <button\n type=\"button\"\n class=\"px-1.5 font-medium text-gray-700 hover:text-primary cursor-pointer\"\n (click)=\"resetZoom()\"\n title=\"Reset zoom\"\n >\n {{ imageZoom }}%\n </button>\n <button\n type=\"button\"\n class=\"preview-icon-btn\"\n (click)=\"zoomIn()\"\n [disabled]=\"imageZoom >= 200\"\n title=\"Zoom in\"\n >\n +\n </button>\n </div>\n\n <!-- Open in new tab (Chrome preview) -->\n <button\n *ngIf=\"canOpenExternal\"\n type=\"button\"\n class=\"preview-action-btn\"\n (click)=\"openInNewTab()\"\n title=\"Open in new tab\"\n >\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n >\n <path\n d=\"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6\"\n ></path>\n <polyline points=\"15 3 21 3 21 9\"></polyline>\n <line x1=\"10\" y1=\"14\" x2=\"21\" y2=\"3\"></line>\n </svg>\n <span class=\"hidden sm:inline\">Open in tab</span>\n </button>\n </div>\n </div>\n\n <!-- Multi-file switcher (when multiple files are uploaded) -->\n <div\n *ngIf=\"hasMultipleFiles\"\n class=\"flex items-center justify-between gap-2 px-1 py-1 bg-gray-50 rounded-lg border border-gray-200\"\n >\n <div class=\"flex items-center gap-1.5 overflow-x-auto py-0.5 flex-1 min-w-0\">\n <button\n *ngFor=\"let f of files; let idx = index\"\n type=\"button\"\n (click)=\"selectFile(idx)\"\n class=\"sheet-tab whitespace-nowrap max-w-[160px] truncate\"\n [class.sheet-tab-active]=\"idx === activeIndex\"\n [title]=\"f.name\"\n >\n {{ f.name }}\n </button>\n </div>\n <div class=\"flex items-center gap-1 flex-shrink-0 text-xs text-gray-600\">\n <button\n type=\"button\"\n class=\"preview-icon-btn\"\n (click)=\"prevFile()\"\n [disabled]=\"activeIndex <= 0\"\n title=\"Previous file\"\n >\n \u2039\n </button>\n <span class=\"px-1 font-medium tabular-nums\">\n {{ activeIndex + 1 }} / {{ files.length }}\n </span>\n <button\n type=\"button\"\n class=\"preview-icon-btn\"\n (click)=\"nextFile()\"\n [disabled]=\"activeIndex >= files.length - 1\"\n title=\"Next file\"\n >\n \u203A\n </button>\n </div>\n </div>\n\n <!-- Body (scrollable for smaller screens) -->\n <div class=\"preview-scroll-body\">\n <!-- Loading -->\n <div\n *ngIf=\"isLoading\"\n class=\"flex flex-col items-center justify-center py-12 gap-2 text-sm text-gray-500\"\n >\n <div class=\"preview-spinner\"></div>\n <span>Loading preview...</span>\n </div>\n\n <!-- Error / Fallback -->\n <div\n *ngIf=\"!isLoading && errorMessage\"\n class=\"flex flex-col items-center justify-center py-10 px-4 text-center gap-3\"\n >\n <p class=\"text-sm text-gray-600 max-w-md\">{{ errorMessage }}</p>\n <verbena-button\n *ngIf=\"canOpenExternal\"\n text=\"Open in New Tab\"\n class=\"verben-primary-button\"\n (click)=\"openInNewTab()\"\n ></verbena-button>\n </div>\n\n <!-- Image Preview -->\n <div\n *ngIf=\"!isLoading && !errorMessage && previewKind === 'image' && imageSrc\"\n class=\"preview-image-stage\"\n >\n <img\n [src]=\"imageSrc\"\n [alt]=\"resolvedName\"\n [style.transform]=\"'scale(' + imageZoom / 100 + ')'\"\n class=\"preview-image\"\n />\n </div>\n\n <!-- Excel / CSV Preview -->\n <div\n *ngIf=\"!isLoading && !errorMessage && previewKind === 'excel' && activeSheet\"\n class=\"flex flex-col gap-2\"\n >\n <div class=\"flex flex-wrap items-center justify-between gap-2\">\n <div class=\"flex flex-wrap gap-1.5\" *ngIf=\"sheets.length > 1\">\n <button\n *ngFor=\"let sheet of sheets; let idx = index\"\n type=\"button\"\n (click)=\"selectSheet(idx)\"\n class=\"sheet-tab\"\n [class.sheet-tab-active]=\"idx === activeSheetIndex\"\n >\n {{ sheet.name }}\n </button>\n </div>\n <span class=\"text-xs text-gray-500 ml-auto\">\n {{ activeSheet.rows.length }} rows \u00D7\n {{ activeSheet.rows.length ? activeSheet.rows[0].length : 0 }} cols\n </span>\n </div>\n\n <div class=\"excel-table-wrap\">\n <table class=\"excel-table\">\n <thead *ngIf=\"activeSheet.rows.length > 0\">\n <tr>\n <th class=\"excel-row-num\">#</th>\n <th *ngFor=\"let header of activeSheet.rows[0]\">\n {{ header }}\n </th>\n </tr>\n </thead>\n <tbody>\n <tr\n *ngFor=\"\n let row of activeSheet.rows | slice: 1;\n let rIdx = index\n \"\n >\n <td class=\"excel-row-num\">{{ rIdx + 2 }}</td>\n <td *ngFor=\"let cell of row\" [title]=\"cell\">{{ cell }}</td>\n </tr>\n </tbody>\n </table>\n </div>\n </div>\n\n <!-- PDF Preview -->\n <div\n *ngIf=\"!isLoading && !errorMessage && previewKind === 'pdf' && safePdfUrl\"\n class=\"w-full\"\n >\n <iframe\n [src]=\"safePdfUrl\"\n class=\"w-full rounded-lg border border-gray-200\"\n style=\"height: 62vh\"\n title=\"PDF Preview\"\n ></iframe>\n </div>\n\n <!-- Text / JSON Preview -->\n <pre\n *ngIf=\"!isLoading && !errorMessage && previewKind === 'text'\"\n class=\"preview-text-pre\"\n >{{ textContent }}</pre\n >\n\n <!-- Unsupported Format -->\n <div\n *ngIf=\"!isLoading && !errorMessage && previewKind === 'unsupported'\"\n class=\"flex flex-col items-center justify-center py-10 px-4 text-center gap-3\"\n >\n <p class=\"text-sm text-gray-600\">\n Inline preview is not available for\n <strong>.{{ extensionLabel.toLowerCase() }}</strong> files.\n </p>\n <verbena-button\n *ngIf=\"canOpenExternal\"\n text=\"Open in New Tab\"\n class=\"verben-primary-button\"\n (click)=\"openInNewTab()\"\n ></verbena-button>\n </div>\n </div>\n\n <!-- Footer -->\n <div class=\"flex justify-end gap-2 pt-1\" *ngIf=\"!confirmMode; else confirmFooter\">\n <verbena-button\n width=\"100%\"\n class=\"verben-primary-button\"\n [text]=\"'Close'\"\n (click)=\"close()\"\n ></verbena-button>\n </div>\n <ng-template #confirmFooter>\n <div class=\"flex justify-end gap-2 pt-1\">\n <verbena-button\n [text]=\"'Cancel'\"\n bgColor=\"#f1f5f9\"\n textColor=\"#334155\"\n borderRadius=\"8px\"\n (click)=\"close()\"\n ></verbena-button>\n <verbena-button\n class=\"verben-primary-button\"\n [text]=\"confirmText\"\n (click)=\"confirm()\"\n ></verbena-button>\n </div>\n </ng-template>\n </div>\n </ng-template>\n</verben-dialogue>\n", styles: [".preview-shell{width:100%;max-width:min(880px,90vw)}.preview-badge{display:inline-flex;align-items:center;padding:3px 8px;border-radius:6px;font-size:11px;font-weight:700;background:#1a237e1a;color:var(--vbn-color-primary, #1a237e);flex-shrink:0}.preview-icon-btn{width:24px;height:24px;display:inline-flex;align-items:center;justify-content:center;border-radius:6px;font-weight:600;color:#334155;cursor:pointer}.preview-icon-btn:hover:not(:disabled){background:#e2e8f0}.preview-icon-btn:disabled{opacity:.4;cursor:not-allowed}.preview-action-btn{display:inline-flex;align-items:center;gap:6px;padding:6px 10px;border-radius:8px;border:1px solid #cbd5e1;background:#fff;color:#334155;font-size:12px;font-weight:500;cursor:pointer}.preview-action-btn:hover{border-color:var(--vbn-color-primary, #1a237e);color:var(--vbn-color-primary, #1a237e)}.preview-scroll-body{max-height:66vh;overflow:auto;border-radius:10px;background:#f8fafc;border:1px solid #e2e8f0;padding:12px}.preview-image-stage{display:flex;align-items:center;justify-content:center;min-height:220px;overflow:auto;background:repeating-conic-gradient(#eef2f6 0% 25%,#fff 0% 50%) 50% / 16px 16px;border-radius:8px;padding:12px}.preview-image{max-width:100%;max-height:58vh;object-fit:contain;transition:transform .15s ease}.sheet-tab{padding:4px 10px;font-size:12px;font-weight:500;border-radius:6px;border:1px solid #cbd5e1;background:#fff;color:#475569;cursor:pointer}.sheet-tab-active{background:var(--vbn-color-primary, #1a237e);border-color:var(--vbn-color-primary, #1a237e);color:#fff}.excel-table-wrap{max-height:54vh;overflow:auto;border:1px solid #cbd5e1;border-radius:8px;background:#fff}.excel-table{width:100%;border-collapse:collapse;font-size:12px}.excel-table th,.excel-table td{border:1px solid #e2e8f0;padding:6px 10px;text-align:left;white-space:nowrap;max-width:240px;overflow:hidden;text-overflow:ellipsis}.excel-table thead th{position:sticky;top:0;z-index:1;background:#f1f5f9;font-weight:600}.excel-table tbody tr:nth-child(2n){background:#f8fafc}.excel-row-num{width:40px;text-align:center!important;color:#64748b;background:#f1f5f9}.preview-text-pre{margin:0;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap;word-break:break-word;max-height:58vh;overflow:auto}.preview-spinner{width:28px;height:28px;border:3px solid #e2e8f0;border-top-color:var(--vbn-color-primary, #1a237e);border-radius:50%;animation:preview-spin .8s linear infinite}@keyframes preview-spin{to{transform:rotate(360deg)}}\n"] }]
580
+ }], ctorParameters: () => [{ type: i1.EnvironmentService }, { type: i2.DomSanitizer }], propDecorators: { isVisible: [{
581
+ type: Input
582
+ }], file: [{
583
+ type: Input
584
+ }], files: [{
585
+ type: Input
586
+ }], initialIndex: [{
587
+ type: Input
588
+ }], fileUrl: [{
589
+ type: Input
590
+ }], fileName: [{
591
+ type: Input
592
+ }], confirmMode: [{
593
+ type: Input
594
+ }], confirmText: [{
595
+ type: Input
596
+ }], closed: [{
597
+ type: Output
598
+ }], confirmed: [{
599
+ type: Output
600
+ }], openExternal: [{
601
+ type: Output
602
+ }] } });
603
+
10
604
  class FileRenderComponent {
11
605
  envService;
606
+ file = null;
607
+ files = [];
608
+ fileIndex = 0;
12
609
  fileUrl = null;
13
- multiple = false;
14
610
  fileName = null;
611
+ multiple = false;
15
612
  disabled = false;
16
613
  showCancel = false;
614
+ showPreview = true;
17
615
  onCancelClicked = new EventEmitter();
616
+ resolvedFileName = null;
617
+ isPreviewVisible = false;
618
+ tempObjectUrl = null;
18
619
  constructor(envService) {
19
620
  this.envService = envService;
20
621
  }
21
622
  ngOnInit() {
22
- if (this.fileUrl) {
23
- this.fileName = this.fileUrl.split('/').pop() || null;
623
+ this.syncFileName();
624
+ }
625
+ ngOnChanges(changes) {
626
+ if (changes['file'] || changes['fileUrl'] || changes['fileName']) {
627
+ this.syncFileName();
628
+ }
629
+ }
630
+ ngOnDestroy() {
631
+ if (this.tempObjectUrl) {
632
+ URL.revokeObjectURL(this.tempObjectUrl);
633
+ this.tempObjectUrl = null;
24
634
  }
25
635
  }
636
+ isRealFile(candidate) {
637
+ return typeof Blob !== 'undefined' && candidate instanceof Blob;
638
+ }
639
+ syncFileName() {
640
+ if (this.fileName) {
641
+ this.resolvedFileName = this.fileName;
642
+ }
643
+ else if (this.file?.name) {
644
+ this.resolvedFileName =
645
+ this.file.name.split('/').pop()?.split('?')[0]?.split('#')[0] ||
646
+ this.file.name;
647
+ }
648
+ else if (this.fileUrl) {
649
+ this.resolvedFileName =
650
+ this.fileUrl.split('/').pop()?.split('?')[0]?.split('#')[0] || null;
651
+ }
652
+ else {
653
+ this.resolvedFileName = null;
654
+ }
655
+ }
656
+ openPreview() {
657
+ if (!this.file && !this.fileUrl) {
658
+ return;
659
+ }
660
+ this.isPreviewVisible = true;
661
+ }
662
+ closePreview() {
663
+ this.isPreviewVisible = false;
664
+ }
26
665
  openFile() {
27
- if (!this.fileUrl) {
666
+ if (this.isRealFile(this.file)) {
667
+ if (this.tempObjectUrl) {
668
+ URL.revokeObjectURL(this.tempObjectUrl);
669
+ }
670
+ this.tempObjectUrl = URL.createObjectURL(this.file);
671
+ window.open(this.tempObjectUrl, '_blank');
672
+ return;
673
+ }
674
+ const rawUrl = this.file?.name || this.fileUrl;
675
+ if (!rawUrl) {
28
676
  return;
29
677
  }
30
- window.open(`${this.envService.environment.FILE_URL}${this.fileUrl}`, '_blank');
678
+ const targetUrl = /^(https?:|blob:|data:)/i.test(rawUrl)
679
+ ? rawUrl
680
+ : `${this.envService.environment.FILE_URL}${rawUrl}`;
681
+ window.open(targetUrl, '_blank');
31
682
  }
32
683
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: FileRenderComponent, deps: [{ token: i1.EnvironmentService }], target: i0.ɵɵFactoryTarget.Component });
33
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.14", type: FileRenderComponent, selector: "verben-file-render", inputs: { fileUrl: "fileUrl", multiple: "multiple", disabled: "disabled", showCancel: "showCancel" }, outputs: { onCancelClicked: "onCancelClicked" }, ngImport: i0, template: "<div class=\"file-container p-2 flex items-center justify-between gap-3\">\n <div class=\"text-sm overflow-x-auto font-semibold\">{{ fileName }}</div>\n <div class=\"flex gap-2 items-center\">\n <span (click)=\"openFile()\" class=\"cursor-pointer\">\n <verben-svg\n [icon]=\"'download-icon'\"\n [width]=\"15\"\n [height]=\"15\"\n ></verben-svg>\n </span>\n <verben-svg\n *ngIf=\"showCancel\"\n [stroke]=\"disabled ? 'var(--vbn-color-text-muted)' : multiple ? 'var(--vbn-color-primary)' : 'var(--vbn-color-border-focus)'\"\n [icon]=\"'close'\"\n [width]=\"15\"\n [height]=\"15\"\n (click)=\"onCancelClicked.emit()\"\n >\n </verben-svg>\n </div>\n</div>\n", styles: [".file-container{border:1px solid #ccc6fbb2;border-radius:5px}\n"], dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i3.SvgComponent, selector: "verben-svg", inputs: ["icon", "width", "height", "fill", "stroke", "type", "size"] }] });
684
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.14", type: FileRenderComponent, selector: "verben-file-render", inputs: { file: "file", files: "files", fileIndex: "fileIndex", fileUrl: "fileUrl", fileName: "fileName", multiple: "multiple", disabled: "disabled", showCancel: "showCancel", showPreview: "showPreview" }, outputs: { onCancelClicked: "onCancelClicked" }, usesOnChanges: true, ngImport: i0, template: "<div class=\"file-container p-2 flex items-center justify-between gap-3\">\n <button\n type=\"button\"\n (click)=\"showPreview ? openPreview() : openFile()\"\n class=\"text-sm overflow-x-auto font-semibold text-left hover:text-primary transition-colors cursor-pointer bg-transparent border-0 p-0\"\n [title]=\"showPreview ? 'Preview ' + (resolvedFileName || '') : (resolvedFileName || '')\"\n >\n {{ resolvedFileName }}\n </button>\n <div class=\"flex gap-2 items-center flex-shrink-0\">\n <button\n *ngIf=\"showPreview\"\n type=\"button\"\n (click)=\"openPreview()\"\n class=\"cursor-pointer text-gray-600 hover:text-primary transition-colors bg-transparent border-0 p-0 flex items-center\"\n title=\"Preview in app\"\n >\n <svg\n width=\"15\"\n height=\"15\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n >\n <path d=\"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z\"></path>\n <circle cx=\"12\" cy=\"12\" r=\"3\"></circle>\n </svg>\n </button>\n <span\n (click)=\"openFile()\"\n class=\"cursor-pointer flex items-center\"\n title=\"Open in new tab\"\n >\n <verben-svg\n [icon]=\"'download-icon'\"\n [width]=\"15\"\n [height]=\"15\"\n ></verben-svg>\n </span>\n <verben-svg\n *ngIf=\"showCancel\"\n [stroke]=\"disabled ? 'var(--vbn-color-text-muted)' : multiple ? 'var(--vbn-color-primary)' : 'var(--vbn-color-border-focus)'\"\n [icon]=\"'close'\"\n [width]=\"15\"\n [height]=\"15\"\n (click)=\"onCancelClicked.emit()\"\n >\n </verben-svg>\n </div>\n</div>\n\n<verben-file-preview\n [isVisible]=\"isPreviewVisible\"\n [file]=\"file\"\n [files]=\"files\"\n [initialIndex]=\"fileIndex\"\n [fileUrl]=\"fileUrl\"\n [fileName]=\"resolvedFileName\"\n (closed)=\"closePreview()\"\n (openExternal)=\"openFile()\"\n></verben-file-preview>\n", styles: [".file-container{border:1px solid #ccc6fbb2;border-radius:5px}\n"], dependencies: [{ kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i4.SvgComponent, selector: "verben-svg", inputs: ["icon", "width", "height", "fill", "stroke", "type", "size"] }, { kind: "component", type: FilePreviewComponent, selector: "verben-file-preview", inputs: ["isVisible", "file", "files", "initialIndex", "fileUrl", "fileName", "confirmMode", "confirmText"], outputs: ["closed", "confirmed", "openExternal"] }] });
34
685
  }
35
686
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: FileRenderComponent, decorators: [{
36
687
  type: Component,
37
- args: [{ selector: 'verben-file-render', template: "<div class=\"file-container p-2 flex items-center justify-between gap-3\">\n <div class=\"text-sm overflow-x-auto font-semibold\">{{ fileName }}</div>\n <div class=\"flex gap-2 items-center\">\n <span (click)=\"openFile()\" class=\"cursor-pointer\">\n <verben-svg\n [icon]=\"'download-icon'\"\n [width]=\"15\"\n [height]=\"15\"\n ></verben-svg>\n </span>\n <verben-svg\n *ngIf=\"showCancel\"\n [stroke]=\"disabled ? 'var(--vbn-color-text-muted)' : multiple ? 'var(--vbn-color-primary)' : 'var(--vbn-color-border-focus)'\"\n [icon]=\"'close'\"\n [width]=\"15\"\n [height]=\"15\"\n (click)=\"onCancelClicked.emit()\"\n >\n </verben-svg>\n </div>\n</div>\n", styles: [".file-container{border:1px solid #ccc6fbb2;border-radius:5px}\n"] }]
38
- }], ctorParameters: () => [{ type: i1.EnvironmentService }], propDecorators: { fileUrl: [{
688
+ args: [{ selector: 'verben-file-render', template: "<div class=\"file-container p-2 flex items-center justify-between gap-3\">\n <button\n type=\"button\"\n (click)=\"showPreview ? openPreview() : openFile()\"\n class=\"text-sm overflow-x-auto font-semibold text-left hover:text-primary transition-colors cursor-pointer bg-transparent border-0 p-0\"\n [title]=\"showPreview ? 'Preview ' + (resolvedFileName || '') : (resolvedFileName || '')\"\n >\n {{ resolvedFileName }}\n </button>\n <div class=\"flex gap-2 items-center flex-shrink-0\">\n <button\n *ngIf=\"showPreview\"\n type=\"button\"\n (click)=\"openPreview()\"\n class=\"cursor-pointer text-gray-600 hover:text-primary transition-colors bg-transparent border-0 p-0 flex items-center\"\n title=\"Preview in app\"\n >\n <svg\n width=\"15\"\n height=\"15\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"2\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n >\n <path d=\"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z\"></path>\n <circle cx=\"12\" cy=\"12\" r=\"3\"></circle>\n </svg>\n </button>\n <span\n (click)=\"openFile()\"\n class=\"cursor-pointer flex items-center\"\n title=\"Open in new tab\"\n >\n <verben-svg\n [icon]=\"'download-icon'\"\n [width]=\"15\"\n [height]=\"15\"\n ></verben-svg>\n </span>\n <verben-svg\n *ngIf=\"showCancel\"\n [stroke]=\"disabled ? 'var(--vbn-color-text-muted)' : multiple ? 'var(--vbn-color-primary)' : 'var(--vbn-color-border-focus)'\"\n [icon]=\"'close'\"\n [width]=\"15\"\n [height]=\"15\"\n (click)=\"onCancelClicked.emit()\"\n >\n </verben-svg>\n </div>\n</div>\n\n<verben-file-preview\n [isVisible]=\"isPreviewVisible\"\n [file]=\"file\"\n [files]=\"files\"\n [initialIndex]=\"fileIndex\"\n [fileUrl]=\"fileUrl\"\n [fileName]=\"resolvedFileName\"\n (closed)=\"closePreview()\"\n (openExternal)=\"openFile()\"\n></verben-file-preview>\n", styles: [".file-container{border:1px solid #ccc6fbb2;border-radius:5px}\n"] }]
689
+ }], ctorParameters: () => [{ type: i1.EnvironmentService }], propDecorators: { file: [{
690
+ type: Input
691
+ }], files: [{
692
+ type: Input
693
+ }], fileIndex: [{
694
+ type: Input
695
+ }], fileUrl: [{
696
+ type: Input
697
+ }], fileName: [{
39
698
  type: Input
40
699
  }], multiple: [{
41
700
  type: Input
@@ -43,35 +702,40 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImpo
43
702
  type: Input
44
703
  }], showCancel: [{
45
704
  type: Input
705
+ }], showPreview: [{
706
+ type: Input
46
707
  }], onCancelClicked: [{
47
708
  type: Output
48
709
  }] } });
49
710
 
50
711
  class FileRenderModule {
51
712
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: FileRenderModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
52
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.14", ngImport: i0, type: FileRenderModule, declarations: [FileRenderComponent], imports: [CommonModule,
713
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.14", ngImport: i0, type: FileRenderModule, declarations: [FileRenderComponent, FilePreviewComponent], imports: [CommonModule,
53
714
  FormsModule,
54
715
  ReactiveFormsModule,
55
716
  SvgModule,
56
- VerbenaButtonModule], exports: [FileRenderComponent] });
717
+ VerbenaButtonModule,
718
+ VerbenDialogueModule], exports: [FileRenderComponent, FilePreviewComponent] });
57
719
  static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: FileRenderModule, imports: [CommonModule,
58
720
  FormsModule,
59
721
  ReactiveFormsModule,
60
722
  SvgModule,
61
- VerbenaButtonModule] });
723
+ VerbenaButtonModule,
724
+ VerbenDialogueModule] });
62
725
  }
63
726
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: FileRenderModule, decorators: [{
64
727
  type: NgModule,
65
728
  args: [{
66
- declarations: [FileRenderComponent],
729
+ declarations: [FileRenderComponent, FilePreviewComponent],
67
730
  imports: [
68
731
  CommonModule,
69
732
  FormsModule,
70
733
  ReactiveFormsModule,
71
734
  SvgModule,
72
735
  VerbenaButtonModule,
736
+ VerbenDialogueModule,
73
737
  ],
74
- exports: [FileRenderComponent],
738
+ exports: [FileRenderComponent, FilePreviewComponent],
75
739
  }]
76
740
  }] });
77
741
 
@@ -79,5 +743,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImpo
79
743
  * Generated bundle index. Do not edit.
80
744
  */
81
745
 
82
- export { FileRenderComponent, FileRenderModule };
746
+ export { FilePreviewComponent, FileRenderComponent, FileRenderModule };
83
747
  //# sourceMappingURL=verben-workflow-ui-src-lib-components-file-render.mjs.map