@elyracode/web-ui 0.9.57 → 1.0.0

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 (95) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/components/SandboxedIframe.d.ts +15 -1
  3. package/dist/components/SandboxedIframe.d.ts.map +1 -1
  4. package/dist/components/SandboxedIframe.js +129 -67
  5. package/dist/components/SandboxedIframe.js.map +1 -1
  6. package/dist/components/sandbox/RuntimeMessageRouter.d.ts +12 -2
  7. package/dist/components/sandbox/RuntimeMessageRouter.d.ts.map +1 -1
  8. package/dist/components/sandbox/RuntimeMessageRouter.js +26 -2
  9. package/dist/components/sandbox/RuntimeMessageRouter.js.map +1 -1
  10. package/package.json +18 -8
  11. package/example/README.md +0 -61
  12. package/example/index.html +0 -13
  13. package/example/package.json +0 -25
  14. package/example/src/app.css +0 -1
  15. package/example/src/css-modules.d.ts +0 -3
  16. package/example/src/custom-messages.ts +0 -99
  17. package/example/src/main.ts +0 -421
  18. package/example/tsconfig.json +0 -23
  19. package/example/vite.config.ts +0 -6
  20. package/scripts/count-prompt-tokens.ts +0 -88
  21. package/src/ChatPanel.ts +0 -209
  22. package/src/app.css +0 -68
  23. package/src/components/AgentInterface.ts +0 -403
  24. package/src/components/AttachmentTile.ts +0 -107
  25. package/src/components/ConsoleBlock.ts +0 -72
  26. package/src/components/CustomProviderCard.ts +0 -100
  27. package/src/components/ExpandableSection.ts +0 -46
  28. package/src/components/Input.ts +0 -113
  29. package/src/components/MessageEditor.ts +0 -405
  30. package/src/components/MessageList.ts +0 -98
  31. package/src/components/Messages.ts +0 -383
  32. package/src/components/ProviderKeyInput.ts +0 -153
  33. package/src/components/SandboxedIframe.ts +0 -627
  34. package/src/components/StreamingMessageContainer.ts +0 -103
  35. package/src/components/ThinkingBlock.ts +0 -43
  36. package/src/components/message-renderer-registry.ts +0 -28
  37. package/src/components/sandbox/ArtifactsRuntimeProvider.ts +0 -226
  38. package/src/components/sandbox/AttachmentsRuntimeProvider.ts +0 -68
  39. package/src/components/sandbox/ConsoleRuntimeProvider.ts +0 -188
  40. package/src/components/sandbox/FileDownloadRuntimeProvider.ts +0 -114
  41. package/src/components/sandbox/RuntimeMessageBridge.ts +0 -82
  42. package/src/components/sandbox/RuntimeMessageRouter.ts +0 -215
  43. package/src/components/sandbox/SandboxRuntimeProvider.ts +0 -54
  44. package/src/components/sandbox/runtime-messages.ts +0 -146
  45. package/src/dialogs/ApiKeyPromptDialog.ts +0 -75
  46. package/src/dialogs/AttachmentOverlay.ts +0 -637
  47. package/src/dialogs/CustomProviderDialog.ts +0 -274
  48. package/src/dialogs/ModelSelector.ts +0 -370
  49. package/src/dialogs/PersistentStorageDialog.ts +0 -144
  50. package/src/dialogs/ProvidersModelsTab.ts +0 -212
  51. package/src/dialogs/SessionListDialog.ts +0 -150
  52. package/src/dialogs/SettingsDialog.ts +0 -218
  53. package/src/index.ts +0 -120
  54. package/src/prompts/prompts.ts +0 -282
  55. package/src/storage/app-storage.ts +0 -60
  56. package/src/storage/backends/indexeddb-storage-backend.ts +0 -193
  57. package/src/storage/store.ts +0 -33
  58. package/src/storage/stores/custom-providers-store.ts +0 -62
  59. package/src/storage/stores/provider-keys-store.ts +0 -33
  60. package/src/storage/stores/sessions-store.ts +0 -136
  61. package/src/storage/stores/settings-store.ts +0 -34
  62. package/src/storage/types.ts +0 -206
  63. package/src/tools/artifacts/ArtifactElement.ts +0 -14
  64. package/src/tools/artifacts/ArtifactPill.ts +0 -26
  65. package/src/tools/artifacts/Console.ts +0 -93
  66. package/src/tools/artifacts/DocxArtifact.ts +0 -213
  67. package/src/tools/artifacts/ExcelArtifact.ts +0 -231
  68. package/src/tools/artifacts/GenericArtifact.ts +0 -117
  69. package/src/tools/artifacts/HtmlArtifact.ts +0 -195
  70. package/src/tools/artifacts/ImageArtifact.ts +0 -116
  71. package/src/tools/artifacts/MarkdownArtifact.ts +0 -82
  72. package/src/tools/artifacts/PdfArtifact.ts +0 -202
  73. package/src/tools/artifacts/SvgArtifact.ts +0 -119
  74. package/src/tools/artifacts/TextArtifact.ts +0 -148
  75. package/src/tools/artifacts/artifacts-tool-renderer.ts +0 -310
  76. package/src/tools/artifacts/artifacts.ts +0 -713
  77. package/src/tools/artifacts/index.ts +0 -7
  78. package/src/tools/extract-document.ts +0 -275
  79. package/src/tools/index.ts +0 -46
  80. package/src/tools/javascript-repl.ts +0 -293
  81. package/src/tools/renderer-registry.ts +0 -130
  82. package/src/tools/renderers/BashRenderer.ts +0 -52
  83. package/src/tools/renderers/CalculateRenderer.ts +0 -58
  84. package/src/tools/renderers/DefaultRenderer.ts +0 -103
  85. package/src/tools/renderers/GetCurrentTimeRenderer.ts +0 -92
  86. package/src/tools/types.ts +0 -15
  87. package/src/utils/attachment-utils.ts +0 -479
  88. package/src/utils/auth-token.ts +0 -22
  89. package/src/utils/format.ts +0 -42
  90. package/src/utils/i18n.ts +0 -653
  91. package/src/utils/model-discovery.ts +0 -290
  92. package/src/utils/proxy-utils.ts +0 -139
  93. package/src/utils/test-sessions.ts +0 -2357
  94. package/tsconfig.build.json +0 -20
  95. package/tsconfig.json +0 -7
@@ -1,637 +0,0 @@
1
- import "@elyracode/mini-lit/dist/ModeToggle.js";
2
- import { icon } from "@elyracode/mini-lit";
3
- import { Button } from "@elyracode/mini-lit/dist/Button.js";
4
- import { renderAsync } from "docx-preview";
5
- import { html, LitElement } from "lit";
6
- import { state } from "lit/decorators.js";
7
- import { Download, X } from "lucide";
8
- import type { PDFDocumentLoadingTask, PDFDocumentProxy } from "pdfjs-dist";
9
- import * as pdfjsLib from "pdfjs-dist";
10
- import * as XLSX from "xlsx";
11
- import type { Attachment } from "../utils/attachment-utils.js";
12
- import { i18n } from "../utils/i18n.js";
13
-
14
- type FileType = "image" | "pdf" | "docx" | "pptx" | "excel" | "text";
15
-
16
- export class AttachmentOverlay extends LitElement {
17
- @state() private attachment?: Attachment;
18
- @state() private showExtractedText = false;
19
- @state() private error: string | null = null;
20
-
21
- // Track current loading task to cancel if needed
22
- private currentLoadingTask: PDFDocumentLoadingTask | null = null;
23
- private onCloseCallback?: () => void;
24
- private boundHandleKeyDown?: (e: KeyboardEvent) => void;
25
-
26
- protected override createRenderRoot(): HTMLElement | DocumentFragment {
27
- return this;
28
- }
29
-
30
- static open(attachment: Attachment, onClose?: () => void) {
31
- const overlay = new AttachmentOverlay();
32
- overlay.attachment = attachment;
33
- overlay.onCloseCallback = onClose;
34
- document.body.appendChild(overlay);
35
- overlay.setupEventListeners();
36
- }
37
-
38
- private setupEventListeners() {
39
- this.boundHandleKeyDown = (e: KeyboardEvent) => {
40
- if (e.key === "Escape") {
41
- this.close();
42
- }
43
- };
44
- window.addEventListener("keydown", this.boundHandleKeyDown);
45
- }
46
-
47
- private close() {
48
- this.cleanup();
49
- if (this.boundHandleKeyDown) {
50
- window.removeEventListener("keydown", this.boundHandleKeyDown);
51
- }
52
- this.onCloseCallback?.();
53
- this.remove();
54
- }
55
-
56
- private getFileType(): FileType {
57
- if (!this.attachment) return "text";
58
-
59
- if (this.attachment.type === "image") return "image";
60
- if (this.attachment.mimeType === "application/pdf") return "pdf";
61
- if (this.attachment.mimeType?.includes("wordprocessingml")) return "docx";
62
- if (
63
- this.attachment.mimeType?.includes("presentationml") ||
64
- this.attachment.fileName.toLowerCase().endsWith(".pptx")
65
- )
66
- return "pptx";
67
- if (
68
- this.attachment.mimeType?.includes("spreadsheetml") ||
69
- this.attachment.mimeType?.includes("ms-excel") ||
70
- this.attachment.fileName.toLowerCase().endsWith(".xlsx") ||
71
- this.attachment.fileName.toLowerCase().endsWith(".xls")
72
- )
73
- return "excel";
74
-
75
- return "text";
76
- }
77
-
78
- private getFileTypeLabel(): string {
79
- const type = this.getFileType();
80
- switch (type) {
81
- case "pdf":
82
- return i18n("PDF");
83
- case "docx":
84
- return i18n("Document");
85
- case "pptx":
86
- return i18n("Presentation");
87
- case "excel":
88
- return i18n("Spreadsheet");
89
- default:
90
- return "";
91
- }
92
- }
93
-
94
- private handleBackdropClick = () => {
95
- this.close();
96
- };
97
-
98
- private handleDownload = () => {
99
- if (!this.attachment) return;
100
-
101
- // Create a blob from the base64 content
102
- const byteCharacters = atob(this.attachment.content);
103
- const byteNumbers = new Array(byteCharacters.length);
104
- for (let i = 0; i < byteCharacters.length; i++) {
105
- byteNumbers[i] = byteCharacters.charCodeAt(i);
106
- }
107
- const byteArray = new Uint8Array(byteNumbers);
108
- const blob = new Blob([byteArray], { type: this.attachment.mimeType });
109
-
110
- // Create download link
111
- const url = URL.createObjectURL(blob);
112
- const a = document.createElement("a");
113
- a.href = url;
114
- a.download = this.attachment.fileName;
115
- document.body.appendChild(a);
116
- a.click();
117
- document.body.removeChild(a);
118
- URL.revokeObjectURL(url);
119
- };
120
-
121
- private cleanup() {
122
- this.showExtractedText = false;
123
- this.error = null;
124
- // Cancel any loading PDF task when closing
125
- if (this.currentLoadingTask) {
126
- this.currentLoadingTask.destroy();
127
- this.currentLoadingTask = null;
128
- }
129
- }
130
-
131
- override render() {
132
- if (!this.attachment) return html``;
133
-
134
- return html`
135
- <!-- Full screen overlay -->
136
- <div class="fixed inset-0 bg-black/90 z-50 flex flex-col" @click=${this.handleBackdropClick}>
137
- <!-- Compact header bar -->
138
- <div class="bg-background/95 backdrop-blur border-b border-border" @click=${(e: Event) => e.stopPropagation()}>
139
- <div class="px-4 py-2 flex items-center justify-between">
140
- <div class="flex items-center gap-3 min-w-0">
141
- <span class="text-sm font-medium text-foreground truncate">${this.attachment.fileName}</span>
142
- </div>
143
- <div class="flex items-center gap-2">
144
- ${this.renderToggle()}
145
- ${Button({
146
- variant: "ghost",
147
- size: "icon",
148
- onClick: this.handleDownload,
149
- children: icon(Download, "sm"),
150
- className: "h-8 w-8",
151
- })}
152
- ${Button({
153
- variant: "ghost",
154
- size: "icon",
155
- onClick: () => this.close(),
156
- children: icon(X, "sm"),
157
- className: "h-8 w-8",
158
- })}
159
- </div>
160
- </div>
161
- </div>
162
-
163
- <!-- Content container -->
164
- <div class="flex-1 flex items-center justify-center overflow-auto" @click=${(e: Event) => e.stopPropagation()}>
165
- ${this.renderContent()}
166
- </div>
167
- </div>
168
- `;
169
- }
170
-
171
- private renderToggle() {
172
- if (!this.attachment) return html``;
173
-
174
- const fileType = this.getFileType();
175
- const hasExtractedText = !!this.attachment.extractedText;
176
- const showToggle = fileType !== "image" && fileType !== "text" && fileType !== "pptx" && hasExtractedText;
177
-
178
- if (!showToggle) return html``;
179
-
180
- const fileTypeLabel = this.getFileTypeLabel();
181
-
182
- return html`
183
- <mode-toggle
184
- .modes=${[fileTypeLabel, i18n("Text")]}
185
- .selectedIndex=${this.showExtractedText ? 1 : 0}
186
- @mode-change=${(e: CustomEvent<{ index: number; mode: string }>) => {
187
- e.stopPropagation();
188
- this.showExtractedText = e.detail.index === 1;
189
- this.error = null;
190
- }}
191
- ></mode-toggle>
192
- `;
193
- }
194
-
195
- private renderContent() {
196
- if (!this.attachment) return html``;
197
-
198
- // Error state
199
- if (this.error) {
200
- return html`
201
- <div class="bg-destructive/10 border border-destructive text-destructive p-4 rounded-lg max-w-2xl">
202
- <div class="font-medium mb-1">${i18n("Error loading file")}</div>
203
- <div class="text-sm opacity-90">${this.error}</div>
204
- </div>
205
- `;
206
- }
207
-
208
- // Content based on file type
209
- return this.renderFileContent();
210
- }
211
-
212
- private renderFileContent() {
213
- if (!this.attachment) return html``;
214
-
215
- const fileType = this.getFileType();
216
-
217
- // Show extracted text if toggled
218
- if (this.showExtractedText && fileType !== "image") {
219
- return html`
220
- <div class="bg-card border border-border text-foreground p-6 w-full h-full max-w-4xl overflow-auto">
221
- <pre class="whitespace-pre-wrap font-mono text-xs leading-relaxed">${
222
- this.attachment.extractedText || i18n("No text content available")
223
- }</pre>
224
- </div>
225
- `;
226
- }
227
-
228
- // Render based on file type
229
- switch (fileType) {
230
- case "image": {
231
- const imageUrl = `data:${this.attachment.mimeType};base64,${this.attachment.content}`;
232
- return html`
233
- <img src="${imageUrl}" class="max-w-full max-h-full object-contain rounded-lg shadow-lg" alt="${this.attachment.fileName}" />
234
- `;
235
- }
236
-
237
- case "pdf":
238
- return html`
239
- <div
240
- id="pdf-container"
241
- class="bg-card text-foreground overflow-auto shadow-lg border border-border w-full h-full max-w-[1000px]"
242
- ></div>
243
- `;
244
-
245
- case "docx":
246
- return html`
247
- <div
248
- id="docx-container"
249
- class="bg-card text-foreground overflow-auto shadow-lg border border-border w-full h-full max-w-[1000px]"
250
- ></div>
251
- `;
252
-
253
- case "excel":
254
- return html` <div id="excel-container" class="bg-card text-foreground overflow-auto w-full h-full"></div> `;
255
-
256
- case "pptx":
257
- return html`
258
- <div
259
- id="pptx-container"
260
- class="bg-card text-foreground overflow-auto shadow-lg border border-border w-full h-full max-w-[1000px]"
261
- ></div>
262
- `;
263
-
264
- default:
265
- return html`
266
- <div class="bg-card border border-border text-foreground p-6 w-full h-full max-w-4xl overflow-auto">
267
- <pre class="whitespace-pre-wrap font-mono text-sm">${
268
- this.attachment.extractedText || i18n("No content available")
269
- }</pre>
270
- </div>
271
- `;
272
- }
273
- }
274
-
275
- override async updated(changedProperties: Map<string, any>) {
276
- super.updated(changedProperties);
277
-
278
- // Only process if we need to render the actual file (not extracted text)
279
- if (
280
- (changedProperties.has("attachment") || changedProperties.has("showExtractedText")) &&
281
- this.attachment &&
282
- !this.showExtractedText &&
283
- !this.error
284
- ) {
285
- const fileType = this.getFileType();
286
-
287
- switch (fileType) {
288
- case "pdf":
289
- await this.renderPdf();
290
- break;
291
- case "docx":
292
- await this.renderDocx();
293
- break;
294
- case "excel":
295
- await this.renderExcel();
296
- break;
297
- case "pptx":
298
- await this.renderExtractedText();
299
- break;
300
- }
301
- }
302
- }
303
-
304
- private async renderPdf() {
305
- const container = this.querySelector("#pdf-container");
306
- if (!container || !this.attachment) return;
307
-
308
- let pdf: PDFDocumentProxy | null = null;
309
-
310
- try {
311
- // Convert base64 to ArrayBuffer
312
- const arrayBuffer = this.base64ToArrayBuffer(this.attachment.content);
313
-
314
- // Cancel any existing loading task
315
- if (this.currentLoadingTask) {
316
- this.currentLoadingTask.destroy();
317
- }
318
-
319
- // Load the PDF
320
- this.currentLoadingTask = pdfjsLib.getDocument({ data: arrayBuffer });
321
- pdf = await this.currentLoadingTask.promise;
322
- this.currentLoadingTask = null;
323
-
324
- // Clear container and add wrapper
325
- container.innerHTML = "";
326
- const wrapper = document.createElement("div");
327
- wrapper.className = "";
328
- container.appendChild(wrapper);
329
-
330
- // Render all pages
331
- for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) {
332
- const page = await pdf.getPage(pageNum);
333
-
334
- // Create a container for each page
335
- const pageContainer = document.createElement("div");
336
- pageContainer.className = "mb-4 last:mb-0";
337
-
338
- // Create canvas for this page
339
- const canvas = document.createElement("canvas");
340
- const context = canvas.getContext("2d");
341
-
342
- // Set scale for reasonable resolution
343
- const viewport = page.getViewport({ scale: 1.5 });
344
- canvas.height = viewport.height;
345
- canvas.width = viewport.width;
346
-
347
- // Style the canvas
348
- canvas.className = "w-full max-w-full h-auto block mx-auto bg-white rounded shadow-sm border border-border";
349
-
350
- // Fill white background for proper PDF rendering
351
- if (context) {
352
- context.fillStyle = "white";
353
- context.fillRect(0, 0, canvas.width, canvas.height);
354
- }
355
-
356
- // Render page
357
- await page.render({
358
- canvasContext: context!,
359
- viewport: viewport,
360
- canvas: canvas,
361
- }).promise;
362
-
363
- pageContainer.appendChild(canvas);
364
-
365
- // Add page separator for multi-page documents
366
- if (pageNum < pdf.numPages) {
367
- const separator = document.createElement("div");
368
- separator.className = "h-px bg-border my-4";
369
- pageContainer.appendChild(separator);
370
- }
371
-
372
- wrapper.appendChild(pageContainer);
373
- }
374
- } catch (error) {
375
- console.error("Error rendering PDF:", error);
376
- this.error = (error instanceof Error ? error.message : undefined) || i18n("Failed to load PDF");
377
- } finally {
378
- if (pdf) {
379
- pdf.destroy();
380
- }
381
- }
382
- }
383
-
384
- private async renderDocx() {
385
- const container = this.querySelector("#docx-container");
386
- if (!container || !this.attachment) return;
387
-
388
- try {
389
- // Convert base64 to ArrayBuffer
390
- const arrayBuffer = this.base64ToArrayBuffer(this.attachment.content);
391
-
392
- // Clear container first
393
- container.innerHTML = "";
394
-
395
- // Create a wrapper div for the document
396
- const wrapper = document.createElement("div");
397
- wrapper.className = "docx-wrapper-custom";
398
- container.appendChild(wrapper);
399
-
400
- // Render the DOCX file into the wrapper
401
- await renderAsync(arrayBuffer, wrapper as HTMLElement, undefined, {
402
- className: "docx",
403
- inWrapper: true,
404
- ignoreWidth: true, // Let it be responsive
405
- ignoreHeight: false,
406
- ignoreFonts: false,
407
- breakPages: true,
408
- ignoreLastRenderedPageBreak: true,
409
- experimental: false,
410
- trimXmlDeclaration: true,
411
- useBase64URL: false,
412
- renderHeaders: true,
413
- renderFooters: true,
414
- renderFootnotes: true,
415
- renderEndnotes: true,
416
- });
417
-
418
- // Apply custom styles to match theme and fix sizing
419
- const style = document.createElement("style");
420
- style.textContent = `
421
- #docx-container {
422
- padding: 0;
423
- }
424
-
425
- #docx-container .docx-wrapper-custom {
426
- max-width: 100%;
427
- overflow-x: auto;
428
- }
429
-
430
- #docx-container .docx-wrapper {
431
- max-width: 100% !important;
432
- margin: 0 !important;
433
- background: transparent !important;
434
- padding: 0em !important;
435
- }
436
-
437
- #docx-container .docx-wrapper > section.docx {
438
- box-shadow: none !important;
439
- border: none !important;
440
- border-radius: 0 !important;
441
- margin: 0 !important;
442
- padding: 2em !important;
443
- background: white !important;
444
- color: black !important;
445
- max-width: 100% !important;
446
- width: 100% !important;
447
- min-width: 0 !important;
448
- overflow-x: auto !important;
449
- }
450
-
451
- /* Fix tables and wide content */
452
- #docx-container table {
453
- max-width: 100% !important;
454
- width: auto !important;
455
- overflow-x: auto !important;
456
- display: block !important;
457
- }
458
-
459
- #docx-container img {
460
- max-width: 100% !important;
461
- height: auto !important;
462
- }
463
-
464
- /* Fix paragraphs and text */
465
- #docx-container p,
466
- #docx-container span,
467
- #docx-container div {
468
- max-width: 100% !important;
469
- word-wrap: break-word !important;
470
- overflow-wrap: break-word !important;
471
- }
472
-
473
- /* Hide page breaks in web view */
474
- #docx-container .docx-page-break {
475
- display: none !important;
476
- }
477
- `;
478
- container.appendChild(style);
479
- } catch (error) {
480
- console.error("Error rendering DOCX:", error);
481
- this.error = (error instanceof Error ? error.message : undefined) || i18n("Failed to load document");
482
- }
483
- }
484
-
485
- private async renderExcel() {
486
- const container = this.querySelector("#excel-container");
487
- if (!container || !this.attachment) return;
488
-
489
- try {
490
- // Convert base64 to ArrayBuffer
491
- const arrayBuffer = this.base64ToArrayBuffer(this.attachment.content);
492
-
493
- // Read the workbook
494
- const workbook = XLSX.read(arrayBuffer, { type: "array" });
495
-
496
- // Clear container
497
- container.innerHTML = "";
498
- const wrapper = document.createElement("div");
499
- wrapper.className = "overflow-auto h-full flex flex-col";
500
- container.appendChild(wrapper);
501
-
502
- // Create tabs for multiple sheets
503
- if (workbook.SheetNames.length > 1) {
504
- const tabContainer = document.createElement("div");
505
- tabContainer.className = "flex gap-2 mb-4 border-b border-border sticky top-0 bg-card z-10";
506
-
507
- const sheetContents: HTMLElement[] = [];
508
-
509
- workbook.SheetNames.forEach((sheetName, index) => {
510
- // Create tab button
511
- const tab = document.createElement("button");
512
- tab.textContent = sheetName;
513
- tab.className =
514
- index === 0
515
- ? "px-4 py-2 text-sm font-medium border-b-2 border-primary text-primary"
516
- : "px-4 py-2 text-sm font-medium text-muted-foreground hover:text-foreground hover:border-b-2 hover:border-border transition-colors";
517
-
518
- // Create sheet content
519
- const sheetDiv = document.createElement("div");
520
- sheetDiv.style.display = index === 0 ? "flex" : "none";
521
- sheetDiv.className = "flex-1 overflow-auto";
522
- sheetDiv.appendChild(this.renderExcelSheet(workbook.Sheets[sheetName], sheetName));
523
- sheetContents.push(sheetDiv);
524
-
525
- // Tab click handler
526
- tab.onclick = () => {
527
- // Update tab styles
528
- tabContainer.querySelectorAll("button").forEach((btn, btnIndex) => {
529
- if (btnIndex === index) {
530
- btn.className = "px-4 py-2 text-sm font-medium border-b-2 border-primary text-primary";
531
- } else {
532
- btn.className =
533
- "px-4 py-2 text-sm font-medium text-muted-foreground hover:text-foreground hover:border-b-2 hover:border-border transition-colors";
534
- }
535
- });
536
- // Show/hide sheets
537
- sheetContents.forEach((content, contentIndex) => {
538
- content.style.display = contentIndex === index ? "flex" : "none";
539
- });
540
- };
541
-
542
- tabContainer.appendChild(tab);
543
- });
544
-
545
- wrapper.appendChild(tabContainer);
546
- sheetContents.forEach((content) => {
547
- wrapper.appendChild(content);
548
- });
549
- } else {
550
- // Single sheet
551
- const sheetName = workbook.SheetNames[0];
552
- wrapper.appendChild(this.renderExcelSheet(workbook.Sheets[sheetName], sheetName));
553
- }
554
- } catch (error) {
555
- console.error("Error rendering Excel:", error);
556
- this.error = (error instanceof Error ? error.message : undefined) || i18n("Failed to load spreadsheet");
557
- }
558
- }
559
-
560
- private renderExcelSheet(worksheet: XLSX.WorkSheet, sheetName: string): HTMLElement {
561
- const sheetDiv = document.createElement("div");
562
-
563
- // Generate HTML table
564
- const htmlTable = XLSX.utils.sheet_to_html(worksheet, { id: `sheet-${sheetName}` });
565
- const tempDiv = document.createElement("div");
566
- tempDiv.innerHTML = htmlTable;
567
-
568
- // Find and style the table
569
- const table = tempDiv.querySelector("table");
570
- if (table) {
571
- table.className = "w-full border-collapse text-foreground";
572
-
573
- // Style all cells
574
- table.querySelectorAll("td, th").forEach((cell) => {
575
- const cellEl = cell as HTMLElement;
576
- cellEl.className = "border border-border px-3 py-2 text-sm text-left";
577
- });
578
-
579
- // Style header row
580
- const headerCells = table.querySelectorAll("thead th, tr:first-child td");
581
- if (headerCells.length > 0) {
582
- headerCells.forEach((th) => {
583
- const thEl = th as HTMLElement;
584
- thEl.className =
585
- "border border-border px-3 py-2 text-sm font-semibold bg-muted text-foreground sticky top-0";
586
- });
587
- }
588
-
589
- // Alternate row colors
590
- table.querySelectorAll("tbody tr:nth-child(even)").forEach((row) => {
591
- const rowEl = row as HTMLElement;
592
- rowEl.className = "bg-muted/30";
593
- });
594
-
595
- sheetDiv.appendChild(table);
596
- }
597
-
598
- return sheetDiv;
599
- }
600
-
601
- private base64ToArrayBuffer(base64: string): ArrayBuffer {
602
- const binaryString = atob(base64);
603
- const bytes = new Uint8Array(binaryString.length);
604
- for (let i = 0; i < binaryString.length; i++) {
605
- bytes[i] = binaryString.charCodeAt(i);
606
- }
607
- return bytes.buffer;
608
- }
609
-
610
- private async renderExtractedText() {
611
- const container = this.querySelector("#pptx-container");
612
- if (!container || !this.attachment) return;
613
-
614
- try {
615
- // Display the extracted text content
616
- container.innerHTML = "";
617
- const wrapper = document.createElement("div");
618
- wrapper.className = "p-6 overflow-auto";
619
-
620
- // Create a pre element to preserve formatting
621
- const pre = document.createElement("pre");
622
- pre.className = "whitespace-pre-wrap text-sm text-foreground font-mono";
623
- pre.textContent = this.attachment.extractedText || i18n("No text content available");
624
-
625
- wrapper.appendChild(pre);
626
- container.appendChild(wrapper);
627
- } catch (error) {
628
- console.error("Error rendering extracted text:", error);
629
- this.error = (error instanceof Error ? error.message : undefined) || i18n("Failed to display text content");
630
- }
631
- }
632
- }
633
-
634
- // Register the custom element only once
635
- if (!customElements.get("attachment-overlay")) {
636
- customElements.define("attachment-overlay", AttachmentOverlay);
637
- }