|
156 | 156 | const actionsRect = actionsCell.getBoundingClientRect();
|
157 | 157 | const left = Math.round(idRect.right - containerRect.left);
|
158 | 158 | const actionsLeft = actionsRect.left - containerRect.left;
|
159 |
| - const width = Math.min( |
160 |
| - customColumns.length * 180, // estimated minimum placeholder width |
161 |
| - actionsLeft - left // don't exceed actions column |
162 |
| - ); |
| 159 | +
|
| 160 | + const width = actionsLeft - left; |
163 | 161 |
|
164 | 162 | spreadsheetContainer.style.setProperty('--group-left', `${left - 2}px`);
|
165 | 163 | spreadsheetContainer.style.setProperty('--group-width', `${width + 2}px`);
|
|
219 | 217 |
|
220 | 218 | const left = Math.round(startLeft - containerRect.left);
|
221 | 219 |
|
222 |
| - // maximum possible width of all custom columns |
223 |
| - const totalFullWidth = customColumns.reduce( |
224 |
| - (total, col) => total + getColumnWidth(col.key), |
225 |
| - 0 |
226 |
| - ); |
227 |
| -
|
228 | 220 | // get the actions column and use its left border as the boundary
|
229 | 221 | const actionsCell = headerElement!.querySelector<HTMLElement>(
|
230 | 222 | '[role="cell"][data-column-id="actions"]'
|
231 | 223 | );
|
232 |
| - const rawVisibleWidth = Math.round(visibleRight - idRect.right); |
233 |
| - let maxAllowedWidth = rawVisibleWidth; |
234 | 224 |
|
235 |
| - if (actionsCell) { |
236 |
| - const actionsRect = actionsCell.getBoundingClientRect(); |
237 |
| - const actionsLeft = actionsRect.left - containerRect.left; |
238 |
| - maxAllowedWidth = Math.min(rawVisibleWidth, actionsLeft - left); |
| 225 | + if (!actionsCell) { |
| 226 | + if (rangeOverlayEl) { |
| 227 | + rangeOverlayEl.style.display = 'none'; |
| 228 | + } |
| 229 | + return; |
239 | 230 | }
|
240 | 231 |
|
241 |
| - // Set overlay width to not exceed actions column boundary |
242 |
| - const width = Math.min(totalFullWidth, maxAllowedWidth); |
| 232 | + const actionsRect = actionsCell.getBoundingClientRect(); |
| 233 | + const actionsLeft = actionsRect.left - containerRect.left; |
| 234 | +
|
| 235 | + const width = actionsLeft - left; |
243 | 236 |
|
244 | 237 | // Apply overlay positioning
|
245 | 238 | spreadsheetContainer.style.setProperty('--group-left', `${left - 2}px`);
|
|
338 | 331 | });
|
339 | 332 | });
|
340 | 333 |
|
341 |
| - const getRowColumns = (): Column[] => [ |
342 |
| - { |
343 |
| - id: '$id', |
344 |
| - title: '$id', |
345 |
| - type: 'string', |
346 |
| - width: 180, |
347 |
| - icon: IconFingerPrint, |
348 |
| - ...baseColProps |
349 |
| - }, |
350 |
| - ...customSuggestedColumns, |
351 |
| - { |
352 |
| - id: 'actions', |
353 |
| - title: '', |
354 |
| - type: 'string' as Column['type'], |
355 |
| - width: 40, |
356 |
| - isAction: true, |
357 |
| - ...baseColProps |
358 |
| - } |
359 |
| - ]; |
| 334 | + const getRowColumns = (): Column[] => { |
| 335 | + const minColumnWidth = 180; |
| 336 | + const fixedWidths = { id: minColumnWidth, actions: 40, selection: 40 }; |
| 337 | +
|
| 338 | + // calculate base widths and total |
| 339 | + const columnsWithBase = customSuggestedColumns.map((col) => ({ |
| 340 | + ...col, |
| 341 | + baseWidth: Math.max(minColumnWidth, getColumnWidth(col.id)) |
| 342 | + })); |
| 343 | +
|
| 344 | + const totalUsed = |
| 345 | + fixedWidths.id + |
| 346 | + fixedWidths.actions + |
| 347 | + fixedWidths.selection + |
| 348 | + columnsWithBase.reduce((sum, col) => sum + col.baseWidth, 0); |
| 349 | +
|
| 350 | + // distribute excess space equally across custom columns |
| 351 | + const viewportWidth = |
| 352 | + spreadsheetContainer?.clientWidth || |
| 353 | + (typeof window !== 'undefined' ? window.innerWidth : totalUsed); |
| 354 | +
|
| 355 | + const extraPerColumn = |
| 356 | + Math.max(0, viewportWidth - totalUsed) / (columnsWithBase.length || 1); |
| 357 | +
|
| 358 | + const finalCustomColumns = columnsWithBase.map((col) => ({ |
| 359 | + ...col, |
| 360 | + width: { min: col.baseWidth + extraPerColumn } |
| 361 | + })); |
| 362 | +
|
| 363 | + return [ |
| 364 | + { |
| 365 | + id: '$id', |
| 366 | + title: '$id', |
| 367 | + type: 'string', |
| 368 | + width: fixedWidths.id, |
| 369 | + icon: IconFingerPrint, |
| 370 | + ...baseColProps |
| 371 | + }, |
| 372 | + ...finalCustomColumns, |
| 373 | + { |
| 374 | + id: 'actions', |
| 375 | + title: '', |
| 376 | + type: 'string' as Column['type'], |
| 377 | + width: fixedWidths.actions, |
| 378 | + isAction: true, |
| 379 | + ...baseColProps |
| 380 | + } |
| 381 | + ]; |
| 382 | + }; |
360 | 383 |
|
361 | 384 | // Handle browser back/forward navigation
|
362 | 385 | const handleBeforeUnload = (event: BeforeUnloadEvent) => {
|
|
0 commit comments