@elyracode/web-ui 0.9.58 → 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 +13 -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,14 +0,0 @@
1
- import { LitElement, type TemplateResult } from "lit";
2
-
3
- export abstract class ArtifactElement extends LitElement {
4
- public filename = "";
5
-
6
- protected override createRenderRoot(): HTMLElement | DocumentFragment {
7
- return this; // light DOM for shared styles
8
- }
9
-
10
- public abstract get content(): string;
11
- public abstract set content(value: string);
12
-
13
- abstract getHeaderButtons(): TemplateResult | HTMLElement;
14
- }
@@ -1,26 +0,0 @@
1
- import { icon } from "@elyracode/mini-lit";
2
- import { html, type TemplateResult } from "lit";
3
- import { FileCode2 } from "lucide";
4
- import type { ArtifactsPanel } from "./artifacts.js";
5
-
6
- export function ArtifactPill(filename: string, artifactsPanel?: ArtifactsPanel): TemplateResult {
7
- const handleClick = (e: Event) => {
8
- if (!artifactsPanel) return;
9
- e.preventDefault();
10
- e.stopPropagation();
11
- // openArtifact will show the artifact and call onOpen() to open the panel if needed
12
- artifactsPanel.openArtifact(filename);
13
- };
14
-
15
- return html`
16
- <span
17
- class="inline-flex items-center gap-1 px-2 py-0.5 text-xs bg-muted/50 border border-border rounded ${
18
- artifactsPanel ? "cursor-pointer hover:bg-muted transition-colors" : ""
19
- }"
20
- @click=${artifactsPanel ? handleClick : null}
21
- >
22
- ${icon(FileCode2, "sm")}
23
- <span class="text-foreground">${filename}</span>
24
- </span>
25
- `;
26
- }
@@ -1,93 +0,0 @@
1
- import { icon } from "@elyracode/mini-lit";
2
- import "@elyracode/mini-lit/dist/CopyButton.js";
3
- import { html, LitElement, type TemplateResult } from "lit";
4
- import { customElement, property, state } from "lit/decorators.js";
5
- import { createRef, type Ref, ref } from "lit/directives/ref.js";
6
- import { repeat } from "lit/directives/repeat.js";
7
- import { ChevronDown, ChevronRight, ChevronsDown, Lock } from "lucide";
8
- import { i18n } from "../../utils/i18n.js";
9
-
10
- interface LogEntry {
11
- type: "log" | "error";
12
- text: string;
13
- }
14
-
15
- @customElement("artifact-console")
16
- export class Console extends LitElement {
17
- @property({ attribute: false }) logs: LogEntry[] = [];
18
- @state() private expanded = false;
19
- @state() private autoscroll = true;
20
- private logsContainerRef: Ref<HTMLDivElement> = createRef();
21
-
22
- protected createRenderRoot() {
23
- return this; // light DOM
24
- }
25
-
26
- override updated() {
27
- // Autoscroll to bottom when new logs arrive
28
- if (this.autoscroll && this.expanded && this.logsContainerRef.value) {
29
- this.logsContainerRef.value.scrollTop = this.logsContainerRef.value.scrollHeight;
30
- }
31
- }
32
-
33
- private getLogsText(): string {
34
- return this.logs.map((l) => `[${l.type}] ${l.text}`).join("\n");
35
- }
36
-
37
- override render(): TemplateResult {
38
- const errorCount = this.logs.filter((l) => l.type === "error").length;
39
- const summary =
40
- errorCount > 0
41
- ? `${i18n("console")} (${errorCount} ${errorCount === 1 ? "error" : "errors"})`
42
- : `${i18n("console")} (${this.logs.length})`;
43
-
44
- return html`
45
- <div class="border-t border-border p-2">
46
- <div class="flex items-center gap-2 w-full">
47
- <button
48
- @click=${() => {
49
- this.expanded = !this.expanded;
50
- }}
51
- class="flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors flex-1 text-left"
52
- >
53
- ${icon(this.expanded ? ChevronDown : ChevronRight, "sm")}
54
- <span>${summary}</span>
55
- </button>
56
- ${
57
- this.expanded
58
- ? html`
59
- <button
60
- @click=${() => {
61
- this.autoscroll = !this.autoscroll;
62
- }}
63
- class="p-1 rounded transition-colors ${this.autoscroll ? "bg-accent text-accent-foreground" : "hover:bg-muted"}"
64
- title=${this.autoscroll ? i18n("Autoscroll enabled") : i18n("Autoscroll disabled")}
65
- >
66
- ${icon(this.autoscroll ? ChevronsDown : Lock, "sm")}
67
- </button>
68
- <copy-button .text=${this.getLogsText()} title=${i18n("Copy logs")} .showText=${false} class="!bg-transparent hover:!bg-accent"></copy-button>
69
- `
70
- : ""
71
- }
72
- </div>
73
- ${
74
- this.expanded
75
- ? html`
76
- <div class="max-h-48 overflow-y-auto space-y-1 mt-2" ${ref(this.logsContainerRef)}>
77
- ${repeat(
78
- this.logs,
79
- (_log, index) => index,
80
- (log) => html`
81
- <div class="text-xs font-mono ${log.type === "error" ? "text-destructive" : "text-muted-foreground"}">
82
- [${log.type}] ${log.text}
83
- </div>
84
- `,
85
- )}
86
- </div>
87
- `
88
- : ""
89
- }
90
- </div>
91
- `;
92
- }
93
- }
@@ -1,213 +0,0 @@
1
- import { DownloadButton } from "@elyracode/mini-lit/dist/DownloadButton.js";
2
- import { renderAsync } from "docx-preview";
3
- import { html, type TemplateResult } from "lit";
4
- import { customElement, property, state } from "lit/decorators.js";
5
- import { i18n } from "../../utils/i18n.js";
6
- import { ArtifactElement } from "./ArtifactElement.js";
7
-
8
- @customElement("docx-artifact")
9
- export class DocxArtifact extends ArtifactElement {
10
- @property({ type: String }) private _content = "";
11
- @state() private error: string | null = null;
12
-
13
- get content(): string {
14
- return this._content;
15
- }
16
-
17
- set content(value: string) {
18
- this._content = value;
19
- this.error = null;
20
- this.requestUpdate();
21
- }
22
-
23
- protected override createRenderRoot(): HTMLElement | DocumentFragment {
24
- return this;
25
- }
26
-
27
- override connectedCallback(): void {
28
- super.connectedCallback();
29
- this.style.display = "block";
30
- this.style.height = "100%";
31
- }
32
-
33
- private base64ToArrayBuffer(base64: string): ArrayBuffer {
34
- // Remove data URL prefix if present
35
- let base64Data = base64;
36
- if (base64.startsWith("data:")) {
37
- const base64Match = base64.match(/base64,(.+)/);
38
- if (base64Match) {
39
- base64Data = base64Match[1];
40
- }
41
- }
42
-
43
- const binaryString = atob(base64Data);
44
- const bytes = new Uint8Array(binaryString.length);
45
- for (let i = 0; i < binaryString.length; i++) {
46
- bytes[i] = binaryString.charCodeAt(i);
47
- }
48
- return bytes.buffer;
49
- }
50
-
51
- private decodeBase64(): Uint8Array {
52
- let base64Data = this._content;
53
- if (this._content.startsWith("data:")) {
54
- const base64Match = this._content.match(/base64,(.+)/);
55
- if (base64Match) {
56
- base64Data = base64Match[1];
57
- }
58
- }
59
-
60
- const binaryString = atob(base64Data);
61
- const bytes = new Uint8Array(binaryString.length);
62
- for (let i = 0; i < binaryString.length; i++) {
63
- bytes[i] = binaryString.charCodeAt(i);
64
- }
65
- return bytes;
66
- }
67
-
68
- public getHeaderButtons() {
69
- return html`
70
- <div class="flex items-center gap-1">
71
- ${DownloadButton({
72
- content: this.decodeBase64(),
73
- filename: this.filename,
74
- mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
75
- title: i18n("Download"),
76
- })}
77
- </div>
78
- `;
79
- }
80
-
81
- override async updated(changedProperties: Map<string, any>) {
82
- super.updated(changedProperties);
83
-
84
- if (changedProperties.has("_content") && this._content && !this.error) {
85
- await this.renderDocx();
86
- }
87
- }
88
-
89
- private async renderDocx() {
90
- const container = this.querySelector("#docx-container");
91
- if (!container || !this._content) return;
92
-
93
- try {
94
- const arrayBuffer = this.base64ToArrayBuffer(this._content);
95
-
96
- // Clear container first
97
- container.innerHTML = "";
98
-
99
- // Create a wrapper div for the document
100
- const wrapper = document.createElement("div");
101
- wrapper.className = "docx-wrapper-custom";
102
- container.appendChild(wrapper);
103
-
104
- // Render the DOCX file into the wrapper
105
- await renderAsync(arrayBuffer, wrapper as HTMLElement, undefined, {
106
- className: "docx",
107
- inWrapper: true,
108
- ignoreWidth: true,
109
- ignoreHeight: false,
110
- ignoreFonts: false,
111
- breakPages: true,
112
- ignoreLastRenderedPageBreak: true,
113
- experimental: false,
114
- trimXmlDeclaration: true,
115
- useBase64URL: false,
116
- renderHeaders: true,
117
- renderFooters: true,
118
- renderFootnotes: true,
119
- renderEndnotes: true,
120
- });
121
-
122
- // Apply custom styles to match theme and fix sizing
123
- const style = document.createElement("style");
124
- style.textContent = `
125
- #docx-container {
126
- padding: 0;
127
- }
128
-
129
- #docx-container .docx-wrapper-custom {
130
- max-width: 100%;
131
- overflow-x: auto;
132
- }
133
-
134
- #docx-container .docx-wrapper {
135
- max-width: 100% !important;
136
- margin: 0 !important;
137
- background: transparent !important;
138
- padding: 0em !important;
139
- }
140
-
141
- #docx-container .docx-wrapper > section.docx {
142
- box-shadow: none !important;
143
- border: none !important;
144
- border-radius: 0 !important;
145
- margin: 0 !important;
146
- padding: 2em !important;
147
- background: white !important;
148
- color: black !important;
149
- max-width: 100% !important;
150
- width: 100% !important;
151
- min-width: 0 !important;
152
- overflow-x: auto !important;
153
- }
154
-
155
- /* Fix tables and wide content */
156
- #docx-container table {
157
- max-width: 100% !important;
158
- width: auto !important;
159
- overflow-x: auto !important;
160
- display: block !important;
161
- }
162
-
163
- #docx-container img {
164
- max-width: 100% !important;
165
- height: auto !important;
166
- }
167
-
168
- /* Fix paragraphs and text */
169
- #docx-container p,
170
- #docx-container span,
171
- #docx-container div {
172
- max-width: 100% !important;
173
- word-wrap: break-word !important;
174
- overflow-wrap: break-word !important;
175
- }
176
-
177
- /* Hide page breaks in web view */
178
- #docx-container .docx-page-break {
179
- display: none !important;
180
- }
181
- `;
182
- container.appendChild(style);
183
- } catch (error) {
184
- console.error("Error rendering DOCX:", error);
185
- this.error = error instanceof Error ? error.message : i18n("Failed to load document");
186
- }
187
- }
188
-
189
- override render(): TemplateResult {
190
- if (this.error) {
191
- return html`
192
- <div class="h-full flex items-center justify-center bg-background p-4">
193
- <div class="bg-destructive/10 border border-destructive text-destructive p-4 rounded-lg max-w-2xl">
194
- <div class="font-medium mb-1">${i18n("Error loading document")}</div>
195
- <div class="text-sm opacity-90">${this.error}</div>
196
- </div>
197
- </div>
198
- `;
199
- }
200
-
201
- return html`
202
- <div class="h-full flex flex-col bg-background overflow-auto">
203
- <div id="docx-container" class="flex-1 overflow-auto"></div>
204
- </div>
205
- `;
206
- }
207
- }
208
-
209
- declare global {
210
- interface HTMLElementTagNameMap {
211
- "docx-artifact": DocxArtifact;
212
- }
213
- }
@@ -1,231 +0,0 @@
1
- import { DownloadButton } from "@elyracode/mini-lit/dist/DownloadButton.js";
2
- import { html, type TemplateResult } from "lit";
3
- import { customElement, property, state } from "lit/decorators.js";
4
- import * as XLSX from "xlsx";
5
- import { i18n } from "../../utils/i18n.js";
6
- import { ArtifactElement } from "./ArtifactElement.js";
7
-
8
- @customElement("excel-artifact")
9
- export class ExcelArtifact extends ArtifactElement {
10
- @property({ type: String }) private _content = "";
11
- @state() private error: string | null = null;
12
-
13
- get content(): string {
14
- return this._content;
15
- }
16
-
17
- set content(value: string) {
18
- this._content = value;
19
- this.error = null;
20
- this.requestUpdate();
21
- }
22
-
23
- protected override createRenderRoot(): HTMLElement | DocumentFragment {
24
- return this;
25
- }
26
-
27
- override connectedCallback(): void {
28
- super.connectedCallback();
29
- this.style.display = "block";
30
- this.style.height = "100%";
31
- }
32
-
33
- private base64ToArrayBuffer(base64: string): ArrayBuffer {
34
- // Remove data URL prefix if present
35
- let base64Data = base64;
36
- if (base64.startsWith("data:")) {
37
- const base64Match = base64.match(/base64,(.+)/);
38
- if (base64Match) {
39
- base64Data = base64Match[1];
40
- }
41
- }
42
-
43
- const binaryString = atob(base64Data);
44
- const bytes = new Uint8Array(binaryString.length);
45
- for (let i = 0; i < binaryString.length; i++) {
46
- bytes[i] = binaryString.charCodeAt(i);
47
- }
48
- return bytes.buffer;
49
- }
50
-
51
- private decodeBase64(): Uint8Array {
52
- let base64Data = this._content;
53
- if (this._content.startsWith("data:")) {
54
- const base64Match = this._content.match(/base64,(.+)/);
55
- if (base64Match) {
56
- base64Data = base64Match[1];
57
- }
58
- }
59
-
60
- const binaryString = atob(base64Data);
61
- const bytes = new Uint8Array(binaryString.length);
62
- for (let i = 0; i < binaryString.length; i++) {
63
- bytes[i] = binaryString.charCodeAt(i);
64
- }
65
- return bytes;
66
- }
67
-
68
- private getMimeType(): string {
69
- const ext = this.filename.split(".").pop()?.toLowerCase();
70
- if (ext === "xls") return "application/vnd.ms-excel";
71
- return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
72
- }
73
-
74
- public getHeaderButtons() {
75
- return html`
76
- <div class="flex items-center gap-1">
77
- ${DownloadButton({
78
- content: this.decodeBase64(),
79
- filename: this.filename,
80
- mimeType: this.getMimeType(),
81
- title: i18n("Download"),
82
- })}
83
- </div>
84
- `;
85
- }
86
-
87
- override async updated(changedProperties: Map<string, any>) {
88
- super.updated(changedProperties);
89
-
90
- if (changedProperties.has("_content") && this._content && !this.error) {
91
- await this.renderExcel();
92
- }
93
- }
94
-
95
- private async renderExcel() {
96
- const container = this.querySelector("#excel-container");
97
- if (!container || !this._content) return;
98
-
99
- try {
100
- const arrayBuffer = this.base64ToArrayBuffer(this._content);
101
- const workbook = XLSX.read(arrayBuffer, { type: "array" });
102
-
103
- container.innerHTML = "";
104
- const wrapper = document.createElement("div");
105
- wrapper.className = "overflow-auto h-full flex flex-col";
106
- container.appendChild(wrapper);
107
-
108
- // Create tabs for multiple sheets
109
- if (workbook.SheetNames.length > 1) {
110
- const tabContainer = document.createElement("div");
111
- tabContainer.className = "flex gap-2 mb-4 border-b border-border sticky top-0 bg-background z-10";
112
-
113
- const sheetContents: HTMLElement[] = [];
114
-
115
- workbook.SheetNames.forEach((sheetName, index) => {
116
- // Create tab button
117
- const tab = document.createElement("button");
118
- tab.textContent = sheetName;
119
- tab.className =
120
- index === 0
121
- ? "px-4 py-2 text-sm font-medium border-b-2 border-primary text-primary"
122
- : "px-4 py-2 text-sm font-medium text-muted-foreground hover:text-foreground hover:border-b-2 hover:border-border transition-colors";
123
-
124
- // Create sheet content
125
- const sheetDiv = document.createElement("div");
126
- sheetDiv.style.display = index === 0 ? "flex" : "none";
127
- sheetDiv.className = "flex-1 overflow-auto";
128
- sheetDiv.appendChild(this.renderExcelSheet(workbook.Sheets[sheetName], sheetName));
129
- sheetContents.push(sheetDiv);
130
-
131
- // Tab click handler
132
- tab.onclick = () => {
133
- // Update tab styles
134
- tabContainer.querySelectorAll("button").forEach((btn, btnIndex) => {
135
- if (btnIndex === index) {
136
- btn.className = "px-4 py-2 text-sm font-medium border-b-2 border-primary text-primary";
137
- } else {
138
- btn.className =
139
- "px-4 py-2 text-sm font-medium text-muted-foreground hover:text-foreground hover:border-b-2 hover:border-border transition-colors";
140
- }
141
- });
142
- // Show/hide sheets
143
- sheetContents.forEach((content, contentIndex) => {
144
- content.style.display = contentIndex === index ? "flex" : "none";
145
- });
146
- };
147
-
148
- tabContainer.appendChild(tab);
149
- });
150
-
151
- wrapper.appendChild(tabContainer);
152
- sheetContents.forEach((content) => {
153
- wrapper.appendChild(content);
154
- });
155
- } else {
156
- // Single sheet
157
- const sheetName = workbook.SheetNames[0];
158
- wrapper.appendChild(this.renderExcelSheet(workbook.Sheets[sheetName], sheetName));
159
- }
160
- } catch (error) {
161
- console.error("Error rendering Excel:", error);
162
- this.error = error instanceof Error ? error.message : i18n("Failed to load spreadsheet");
163
- }
164
- }
165
-
166
- private renderExcelSheet(worksheet: XLSX.WorkSheet, sheetName: string): HTMLElement {
167
- const sheetDiv = document.createElement("div");
168
-
169
- // Generate HTML table
170
- const htmlTable = XLSX.utils.sheet_to_html(worksheet, { id: `sheet-${sheetName}` });
171
- const tempDiv = document.createElement("div");
172
- tempDiv.innerHTML = htmlTable;
173
-
174
- // Find and style the table
175
- const table = tempDiv.querySelector("table");
176
- if (table) {
177
- table.className = "w-full border-collapse text-foreground";
178
-
179
- // Style all cells
180
- table.querySelectorAll("td, th").forEach((cell) => {
181
- const cellEl = cell as HTMLElement;
182
- cellEl.className = "border border-border px-3 py-2 text-sm text-left";
183
- });
184
-
185
- // Style header row
186
- const headerCells = table.querySelectorAll("thead th, tr:first-child td");
187
- if (headerCells.length > 0) {
188
- headerCells.forEach((th) => {
189
- const thEl = th as HTMLElement;
190
- thEl.className =
191
- "border border-border px-3 py-2 text-sm font-semibold bg-muted text-foreground sticky top-0";
192
- });
193
- }
194
-
195
- // Alternate row colors
196
- table.querySelectorAll("tbody tr:nth-child(even)").forEach((row) => {
197
- const rowEl = row as HTMLElement;
198
- rowEl.className = "bg-muted/30";
199
- });
200
-
201
- sheetDiv.appendChild(table);
202
- }
203
-
204
- return sheetDiv;
205
- }
206
-
207
- override render(): TemplateResult {
208
- if (this.error) {
209
- return html`
210
- <div class="h-full flex items-center justify-center bg-background p-4">
211
- <div class="bg-destructive/10 border border-destructive text-destructive p-4 rounded-lg max-w-2xl">
212
- <div class="font-medium mb-1">${i18n("Error loading spreadsheet")}</div>
213
- <div class="text-sm opacity-90">${this.error}</div>
214
- </div>
215
- </div>
216
- `;
217
- }
218
-
219
- return html`
220
- <div class="h-full flex flex-col bg-background overflow-auto">
221
- <div id="excel-container" class="flex-1 overflow-auto"></div>
222
- </div>
223
- `;
224
- }
225
- }
226
-
227
- declare global {
228
- interface HTMLElementTagNameMap {
229
- "excel-artifact": ExcelArtifact;
230
- }
231
- }
@@ -1,117 +0,0 @@
1
- import { DownloadButton } from "@elyracode/mini-lit/dist/DownloadButton.js";
2
- import { html, type TemplateResult } from "lit";
3
- import { customElement, property } from "lit/decorators.js";
4
- import { i18n } from "../../utils/i18n.js";
5
- import { ArtifactElement } from "./ArtifactElement.js";
6
-
7
- @customElement("generic-artifact")
8
- export class GenericArtifact extends ArtifactElement {
9
- @property({ type: String }) private _content = "";
10
-
11
- get content(): string {
12
- return this._content;
13
- }
14
-
15
- set content(value: string) {
16
- this._content = value;
17
- this.requestUpdate();
18
- }
19
-
20
- protected override createRenderRoot(): HTMLElement | DocumentFragment {
21
- return this;
22
- }
23
-
24
- override connectedCallback(): void {
25
- super.connectedCallback();
26
- this.style.display = "block";
27
- this.style.height = "100%";
28
- }
29
-
30
- private decodeBase64(): Uint8Array {
31
- let base64Data = this._content;
32
- if (this._content.startsWith("data:")) {
33
- const base64Match = this._content.match(/base64,(.+)/);
34
- if (base64Match) {
35
- base64Data = base64Match[1];
36
- }
37
- }
38
-
39
- const binaryString = atob(base64Data);
40
- const bytes = new Uint8Array(binaryString.length);
41
- for (let i = 0; i < binaryString.length; i++) {
42
- bytes[i] = binaryString.charCodeAt(i);
43
- }
44
- return bytes;
45
- }
46
-
47
- private getMimeType(): string {
48
- const ext = this.filename.split(".").pop()?.toLowerCase();
49
- // Add common MIME types
50
- const mimeTypes: Record<string, string> = {
51
- pdf: "application/pdf",
52
- zip: "application/zip",
53
- tar: "application/x-tar",
54
- gz: "application/gzip",
55
- rar: "application/vnd.rar",
56
- "7z": "application/x-7z-compressed",
57
- mp3: "audio/mpeg",
58
- mp4: "video/mp4",
59
- avi: "video/x-msvideo",
60
- mov: "video/quicktime",
61
- wav: "audio/wav",
62
- ogg: "audio/ogg",
63
- json: "application/json",
64
- xml: "application/xml",
65
- bin: "application/octet-stream",
66
- };
67
- return mimeTypes[ext || ""] || "application/octet-stream";
68
- }
69
-
70
- public getHeaderButtons() {
71
- return html`
72
- <div class="flex items-center gap-1">
73
- ${DownloadButton({
74
- content: this.decodeBase64(),
75
- filename: this.filename,
76
- mimeType: this.getMimeType(),
77
- title: i18n("Download"),
78
- })}
79
- </div>
80
- `;
81
- }
82
-
83
- override render(): TemplateResult {
84
- return html`
85
- <div class="h-full flex items-center justify-center bg-background p-8">
86
- <div class="text-center max-w-md">
87
- <div class="text-muted-foreground text-lg mb-4">
88
- <svg
89
- xmlns="http://www.w3.org/2000/svg"
90
- class="h-16 w-16 mx-auto mb-4 text-muted-foreground/50"
91
- fill="none"
92
- viewBox="0 0 24 24"
93
- stroke="currentColor"
94
- >
95
- <path
96
- stroke-linecap="round"
97
- stroke-linejoin="round"
98
- stroke-width="1.5"
99
- d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"
100
- />
101
- </svg>
102
- <div class="font-medium text-foreground mb-2">${this.filename}</div>
103
- <p class="text-sm">
104
- ${i18n("Preview not available for this file type.")} ${i18n("Click the download button above to view it on your computer.")}
105
- </p>
106
- </div>
107
- </div>
108
- </div>
109
- `;
110
- }
111
- }
112
-
113
- declare global {
114
- interface HTMLElementTagNameMap {
115
- "generic-artifact": GenericArtifact;
116
- }
117
- }