juxscript 1.1.228 → 1.1.230

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,60 @@
1
+ import { TabularDriver } from '../../storage/TabularDriver.js';
2
+ import { DataFrame } from '../../storage/DataFrame.js';
3
+ export interface ImportSettingsCallbacks {
4
+ onReimport: (df: DataFrame | Record<string, DataFrame>, sourceName: string) => void;
5
+ onError: (message: string) => void;
6
+ onStatusUpdate: (text: string, type: 'loading' | 'success' | 'error') => void;
7
+ }
8
+ export interface SettingsModalCallbacks {
9
+ onClear: () => Promise<void>;
10
+ onAdjustImport: () => void;
11
+ }
12
+ export interface SettingsModalData {
13
+ fileName: string;
14
+ fileSize?: number;
15
+ rowCount: number;
16
+ colCount: number;
17
+ isMalformed: boolean;
18
+ hasRawFileData: boolean;
19
+ }
20
+ export interface RawFileData {
21
+ file: File;
22
+ text?: string;
23
+ isExcel?: boolean;
24
+ }
25
+ export declare class ImportSettingsModal {
26
+ private _id;
27
+ private _driver;
28
+ private _reshapeModal;
29
+ private _reshapeModalRendered;
30
+ private _settingsModal;
31
+ private _modal;
32
+ private _modalRendered;
33
+ private _maxSheetSize;
34
+ private _sheetChunkSize;
35
+ constructor(id: string, driver: TabularDriver, options?: {
36
+ maxSheetSize?: number;
37
+ sheetChunkSize?: number;
38
+ });
39
+ /**
40
+ * Show the data settings modal with file info and options
41
+ */
42
+ showSettings(data: SettingsModalData, callbacks: SettingsModalCallbacks): void;
43
+ /**
44
+ * Close the settings modal if open
45
+ */
46
+ closeSettings(): void;
47
+ /**
48
+ * Show the appropriate reshape modal based on file type
49
+ */
50
+ showImportSettings(rawFileData: RawFileData, callbacks: ImportSettingsCallbacks): Promise<void>;
51
+ /**
52
+ * Cleanup any existing modals
53
+ */
54
+ cleanup(): void;
55
+ private _escapeHtml;
56
+ private _buildClickablePreviewHTML;
57
+ private _showExcelModal;
58
+ private _showCSVModal;
59
+ }
60
+ //# sourceMappingURL=ImportSettingsModal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImportSettingsModal.d.ts","sourceRoot":"","sources":["ImportSettingsModal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,MAAM,WAAW,uBAAuB;IACpC,UAAU,EAAE,CAAC,EAAE,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IACpF,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,KAAK,IAAI,CAAC;CACjF;AAED,MAAM,WAAW,sBAAsB;IACnC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,cAAc,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,qBAAqB,CAAkB;IAC/C,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,eAAe,CAAS;gBAG5B,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,aAAa,EACrB,OAAO,GAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAO;IAYpE;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,iBAAiB,EAAE,SAAS,EAAE,sBAAsB,GAAG,IAAI;IA6E9E;;OAEG;IACH,aAAa,IAAI,IAAI;IAUrB;;OAEG;IACG,kBAAkB,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IAUrG;;OAEG;IACH,OAAO,IAAI,IAAI;IAUf,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,0BAA0B;YAwDpB,eAAe;IAiI7B,OAAO,CAAC,aAAa;CAoKxB"}
@@ -0,0 +1,442 @@
1
+ import { Modal } from '../modal.js';
2
+ export class ImportSettingsModal {
3
+ constructor(id, driver, options = {}) {
4
+ this._reshapeModal = null;
5
+ this._reshapeModalRendered = false;
6
+ this._settingsModal = null;
7
+ this._modal = null;
8
+ this._modalRendered = false;
9
+ this._id = id;
10
+ this._driver = driver;
11
+ this._maxSheetSize = options.maxSheetSize ?? 100000;
12
+ this._sheetChunkSize = options.sheetChunkSize ?? 10000;
13
+ }
14
+ /* ═══════════════════════════════════════════════════
15
+ * SETTINGS MODAL (Overview)
16
+ * ═══════════════════════════════════════════════════ */
17
+ /**
18
+ * Show the data settings modal with file info and options
19
+ */
20
+ showSettings(data, callbacks) {
21
+ this.cleanup();
22
+ this._settingsModal = new Modal(`${this._id}-settings-modal`, {
23
+ title: 'Data Settings',
24
+ size: 'medium',
25
+ close: true,
26
+ backdropClose: true
27
+ });
28
+ const fileSizeKB = data.fileSize ? (data.fileSize / 1024).toFixed(1) : '0';
29
+ let contentHTML = `
30
+ <div class="jux-dataframe-settings-content">
31
+ <div class="jux-dataframe-settings-section">
32
+ <div class="jux-dataframe-settings-label">Source</div>
33
+ <div class="jux-dataframe-settings-value">
34
+ <strong>${this._escapeHtml(data.fileName)}</strong>
35
+ ${data.fileSize ? `<span class="jux-muted" style="margin-left: 8px;">${fileSizeKB} KB</span>` : ''}
36
+ </div>
37
+ </div>
38
+ <div class="jux-dataframe-settings-section">
39
+ <div class="jux-dataframe-settings-label">Data</div>
40
+ <div class="jux-dataframe-settings-value">
41
+ ${data.rowCount > 0 ? `${data.rowCount} rows × ${data.colCount} columns` : 'No data loaded'}
42
+ ${data.isMalformed ? '<span style="color: hsl(var(--warning)); margin-left: 8px;">⚠️ May need reformatting</span>' : ''}
43
+ </div>
44
+ </div>
45
+ `;
46
+ if (data.hasRawFileData) {
47
+ contentHTML += `
48
+ <div class="jux-dataframe-settings-section">
49
+ <div class="jux-dataframe-settings-label">Import</div>
50
+ <div class="jux-dataframe-settings-value">
51
+ <button id="${this._id}-adjust-import" class="jux-button jux-button-outline jux-button-sm">
52
+ ⚙️ Adjust Header Row / Delimiter
53
+ </button>
54
+ </div>
55
+ </div>
56
+ `;
57
+ }
58
+ contentHTML += `</div>`;
59
+ this._settingsModal
60
+ .content(contentHTML)
61
+ .actions([
62
+ {
63
+ label: 'Remove Data',
64
+ variant: 'secondary',
65
+ click: async () => {
66
+ await callbacks.onClear();
67
+ this._settingsModal.closeModal();
68
+ }
69
+ },
70
+ {
71
+ label: 'Done',
72
+ variant: 'primary',
73
+ click: () => this._settingsModal.closeModal()
74
+ }
75
+ ]);
76
+ this._settingsModal.render(document.body);
77
+ this._settingsModal.open();
78
+ requestAnimationFrame(() => {
79
+ const adjustBtn = document.getElementById(`${this._id}-adjust-import`);
80
+ if (adjustBtn) {
81
+ adjustBtn.addEventListener('click', () => {
82
+ this._settingsModal.closeModal();
83
+ callbacks.onAdjustImport();
84
+ });
85
+ }
86
+ });
87
+ }
88
+ /**
89
+ * Close the settings modal if open
90
+ */
91
+ closeSettings() {
92
+ if (this._settingsModal) {
93
+ this._settingsModal.closeModal();
94
+ }
95
+ }
96
+ /* ═══════════════════════════════════════════════════
97
+ * IMPORT/RESHAPE MODAL
98
+ * ═══════════════════════════════════════════════════ */
99
+ /**
100
+ * Show the appropriate reshape modal based on file type
101
+ */
102
+ async showImportSettings(rawFileData, callbacks) {
103
+ if (!rawFileData)
104
+ return;
105
+ if (rawFileData.isExcel) {
106
+ await this._showExcelModal(rawFileData, callbacks);
107
+ }
108
+ else {
109
+ this._showCSVModal(rawFileData, callbacks);
110
+ }
111
+ }
112
+ /**
113
+ * Cleanup any existing modals
114
+ */
115
+ cleanup() {
116
+ if (this._reshapeModal && this._reshapeModalRendered) {
117
+ const oldEl = document.getElementById(`${this._id}-reshape-modal`);
118
+ if (oldEl)
119
+ oldEl.remove();
120
+ this._reshapeModal = null;
121
+ this._reshapeModalRendered = false;
122
+ }
123
+ // Note: Don't close settings modal here - let it close itself
124
+ }
125
+ _escapeHtml(text) {
126
+ const div = document.createElement('div');
127
+ div.textContent = text;
128
+ return div.innerHTML;
129
+ }
130
+ _buildClickablePreviewHTML(rawRows, selectedSheetRow) {
131
+ let html = '<table style="width: 100%; border-collapse: collapse; font-size: 12px;">';
132
+ for (const { sheetRow, values } of rawRows) {
133
+ const isHeader = (sheetRow === selectedSheetRow);
134
+ const isSkipped = (sheetRow < selectedSheetRow);
135
+ let rowStyle = 'border-bottom: 1px solid hsl(var(--border)); cursor: pointer; transition: background 0.1s;';
136
+ if (isHeader) {
137
+ rowStyle += 'background: hsl(142 71% 45% / 0.15); font-weight: 600;';
138
+ }
139
+ else if (isSkipped) {
140
+ rowStyle += 'background: hsl(var(--muted) / 0.4); color: hsl(var(--muted-foreground)); font-style: italic; opacity: 0.7;';
141
+ }
142
+ html += `<tr data-sheet-row="${sheetRow}" style="${rowStyle}" onmouseover="this.style.outline='2px solid hsl(142 71% 45% / 0.5)'" onmouseout="this.style.outline=''">`;
143
+ html += `<td style="padding: 8px 12px; width: 60px; font-weight: 600; color: hsl(var(--muted-foreground)); border-right: 1px solid hsl(var(--border)); text-align: center; user-select: none;">`;
144
+ if (isHeader) {
145
+ html += `<span style="color: hsl(142 71% 45%);">▶ ${sheetRow}</span>`;
146
+ }
147
+ else {
148
+ html += `${sheetRow}`;
149
+ }
150
+ html += '</td>';
151
+ const displayCols = values.slice(0, 6);
152
+ displayCols.forEach(val => {
153
+ const displayVal = val != null ? String(val).substring(0, 20) : '';
154
+ const cellStyle = isHeader
155
+ ? 'padding: 8px 12px; font-weight: 600; color: hsl(var(--foreground));'
156
+ : 'padding: 8px 12px;';
157
+ html += `<td style="${cellStyle}">${this._escapeHtml(displayVal)}</td>`;
158
+ });
159
+ if (values.length > 6) {
160
+ html += `<td style="padding: 8px 12px; color: hsl(var(--muted-foreground));">…</td>`;
161
+ }
162
+ html += `<td style="padding: 8px 12px; text-align: right; white-space: nowrap; user-select: none;">`;
163
+ if (isHeader) {
164
+ html += '<span style="background: hsl(142 71% 45%); color: white; padding: 3px 8px; border-radius: 4px; font-size: 10px; font-weight: 600;">HEADER</span>';
165
+ }
166
+ else if (isSkipped) {
167
+ html += '<span style="color: hsl(var(--muted-foreground)); font-size: 10px;">skipped</span>';
168
+ }
169
+ else {
170
+ html += '<span style="color: hsl(var(--muted-foreground)); font-size: 10px;">data</span>';
171
+ }
172
+ html += '</td></tr>';
173
+ }
174
+ html += '</table>';
175
+ return html;
176
+ }
177
+ async _showExcelModal(rawFileData, callbacks) {
178
+ if (!rawFileData.file)
179
+ return;
180
+ this.cleanup();
181
+ const rawRows = await this._driver.readRawExcelRows(rawFileData.file, 15);
182
+ if (rawRows.length === 0)
183
+ return;
184
+ // Auto-detect best header row
185
+ let selectedSheetRow = rawRows[0].sheetRow;
186
+ for (const { sheetRow, values } of rawRows) {
187
+ const nonEmpty = values.filter(v => v !== null && v !== undefined && String(v).trim() !== '');
188
+ if (nonEmpty.length < values.length * 0.5)
189
+ continue;
190
+ const nonNumeric = nonEmpty.filter(v => {
191
+ const str = String(v).trim();
192
+ return isNaN(Number(str)) && str !== '';
193
+ }).length;
194
+ if (nonNumeric >= nonEmpty.length * 0.7) {
195
+ selectedSheetRow = sheetRow;
196
+ break;
197
+ }
198
+ }
199
+ this._modal = new Modal(`${this._id}-reshape-modal`, {
200
+ title: 'Excel Import Settings',
201
+ size: 'large',
202
+ close: true,
203
+ backdropClose: false
204
+ });
205
+ const modalContentHTML = `
206
+ <div style="margin-bottom: 1rem;">
207
+ <div id="${this._id}-reshape-hint" style="padding: 0.75rem; background: hsl(var(--muted) / 0.5); border-radius: var(--radius); font-size: 0.875rem;"></div>
208
+ <input type="hidden" id="${this._id}-header-row" value="${selectedSheetRow}" />
209
+ </div>
210
+ <div>
211
+ <div style="font-weight: 600; margin-bottom: 0.5rem; color: hsl(var(--foreground));">Click a row to select it as the header:</div>
212
+ <div id="${this._id}-preview" style="font-family: ui-monospace, monospace; font-size: 12px; background: hsl(var(--muted) / 0.3); border: 1px solid hsl(var(--border)); border-radius: var(--radius); padding: 0; overflow: hidden; max-height: 400px; overflow-y: auto;"></div>
213
+ </div>
214
+ `;
215
+ this._modal
216
+ .content(modalContentHTML)
217
+ .actions([
218
+ {
219
+ label: 'Cancel',
220
+ variant: 'secondary',
221
+ click: () => this._modal.closeModal()
222
+ },
223
+ {
224
+ label: 'Apply & Re-import',
225
+ variant: 'primary',
226
+ click: async () => {
227
+ const input = document.getElementById(`${this._id}-header-row`);
228
+ const headerRow = parseInt(input.value) || 0;
229
+ callbacks.onStatusUpdate('Re-parsing with new settings...', 'loading');
230
+ try {
231
+ const sheets = await this._driver.streamFileMultiSheet(rawFileData.file, {
232
+ headerRow,
233
+ maxSheetSize: this._maxSheetSize,
234
+ sheetChunkSize: this._sheetChunkSize
235
+ });
236
+ const sheetNames = Object.keys(sheets);
237
+ if (sheetNames.length === 0) {
238
+ callbacks.onError(`No data found with header at row ${headerRow}. Try a different row.`);
239
+ return;
240
+ }
241
+ await this._driver.store(rawFileData.file.name, sheets[sheetNames[0]], { source: rawFileData.file.name });
242
+ if (sheetNames.length > 1) {
243
+ callbacks.onReimport(sheets, rawFileData.file.name);
244
+ }
245
+ else {
246
+ callbacks.onReimport(sheets[sheetNames[0]], rawFileData.file.name);
247
+ }
248
+ this._modal.closeModal();
249
+ }
250
+ catch (err) {
251
+ callbacks.onError(`Error: ${err.message}`);
252
+ }
253
+ }
254
+ }
255
+ ]);
256
+ this._modal.render(document.body);
257
+ this._modalRendered = true;
258
+ await new Promise(resolve => requestAnimationFrame(resolve));
259
+ const previewDiv = document.getElementById(`${this._id}-preview`);
260
+ const hintDiv = document.getElementById(`${this._id}-reshape-hint`);
261
+ const hiddenInput = document.getElementById(`${this._id}-header-row`);
262
+ const updateHint = (row) => {
263
+ if (!hintDiv)
264
+ return;
265
+ const vals = rawRows.find(r => r.sheetRow === row)?.values ?? [];
266
+ const headerNames = vals.filter((v) => v != null && String(v).trim() !== '').map((v) => String(v).trim());
267
+ const preview = headerNames.slice(0, 4).join(', ') + (headerNames.length > 4 ? '…' : '');
268
+ if (row > rawRows[0].sheetRow) {
269
+ hintDiv.innerHTML = `Sheet row <strong>${row}</strong> selected as header. Columns: <code>${this._escapeHtml(preview)}</code>. Rows before it will be skipped.`;
270
+ }
271
+ else {
272
+ hintDiv.innerHTML = `Sheet row <strong>${row}</strong> (first row) selected as header. Columns: <code>${this._escapeHtml(preview)}</code>`;
273
+ }
274
+ };
275
+ const renderPreview = (selected) => {
276
+ if (!previewDiv)
277
+ return;
278
+ previewDiv.innerHTML = this._buildClickablePreviewHTML(rawRows, selected);
279
+ previewDiv.querySelectorAll('tr[data-sheet-row]').forEach(tr => {
280
+ tr.addEventListener('click', () => {
281
+ const rowIdx = parseInt(tr.dataset.sheetRow);
282
+ hiddenInput.value = String(rowIdx);
283
+ updateHint(rowIdx);
284
+ renderPreview(rowIdx);
285
+ });
286
+ });
287
+ };
288
+ updateHint(selectedSheetRow);
289
+ renderPreview(selectedSheetRow);
290
+ this._modal.open();
291
+ }
292
+ _showCSVModal(rawFileData, callbacks) {
293
+ if (!rawFileData.text)
294
+ return;
295
+ this.cleanup();
296
+ const text = rawFileData.text;
297
+ const detected = this._driver._detectDelimiter(text);
298
+ const lines = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n').split('\n');
299
+ const rawRows = [];
300
+ const maxPreviewRows = Math.min(lines.length, 15);
301
+ for (let i = 0; i < maxPreviewRows; i++) {
302
+ if (!lines[i]) {
303
+ rawRows.push({ sheetRow: i, values: [''] });
304
+ continue;
305
+ }
306
+ const values = this._driver._parseLine(lines[i], detected);
307
+ rawRows.push({ sheetRow: i, values });
308
+ }
309
+ // Auto-detect header row
310
+ let selectedRow = 0;
311
+ for (const { sheetRow, values } of rawRows) {
312
+ const nonEmpty = values.filter((v) => v.trim() !== '');
313
+ if (nonEmpty.length < values.length * 0.5)
314
+ continue;
315
+ const nonNumeric = nonEmpty.filter((v) => {
316
+ const trimmed = v.trim();
317
+ return isNaN(Number(trimmed)) && trimmed !== '';
318
+ }).length;
319
+ if (nonNumeric >= nonEmpty.length * 0.7) {
320
+ selectedRow = sheetRow;
321
+ break;
322
+ }
323
+ }
324
+ this._modal = new Modal(`${this._id}-reshape-modal`, {
325
+ title: 'CSV Import Settings',
326
+ size: 'large',
327
+ close: true,
328
+ backdropClose: false
329
+ });
330
+ const modalContentHTML = `
331
+ <div style="margin-bottom: 1rem;">
332
+ <label style="display: block; font-weight: 600; margin-bottom: 0.5rem;">Delimiter</label>
333
+ <select id="${this._id}-delimiter" class="jux-input-element" style="width: 100%;">
334
+ <option value=",">Comma (,)</option>
335
+ <option value="|">Pipe (|)</option>
336
+ <option value="&#9;">Tab (\\t)</option>
337
+ <option value=";">Semicolon (;)</option>
338
+ </select>
339
+ </div>
340
+ <div style="margin-bottom: 1rem;">
341
+ <div id="${this._id}-reshape-hint" style="padding: 0.75rem; background: hsl(var(--muted) / 0.5); border-radius: var(--radius); font-size: 0.875rem;"></div>
342
+ <input type="hidden" id="${this._id}-header-row" value="${selectedRow}" />
343
+ </div>
344
+ <div>
345
+ <div style="font-weight: 600; margin-bottom: 0.5rem; color: hsl(var(--foreground));">Click a row to select it as the header:</div>
346
+ <div id="${this._id}-preview" style="font-family: monospace; font-size: 12px; background: hsl(var(--muted) / 0.3); border: 1px solid hsl(var(--border)); border-radius: var(--radius); padding: 0; overflow: hidden; max-height: 400px; overflow-y: auto;"></div>
347
+ </div>
348
+ `;
349
+ this._modal
350
+ .content(modalContentHTML)
351
+ .actions([
352
+ {
353
+ label: 'Cancel',
354
+ variant: 'secondary',
355
+ click: () => this._modal.closeModal()
356
+ },
357
+ {
358
+ label: 'Apply & Re-import',
359
+ variant: 'primary',
360
+ click: async () => {
361
+ const delimiterSelect = document.getElementById(`${this._id}-delimiter`);
362
+ const hiddenInput = document.getElementById(`${this._id}-header-row`);
363
+ const delim = delimiterSelect.value;
364
+ const headerRow = parseInt(hiddenInput.value) || 0;
365
+ callbacks.onStatusUpdate('Re-parsing with new settings...', 'loading');
366
+ try {
367
+ const df = this._driver.parseCSV(rawFileData.text, {
368
+ delimiter: delim,
369
+ headerRow,
370
+ hasHeader: true
371
+ });
372
+ await this._driver.store(rawFileData.file.name, df, { source: rawFileData.file.name });
373
+ callbacks.onReimport(df, rawFileData.file.name);
374
+ this._modal.closeModal();
375
+ }
376
+ catch (err) {
377
+ callbacks.onError(`Error: ${err.message}`);
378
+ }
379
+ }
380
+ }
381
+ ]);
382
+ this._modal.render(document.body);
383
+ this._modalRendered = true;
384
+ requestAnimationFrame(() => {
385
+ const delimiterSelect = document.getElementById(`${this._id}-delimiter`);
386
+ const previewDiv = document.getElementById(`${this._id}-preview`);
387
+ const hintDiv = document.getElementById(`${this._id}-reshape-hint`);
388
+ const hiddenInput = document.getElementById(`${this._id}-header-row`);
389
+ if (delimiterSelect)
390
+ delimiterSelect.value = detected;
391
+ const updateHint = (row) => {
392
+ if (!hintDiv)
393
+ return;
394
+ const vals = rawRows.find(r => r.sheetRow === row)?.values ?? [];
395
+ const headerNames = vals.filter((v) => v != null && String(v).trim() !== '').map((v) => String(v).trim());
396
+ const preview = headerNames.slice(0, 4).join(', ') + (headerNames.length > 4 ? '…' : '');
397
+ if (row > rawRows[0].sheetRow) {
398
+ hintDiv.innerHTML = `Sheet row <strong>${row}</strong> selected as header. Columns: <code>${this._escapeHtml(preview)}</code>. Rows before it will be skipped.`;
399
+ }
400
+ else {
401
+ hintDiv.innerHTML = `Sheet row <strong>${row}</strong> (first row) selected as header. Columns: <code>${this._escapeHtml(preview)}</code>`;
402
+ }
403
+ };
404
+ const reparse = () => {
405
+ const delim = delimiterSelect?.value || ',';
406
+ rawRows.length = 0;
407
+ for (let i = 0; i < maxPreviewRows; i++) {
408
+ if (!lines[i]) {
409
+ rawRows.push({ sheetRow: i, values: [''] });
410
+ continue;
411
+ }
412
+ const values = this._driver._parseLine(lines[i], delim);
413
+ rawRows.push({ sheetRow: i, values });
414
+ }
415
+ };
416
+ const renderPreview = (selected) => {
417
+ if (!previewDiv)
418
+ return;
419
+ previewDiv.innerHTML = this._buildClickablePreviewHTML(rawRows, selected);
420
+ previewDiv.querySelectorAll('tr[data-sheet-row]').forEach(tr => {
421
+ tr.addEventListener('click', () => {
422
+ const rowIdx = parseInt(tr.dataset.sheetRow);
423
+ hiddenInput.value = String(rowIdx);
424
+ updateHint(rowIdx);
425
+ renderPreview(rowIdx);
426
+ });
427
+ });
428
+ };
429
+ if (delimiterSelect) {
430
+ delimiterSelect.addEventListener('change', () => {
431
+ reparse();
432
+ const current = parseInt(hiddenInput.value) || 0;
433
+ updateHint(current);
434
+ renderPreview(current);
435
+ });
436
+ }
437
+ updateHint(selectedRow);
438
+ renderPreview(selectedRow);
439
+ this._modal.open();
440
+ });
441
+ }
442
+ }