@eclipse-lyra/extension-dataviewer 0.7.26 → 0.7.28

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.
@@ -0,0 +1,759 @@
1
+ import { css, LitElement, html } from "lit";
2
+ import { subscribe, persistenceService, publish, LyraPart, toastError, filebrowserDialog, rootContext, contributionRegistry, PANEL_BOTTOM, editorRegistry, File } from "@eclipse-lyra/core";
3
+ import { v4 } from "@eclipse-lyra/core/externals/third-party";
4
+ import { TOPIC_DATAVIEW_PUBLISH, TOPIC_DATAVIEW_ADDED } from "./api.js";
5
+ import { property, state, customElement } from "lit/decorators.js";
6
+ import { when } from "@eclipse-lyra/core/externals/lit";
7
+ import Papa from "papaparse";
8
+ const KEY_PREFIX = "dataview/";
9
+ const KEY_INDEX = KEY_PREFIX + "index";
10
+ class DataviewerService {
11
+ init() {
12
+ if (this.subscriptionToken !== void 0) return;
13
+ this.subscriptionToken = subscribe(TOPIC_DATAVIEW_PUBLISH, (payload) => {
14
+ void this.handlePublish(payload);
15
+ });
16
+ }
17
+ async handlePublish(payload) {
18
+ const storageKey = v4();
19
+ const createdAt = Date.now();
20
+ const entry = {
21
+ id: payload.id ?? storageKey,
22
+ title: payload.title,
23
+ data: payload.data,
24
+ source: payload.source,
25
+ createdAt
26
+ };
27
+ await persistenceService.persistObject(KEY_PREFIX + storageKey, entry);
28
+ const index = await persistenceService.getObject(KEY_INDEX);
29
+ const list = Array.isArray(index) ? index : [];
30
+ list.push({ storageKey, title: payload.title, source: payload.source, createdAt });
31
+ await persistenceService.persistObject(KEY_INDEX, list);
32
+ publish(TOPIC_DATAVIEW_ADDED, { storageKey, title: payload.title, createdAt });
33
+ }
34
+ async listViews() {
35
+ const raw = await persistenceService.getObject(KEY_INDEX);
36
+ if (!Array.isArray(raw) || raw.length === 0) return [];
37
+ if (typeof raw[0] === "string") {
38
+ return raw.map((storageKey) => ({
39
+ storageKey,
40
+ title: storageKey,
41
+ createdAt: 0
42
+ }));
43
+ }
44
+ const list = raw;
45
+ return [...list].sort((a, b) => a.createdAt - b.createdAt);
46
+ }
47
+ async getView(storageKey) {
48
+ const entry = await persistenceService.getObject(KEY_PREFIX + storageKey);
49
+ return entry ?? null;
50
+ }
51
+ async deleteView(storageKey) {
52
+ const index = await persistenceService.getObject(KEY_INDEX);
53
+ const list = Array.isArray(index) ? index.filter((e) => e.storageKey !== storageKey) : [];
54
+ await persistenceService.persistObject(KEY_INDEX, list);
55
+ await persistenceService.persistObject(KEY_PREFIX + storageKey, null);
56
+ }
57
+ async clearAllViews() {
58
+ const index = await persistenceService.getObject(KEY_INDEX);
59
+ const list = Array.isArray(index) ? index : [];
60
+ await Promise.all(list.map((entry) => persistenceService.persistObject(KEY_PREFIX + entry.storageKey, null)));
61
+ await persistenceService.persistObject(KEY_INDEX, []);
62
+ }
63
+ }
64
+ const dataviewerService = new DataviewerService();
65
+ var __defProp$1 = Object.defineProperty;
66
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
67
+ var __decorateClass$1 = (decorators, target, key, kind) => {
68
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
69
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
70
+ if (decorator = decorators[i])
71
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
72
+ if (kind && result) __defProp$1(target, key, result);
73
+ return result;
74
+ };
75
+ function cellString(value) {
76
+ if (value === null || value === void 0) return "";
77
+ return String(value);
78
+ }
79
+ function isNumericColumn(rows, colIndex) {
80
+ if (rows.length === 0) return false;
81
+ return rows.every((row) => {
82
+ const v = row[colIndex];
83
+ if (v === null || v === void 0) return true;
84
+ const n = Number(v);
85
+ return Number.isFinite(n);
86
+ });
87
+ }
88
+ function compareCells(a, b, numeric) {
89
+ if (numeric) {
90
+ const na = Number(a);
91
+ const nb = Number(b);
92
+ if (!Number.isFinite(na)) return Number.isFinite(nb) ? 1 : 0;
93
+ if (!Number.isFinite(nb)) return -1;
94
+ return na - nb;
95
+ }
96
+ return cellString(a).localeCompare(cellString(b), void 0, { numeric: true });
97
+ }
98
+ let LyraDataTable = class extends LitElement {
99
+ constructor() {
100
+ super(...arguments);
101
+ this.data = { columns: [], rows: [] };
102
+ this.emptyMessage = "No data.";
103
+ this.sortColumnIndex = null;
104
+ this.sortDirection = "asc";
105
+ this.filterQuery = "";
106
+ this.pageSize = 25;
107
+ this.currentPage = 0;
108
+ }
109
+ get columns() {
110
+ return Array.isArray(this.data?.columns) ? this.data.columns : [];
111
+ }
112
+ get rows() {
113
+ return Array.isArray(this.data?.rows) ? this.data.rows : [];
114
+ }
115
+ get filteredRows() {
116
+ const q = this.filterQuery.trim().toLowerCase();
117
+ if (!q) return this.rows;
118
+ return this.rows.filter(
119
+ (row) => row.some((cell) => cellString(cell).toLowerCase().includes(q))
120
+ );
121
+ }
122
+ get sortedRows() {
123
+ const filtered = this.filteredRows;
124
+ if (this.sortColumnIndex == null || this.sortColumnIndex < 0) return filtered;
125
+ const col = this.sortColumnIndex;
126
+ const numeric = isNumericColumn(filtered, col);
127
+ const dir = this.sortDirection === "asc" ? 1 : -1;
128
+ return [...filtered].sort((rowA, rowB) => {
129
+ const a = rowA[col];
130
+ const b = rowB[col];
131
+ return dir * compareCells(a, b, numeric);
132
+ });
133
+ }
134
+ get totalRows() {
135
+ return this.sortedRows.length;
136
+ }
137
+ get pageCount() {
138
+ const total = this.totalRows;
139
+ if (total === 0) return 1;
140
+ return Math.ceil(total / this.pageSize);
141
+ }
142
+ get pagedRows() {
143
+ const all = this.sortedRows;
144
+ const page = this.clampedPage;
145
+ const start = page * this.pageSize;
146
+ return all.slice(start, start + this.pageSize);
147
+ }
148
+ get clampedPage() {
149
+ const count = this.pageCount;
150
+ return count <= 0 ? 0 : Math.min(this.currentPage, count - 1);
151
+ }
152
+ goToPage(page) {
153
+ const last = Math.max(0, this.pageCount - 1);
154
+ this.currentPage = Math.max(0, Math.min(page, last));
155
+ this.requestUpdate();
156
+ }
157
+ onPageSizeChange(e) {
158
+ const val = e.target.value;
159
+ const n = parseInt(val, 10);
160
+ if (!Number.isFinite(n) || n < 1) return;
161
+ this.pageSize = n;
162
+ this.currentPage = 0;
163
+ this.requestUpdate();
164
+ }
165
+ onSort(colIndex) {
166
+ if (this.sortColumnIndex === colIndex) {
167
+ this.sortDirection = this.sortDirection === "asc" ? "desc" : "asc";
168
+ } else {
169
+ this.sortColumnIndex = colIndex;
170
+ this.sortDirection = "asc";
171
+ }
172
+ this.requestUpdate();
173
+ }
174
+ onFilterInput(e) {
175
+ this.filterQuery = e.target.value;
176
+ this.requestUpdate();
177
+ }
178
+ clearFilter() {
179
+ this.filterQuery = "";
180
+ this.requestUpdate();
181
+ }
182
+ getSortAria(colIndex) {
183
+ if (this.sortColumnIndex !== colIndex) return "none";
184
+ return this.sortDirection === "asc" ? "ascending" : "descending";
185
+ }
186
+ render() {
187
+ const { columns } = this;
188
+ const total = this.totalRows;
189
+ const displayRows = this.pagedRows;
190
+ const page = this.clampedPage;
191
+ const count = this.pageCount;
192
+ const start = total === 0 ? 0 : page * this.pageSize + 1;
193
+ const end = Math.min((page + 1) * this.pageSize, total);
194
+ if (columns.length === 0 && total === 0 && this.rows.length === 0) {
195
+ return html`<div class="table-empty">${this.emptyMessage}</div>`;
196
+ }
197
+ return html`
198
+ <div class="table-toolbar">
199
+ <wa-input
200
+ class="filter-input"
201
+ placeholder="Filter…"
202
+ .value=${this.filterQuery}
203
+ @input=${this.onFilterInput}
204
+ @wa-clear=${this.clearFilter}
205
+ with-clear
206
+ size="small"
207
+ aria-label="Filter rows"
208
+ >
209
+ <wa-icon slot="start" name="magnifying-glass" label="Filter"></wa-icon>
210
+ </wa-input>
211
+ <div class="paging-controls">
212
+ <wa-select
213
+ class="page-size-select"
214
+ size="small"
215
+ .value=${String(this.pageSize)}
216
+ title="Rows per page"
217
+ @change=${this.onPageSizeChange}
218
+ >
219
+ ${LyraDataTable.PAGE_SIZE_OPTIONS.map(
220
+ (n) => html`<wa-option value=${String(n)}>${n}</wa-option>`
221
+ )}
222
+ </wa-select>
223
+ <span class="paging-summary" aria-live="polite">
224
+ ${total === 0 ? "0 rows" : `${start}–${end} of ${total}`}
225
+ </span>
226
+ <wa-button
227
+ size="small"
228
+ appearance="plain"
229
+ title="Previous page"
230
+ ?disabled=${count <= 1 || page <= 0}
231
+ @click=${() => this.goToPage(page - 1)}
232
+ >
233
+ <wa-icon name="chevron-left" label="Previous"></wa-icon>
234
+ </wa-button>
235
+ <wa-button
236
+ size="small"
237
+ appearance="plain"
238
+ title="Next page"
239
+ ?disabled=${count <= 1 || page >= count - 1}
240
+ @click=${() => this.goToPage(page + 1)}
241
+ >
242
+ <wa-icon name="chevron-right" label="Next"></wa-icon>
243
+ </wa-button>
244
+ </div>
245
+ </div>
246
+ <div class="table-wrap">
247
+ <table class="result-table">
248
+ <thead>
249
+ <tr>
250
+ ${columns.map(
251
+ (col, i) => html`
252
+ <th scope="col" role="columnheader" aria-sort=${this.getSortAria(i)}>
253
+ <button
254
+ type="button"
255
+ class="th-sort"
256
+ @click=${() => this.onSort(i)}
257
+ title="Sort by ${col}"
258
+ >
259
+ <span class="th-label">${col}</span>
260
+ ${this.sortColumnIndex === i ? html`<wa-icon
261
+ name=${this.sortDirection === "asc" ? "arrow-up" : "arrow-down"}
262
+ label=${this.sortDirection}
263
+ ></wa-icon>` : html`<wa-icon name="arrows-up-down" label="Sort"></wa-icon>`}
264
+ </button>
265
+ </th>
266
+ `
267
+ )}
268
+ </tr>
269
+ </thead>
270
+ <tbody>
271
+ ${displayRows.length === 0 ? html`<tr><td colspan=${columns.length} class="table-empty-cell">No matching rows.</td></tr>` : displayRows.map(
272
+ (row) => html`
273
+ <tr>
274
+ ${row.map((cell) => html`<td>${cellString(cell)}</td>`)}
275
+ </tr>
276
+ `
277
+ )}
278
+ </tbody>
279
+ </table>
280
+ </div>
281
+ `;
282
+ }
283
+ };
284
+ LyraDataTable.PAGE_SIZE_OPTIONS = [10, 25, 50, 100];
285
+ LyraDataTable.styles = css`
286
+ :host {
287
+ display: flex;
288
+ flex-direction: column;
289
+ height: 100%;
290
+ min-height: 0;
291
+ }
292
+ .table-empty {
293
+ flex: 1;
294
+ display: flex;
295
+ align-items: center;
296
+ justify-content: center;
297
+ padding: 1rem;
298
+ }
299
+ .table-toolbar {
300
+ flex: none;
301
+ display: flex;
302
+ align-items: center;
303
+ gap: 0.75rem;
304
+ padding: 0.25rem 0;
305
+ flex-wrap: wrap;
306
+ }
307
+ .filter-input {
308
+ max-width: 280px;
309
+ }
310
+ .paging-controls {
311
+ display: flex;
312
+ align-items: center;
313
+ gap: 0.5rem;
314
+ margin-left: auto;
315
+ }
316
+ .page-size-select {
317
+ }
318
+ .paging-summary {
319
+ font-size: 0.8125rem;
320
+ color: var(--wa-color-text-quiet);
321
+ min-width: 5rem;
322
+ }
323
+ .table-wrap {
324
+ flex: 1;
325
+ min-height: 0;
326
+ overflow: auto;
327
+ border: 1px solid var(--wa-color-neutral-border-quiet);
328
+ border-radius: var(--wa-border-radius-medium, 0.25rem);
329
+ }
330
+ .result-table {
331
+ width: 100%;
332
+ border-collapse: collapse;
333
+ font-size: 0.875rem;
334
+ color: var(--wa-color-text-normal);
335
+ }
336
+ .result-table th,
337
+ .result-table td {
338
+ padding: 0.5rem 0.75rem;
339
+ text-align: left;
340
+ border-bottom: 1px solid var(--wa-color-neutral-border-quiet);
341
+ }
342
+ .result-table th {
343
+ position: sticky;
344
+ top: 0;
345
+ z-index: 1;
346
+ background: var(--wa-color-surface-lowered);
347
+ font-weight: 600;
348
+ white-space: nowrap;
349
+ color: var(--wa-color-text-normal);
350
+ box-shadow: 0 1px 0 0 var(--wa-color-neutral-border-quiet);
351
+ }
352
+ .result-table tbody tr:nth-child(even) td {
353
+ background: var(--wa-color-surface-default);
354
+ }
355
+ .result-table tbody tr:nth-child(odd) td {
356
+ background: var(--wa-color-surface-lowered);
357
+ }
358
+ .result-table tbody tr:hover td {
359
+ background: var(--wa-color-neutral-fill-normal);
360
+ }
361
+ .th-sort {
362
+ display: inline-flex;
363
+ align-items: center;
364
+ gap: 0.35rem;
365
+ width: 100%;
366
+ padding: 0;
367
+ border: none;
368
+ background: none;
369
+ font: inherit;
370
+ cursor: pointer;
371
+ color: inherit;
372
+ text-align: left;
373
+ }
374
+ .th-sort:hover {
375
+ opacity: 0.85;
376
+ }
377
+ .th-label {
378
+ overflow: hidden;
379
+ text-overflow: ellipsis;
380
+ }
381
+ .th-sort wa-icon {
382
+ flex-shrink: 0;
383
+ opacity: 0.7;
384
+ font-size: 0.75em;
385
+ }
386
+ .table-empty-cell {
387
+ color: var(--wa-color-text-quiet);
388
+ font-style: italic;
389
+ text-align: center;
390
+ }
391
+ `;
392
+ __decorateClass$1([
393
+ property({ attribute: false })
394
+ ], LyraDataTable.prototype, "data", 2);
395
+ __decorateClass$1([
396
+ property({ type: String })
397
+ ], LyraDataTable.prototype, "emptyMessage", 2);
398
+ __decorateClass$1([
399
+ state()
400
+ ], LyraDataTable.prototype, "sortColumnIndex", 2);
401
+ __decorateClass$1([
402
+ state()
403
+ ], LyraDataTable.prototype, "sortDirection", 2);
404
+ __decorateClass$1([
405
+ state()
406
+ ], LyraDataTable.prototype, "filterQuery", 2);
407
+ __decorateClass$1([
408
+ state()
409
+ ], LyraDataTable.prototype, "pageSize", 2);
410
+ __decorateClass$1([
411
+ state()
412
+ ], LyraDataTable.prototype, "currentPage", 2);
413
+ LyraDataTable = __decorateClass$1([
414
+ customElement("lyra-data-table")
415
+ ], LyraDataTable);
416
+ var __defProp = Object.defineProperty;
417
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
418
+ var __decorateClass = (decorators, target, key, kind) => {
419
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
420
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
421
+ if (decorator = decorators[i])
422
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
423
+ if (kind && result) __defProp(target, key, result);
424
+ return result;
425
+ };
426
+ let DataViewPart = class extends LyraPart {
427
+ constructor() {
428
+ super(...arguments);
429
+ this.dataview = null;
430
+ this.standalone = false;
431
+ this.persistedList = [];
432
+ this.selectedStorageKey = "";
433
+ this.selectedView = null;
434
+ this.loadingList = true;
435
+ this.autoActivateTab = true;
436
+ }
437
+ get displayed() {
438
+ return this.selectedView ?? this.dataview;
439
+ }
440
+ get hasData() {
441
+ const dv = this.displayed;
442
+ if (!dv) return false;
443
+ const { columns, rows } = dv.data;
444
+ return Array.isArray(columns) && Array.isArray(rows) && (columns.length > 0 || rows.length > 0);
445
+ }
446
+ toCsv(dv) {
447
+ const { columns, rows } = dv.data;
448
+ const escapeCell = (value) => {
449
+ if (value === null || value === void 0) return "";
450
+ const str = String(value);
451
+ if (!/[",\n]/.test(str)) return str;
452
+ return `"${str.replace(/"/g, '""')}"`;
453
+ };
454
+ const header = columns.map(escapeCell).join(",");
455
+ const body = rows.map((row) => row.map(escapeCell).join(",")).join("\n");
456
+ return body ? `${header}
457
+ ${body}` : header;
458
+ }
459
+ async onExportCsv() {
460
+ const dv = this.displayed;
461
+ if (!dv || !this.hasData) return;
462
+ try {
463
+ const csv = this.toCsv(dv);
464
+ const safeTitle = dv.title?.trim() || "dataview";
465
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
466
+ const fileName = `${safeTitle.replace(/[^a-zA-Z0-9-_]+/g, "_")}-${timestamp}.csv`;
467
+ const targetDir = await this.chooseExportDirectory();
468
+ if (!targetDir) return;
469
+ this.executeCommand("touch", {
470
+ path: `${targetDir}/${fileName}`,
471
+ contents: csv
472
+ });
473
+ } catch (err) {
474
+ toastError(err instanceof Error ? err.message : String(err));
475
+ }
476
+ }
477
+ async chooseExportDirectory() {
478
+ return filebrowserDialog("directory");
479
+ }
480
+ async doInitUI() {
481
+ const persisted = await this.getDialogSetting();
482
+ if (persisted && typeof persisted.autoActivateTab === "boolean") this.autoActivateTab = persisted.autoActivateTab;
483
+ this.subscribe(TOPIC_DATAVIEW_ADDED, async () => {
484
+ await this.refreshPersistedList(true);
485
+ if (this.autoActivateTab) this.activateContainingTab();
486
+ });
487
+ await this.refreshPersistedList(false);
488
+ }
489
+ async refreshPersistedList(selectLatest) {
490
+ this.loadingList = true;
491
+ this.requestUpdate();
492
+ try {
493
+ this.persistedList = await dataviewerService.listViews();
494
+ if (selectLatest && this.persistedList.length > 0) {
495
+ const latest = this.persistedList[this.persistedList.length - 1];
496
+ this.selectedStorageKey = latest.storageKey;
497
+ this.selectedView = await dataviewerService.getView(latest.storageKey);
498
+ } else if (this.selectedStorageKey) {
499
+ this.selectedView = await dataviewerService.getView(this.selectedStorageKey);
500
+ } else {
501
+ this.selectedView = null;
502
+ }
503
+ } catch (e) {
504
+ toastError(e instanceof Error ? e.message : String(e));
505
+ this.persistedList = [];
506
+ this.selectedView = null;
507
+ } finally {
508
+ this.loadingList = false;
509
+ this.requestUpdate();
510
+ this.updateToolbar();
511
+ }
512
+ }
513
+ async selectStorageKey(key) {
514
+ this.selectedStorageKey = key;
515
+ if (!key) {
516
+ this.selectedView = null;
517
+ this.requestUpdate();
518
+ this.updateToolbar();
519
+ return;
520
+ }
521
+ try {
522
+ this.selectedView = await dataviewerService.getView(key);
523
+ } catch (err) {
524
+ toastError(err instanceof Error ? err.message : String(err));
525
+ this.selectedView = null;
526
+ }
527
+ this.requestUpdate();
528
+ this.updateToolbar();
529
+ }
530
+ async onAutoActivateChange(e) {
531
+ const checked = e.target.checked;
532
+ this.autoActivateTab = checked;
533
+ const current = await this.getDialogSetting() ?? {};
534
+ await this.setDialogSetting({ ...current, autoActivateTab: checked });
535
+ this.updateToolbar();
536
+ }
537
+ async onHistorySelect(e) {
538
+ const value = e.detail?.item?.value ?? "";
539
+ if (!value || value === "__stats__") {
540
+ return;
541
+ }
542
+ await this.selectStorageKey(value);
543
+ }
544
+ async onDeleteView(e, storageKey) {
545
+ e.stopPropagation();
546
+ e.preventDefault();
547
+ try {
548
+ await dataviewerService.deleteView(storageKey);
549
+ const deletedWasSelected = this.selectedStorageKey === storageKey;
550
+ if (deletedWasSelected) {
551
+ this.selectedStorageKey = "";
552
+ this.selectedView = null;
553
+ }
554
+ await this.refreshPersistedList(true);
555
+ } catch (err) {
556
+ toastError(err instanceof Error ? err.message : String(err));
557
+ }
558
+ }
559
+ async onClearHistory() {
560
+ try {
561
+ await dataviewerService.clearAllViews();
562
+ this.selectedStorageKey = "";
563
+ this.selectedView = null;
564
+ await this.refreshPersistedList(false);
565
+ } catch (err) {
566
+ toastError(err instanceof Error ? err.message : String(err));
567
+ }
568
+ }
569
+ renderToolbar() {
570
+ if (this.standalone) return html``;
571
+ const current = this.selectedView ?? this.dataview;
572
+ const selectedMeta = this.persistedList.find((e) => e.storageKey === this.selectedStorageKey);
573
+ const baseTitle = selectedMeta?.title ?? current?.title ?? (this.persistedList.length > 0 ? "Latest data view" : "No data");
574
+ const formattedCreatedAt = selectedMeta?.createdAt ?? current?.createdAt ? new Date(selectedMeta?.createdAt ?? current?.createdAt).toLocaleString() : null;
575
+ const engineLabel = current?.source ?? null;
576
+ const titleWithEngine = engineLabel ? `${baseTitle} · ${engineLabel}` : baseTitle;
577
+ const currentLabel = formattedCreatedAt ? `${titleWithEngine} (${formattedCreatedAt})` : titleWithEngine;
578
+ return html`
579
+ <wa-dropdown
580
+ placement="bottom-start"
581
+ distance="4"
582
+ size="small"
583
+ hoist
584
+ @wa-select=${(e) => this.onHistorySelect(e)}
585
+ >
586
+ <wa-button
587
+ slot="trigger"
588
+ appearance="plain"
589
+ size="small"
590
+ with-caret
591
+ title="Data view history"
592
+ >
593
+ <wa-icon name="clock-rotate-left" label="History"></wa-icon>
594
+ </wa-button>
595
+
596
+ <wa-dropdown-item value="__stats__" disabled>
597
+ ${this.persistedList.length} data view${this.persistedList.length === 1 ? "" : "s"}
598
+ ${this.persistedList.length > 0 ? html`
599
+ <wa-button
600
+ slot="details"
601
+ appearance="plain"
602
+ size="small"
603
+ title="Clear history"
604
+ @click=${() => this.onClearHistory()}
605
+ >
606
+ <wa-icon name="trash" label="Clear history"></wa-icon>
607
+ </wa-button>
608
+ ` : null}
609
+ </wa-dropdown-item>
610
+
611
+ ${this.persistedList.map(
612
+ (entry) => html`
613
+ <wa-dropdown-item value=${entry.storageKey}>
614
+ ${entry.source ? `${entry.title} · ${entry.source}` : entry.title}
615
+ ${entry.createdAt ? html`<span style="opacity: 0.7; margin-left: 0.5rem; font-size: 0.75em;">
616
+ (${new Date(entry.createdAt).toLocaleString()})
617
+ </span>` : null}
618
+ <wa-button
619
+ slot="details"
620
+ appearance="plain"
621
+ size="small"
622
+ title="Delete data view"
623
+ @click=${(e) => this.onDeleteView(e, entry.storageKey)}
624
+ >
625
+ <wa-icon name="trash" label="Delete"></wa-icon>
626
+ </wa-button>
627
+ </wa-dropdown-item>
628
+ `
629
+ )}
630
+
631
+ </wa-dropdown>
632
+
633
+ <wa-divider orientation="vertical"></wa-divider>
634
+
635
+ <wa-button
636
+ size="small"
637
+ appearance="plain"
638
+ title="Export current data view to CSV"
639
+ ?disabled=${!this.hasData}
640
+ @click=${() => this.onExportCsv()}
641
+ >
642
+ <wa-icon name="file-csv" label="Export CSV"></wa-icon>
643
+ </wa-button>
644
+
645
+ <wa-switch
646
+ ?checked=${this.autoActivateTab}
647
+ size="small"
648
+ title="Switch to this tab when new results arrive"
649
+ @change=${(e) => this.onAutoActivateChange(e)}
650
+ style="margin-top: 0.5rem;"
651
+ >
652
+ Auto-show
653
+ </wa-switch>
654
+
655
+ ${when(current, () => html`<wa-divider orientation="vertical"></wa-divider><span>${currentLabel}</span>`)}
656
+ `;
657
+ }
658
+ renderTable(dv) {
659
+ if (!this.hasData) {
660
+ return html`<div class="result-empty">No data.</div>`;
661
+ }
662
+ return html`<lyra-data-table .data=${dv.data}></lyra-data-table>`;
663
+ }
664
+ render() {
665
+ const dv = this.displayed;
666
+ if (dv != null) return this.renderTable(dv);
667
+ return html`<div class="result-empty">No data.</div>`;
668
+ }
669
+ };
670
+ DataViewPart.styles = css`
671
+ :host {
672
+ display: flex;
673
+ flex-direction: column;
674
+ height: 100%;
675
+ }
676
+ .result-empty {
677
+ flex: 1;
678
+ display: flex;
679
+ align-items: center;
680
+ justify-content: center;
681
+ padding: 1rem;
682
+ }
683
+ `;
684
+ __decorateClass([
685
+ property({ attribute: false })
686
+ ], DataViewPart.prototype, "dataview", 2);
687
+ __decorateClass([
688
+ property({ type: Boolean })
689
+ ], DataViewPart.prototype, "standalone", 2);
690
+ __decorateClass([
691
+ state()
692
+ ], DataViewPart.prototype, "persistedList", 2);
693
+ __decorateClass([
694
+ state()
695
+ ], DataViewPart.prototype, "selectedStorageKey", 2);
696
+ __decorateClass([
697
+ state()
698
+ ], DataViewPart.prototype, "selectedView", 2);
699
+ __decorateClass([
700
+ state()
701
+ ], DataViewPart.prototype, "loadingList", 2);
702
+ __decorateClass([
703
+ state()
704
+ ], DataViewPart.prototype, "autoActivateTab", 2);
705
+ DataViewPart = __decorateClass([
706
+ customElement("lyra-dataview")
707
+ ], DataViewPart);
708
+ function parseCsv(text) {
709
+ const result = Papa.parse(text, {
710
+ header: true,
711
+ skipEmptyLines: true
712
+ });
713
+ const columns = result.meta.fields ?? [];
714
+ const rows = result.data.map(
715
+ (row) => columns.map((col) => row[col])
716
+ );
717
+ return { columns, rows };
718
+ }
719
+ dataviewerService.init();
720
+ rootContext.put("dataviewerService", dataviewerService);
721
+ contributionRegistry.registerContribution(PANEL_BOTTOM, {
722
+ name: "view.dataviewer",
723
+ label: "Data Views",
724
+ icon: "table",
725
+ component: (id) => html`<lyra-dataview id="${id}"></lyra-dataview>`
726
+ });
727
+ editorRegistry.registerEditorInputHandler({
728
+ editorId: "system.dataviewer-table",
729
+ label: "Table",
730
+ icon: "table",
731
+ ranking: 800,
732
+ canHandle: (input) => {
733
+ if (!(input instanceof File)) return false;
734
+ const lower = input.getName().toLowerCase();
735
+ return lower.endsWith(".csv") || lower.endsWith(".tsv");
736
+ },
737
+ handle: async (input) => {
738
+ const name = input.getName();
739
+ const text = await input.getContents();
740
+ const { columns, rows } = parseCsv(text ?? "");
741
+ const dataView = { title: name, data: { columns, rows } };
742
+ const editorInput = {
743
+ title: name,
744
+ data: dataView,
745
+ key: name,
746
+ icon: "table",
747
+ noOverflow: false,
748
+ state: {},
749
+ component: () => html`<lyra-dataview .dataview=${dataView} .standalone=${true}></lyra-dataview>`
750
+ };
751
+ return editorInput;
752
+ }
753
+ });
754
+ function dataviewerExtension() {
755
+ }
756
+ export {
757
+ dataviewerExtension as default
758
+ };
759
+ //# sourceMappingURL=dataviewer-extension-DhaSMapU.js.map