Remove concept of rendered columns from grid and instead render all columns
This commit is contained in:
parent
5e8e4add4a
commit
4e703fdfcc
|
@ -17,7 +17,7 @@
|
||||||
isResizing,
|
isResizing,
|
||||||
rand,
|
rand,
|
||||||
sort,
|
sort,
|
||||||
renderedColumns,
|
visibleColumns,
|
||||||
dispatch,
|
dispatch,
|
||||||
subscribe,
|
subscribe,
|
||||||
config,
|
config,
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
|
|
||||||
$: sortedBy = column.name === $sort.column
|
$: sortedBy = column.name === $sort.column
|
||||||
$: canMoveLeft = orderable && idx > 0
|
$: canMoveLeft = orderable && idx > 0
|
||||||
$: canMoveRight = orderable && idx < $renderedColumns.length - 1
|
$: canMoveRight = orderable && idx < $visibleColumns.length - 1
|
||||||
$: sortingLabels = getSortingLabels(column.schema?.type)
|
$: sortingLabels = getSortingLabels(column.schema?.type)
|
||||||
$: searchable = isColumnSearchable(column)
|
$: searchable = isColumnSearchable(column)
|
||||||
$: resetSearchValue(column.name)
|
$: resetSearchValue(column.name)
|
||||||
|
|
|
@ -444,6 +444,13 @@
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.remove {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.remove.visible {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
.add {
|
.add {
|
||||||
background: var(--spectrum-global-color-gray-200);
|
background: var(--spectrum-global-color-gray-200);
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
const {
|
const {
|
||||||
bounds,
|
bounds,
|
||||||
renderedRows,
|
renderedRows,
|
||||||
renderedColumns,
|
visibleColumns,
|
||||||
rowVerticalInversionIndex,
|
rowVerticalInversionIndex,
|
||||||
hoveredRowId,
|
hoveredRowId,
|
||||||
dispatch,
|
dispatch,
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
let body
|
let body
|
||||||
|
|
||||||
$: renderColumnsWidth = $renderedColumns.reduce(
|
$: columnsWidth = $visibleColumns.reduce(
|
||||||
(total, col) => (total += col.width),
|
(total, col) => (total += col.width),
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
<div
|
<div
|
||||||
class="blank"
|
class="blank"
|
||||||
class:highlighted={$hoveredRowId === BlankRowID}
|
class:highlighted={$hoveredRowId === BlankRowID}
|
||||||
style="width:{renderColumnsWidth}px"
|
style="width:{columnsWidth}px"
|
||||||
on:mouseenter={$isDragging ? null : () => ($hoveredRowId = BlankRowID)}
|
on:mouseenter={$isDragging ? null : () => ($hoveredRowId = BlankRowID)}
|
||||||
on:mouseleave={$isDragging ? null : () => ($hoveredRowId = null)}
|
on:mouseleave={$isDragging ? null : () => ($hoveredRowId = null)}
|
||||||
on:click={() => dispatch("add-row-inline")}
|
on:click={() => dispatch("add-row-inline")}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
focusedCellId,
|
focusedCellId,
|
||||||
reorder,
|
reorder,
|
||||||
selectedRows,
|
selectedRows,
|
||||||
renderedColumns,
|
visibleColumns,
|
||||||
hoveredRowId,
|
hoveredRowId,
|
||||||
selectedCellMap,
|
selectedCellMap,
|
||||||
focusedRow,
|
focusedRow,
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
on:mouseleave={$isDragging ? null : () => ($hoveredRowId = null)}
|
on:mouseleave={$isDragging ? null : () => ($hoveredRowId = null)}
|
||||||
on:click={() => dispatch("rowclick", rows.actions.cleanRow(row))}
|
on:click={() => dispatch("rowclick", rows.actions.cleanRow(row))}
|
||||||
>
|
>
|
||||||
{#each $renderedColumns as column, columnIdx (column.name)}
|
{#each $visibleColumns as column, columnIdx}
|
||||||
{@const cellId = `${row._id}-${column.name}`}
|
{@const cellId = `${row._id}-${column.name}`}
|
||||||
<DataCell
|
<DataCell
|
||||||
{cellId}
|
{cellId}
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
maxScrollLeft,
|
maxScrollLeft,
|
||||||
bounds,
|
bounds,
|
||||||
hoveredRowId,
|
hoveredRowId,
|
||||||
hiddenColumnsWidth,
|
|
||||||
menu,
|
menu,
|
||||||
} = getContext("grid")
|
} = getContext("grid")
|
||||||
|
|
||||||
|
@ -23,10 +22,10 @@
|
||||||
let initialTouchX
|
let initialTouchX
|
||||||
let initialTouchY
|
let initialTouchY
|
||||||
|
|
||||||
$: style = generateStyle($scroll, $rowHeight, $hiddenColumnsWidth)
|
$: style = generateStyle($scroll, $rowHeight)
|
||||||
|
|
||||||
const generateStyle = (scroll, rowHeight, hiddenWidths) => {
|
const generateStyle = (scroll, rowHeight) => {
|
||||||
const offsetX = scrollHorizontally ? -1 * scroll.left + hiddenWidths : 0
|
const offsetX = scrollHorizontally ? -1 * scroll.left : 0
|
||||||
const offsetY = scrollVertically ? -1 * (scroll.top % rowHeight) : 0
|
const offsetY = scrollVertically ? -1 * (scroll.top % rowHeight) : 0
|
||||||
return `transform: translate3d(${offsetX}px, ${offsetY}px, 0);`
|
return `transform: translate3d(${offsetX}px, ${offsetY}px, 0);`
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,14 @@
|
||||||
import HeaderCell from "../cells/HeaderCell.svelte"
|
import HeaderCell from "../cells/HeaderCell.svelte"
|
||||||
import { TempTooltip, TooltipType } from "@budibase/bbui"
|
import { TempTooltip, TooltipType } from "@budibase/bbui"
|
||||||
|
|
||||||
const { renderedColumns, config, hasNonAutoColumn, datasource, loading } =
|
const { visibleColumns, config, hasNonAutoColumn, datasource, loading } =
|
||||||
getContext("grid")
|
getContext("grid")
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<GridScrollWrapper scrollHorizontally>
|
<GridScrollWrapper scrollHorizontally>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{#each $renderedColumns as column, idx}
|
{#each $visibleColumns as column, idx}
|
||||||
<HeaderCell {column} {idx}>
|
<HeaderCell {column} {idx}>
|
||||||
<slot name="edit-column" />
|
<slot name="edit-column" />
|
||||||
</HeaderCell>
|
</HeaderCell>
|
||||||
|
|
|
@ -2,17 +2,16 @@
|
||||||
import { getContext, onMount } from "svelte"
|
import { getContext, onMount } from "svelte"
|
||||||
import { Icon, Popover, clickOutside } from "@budibase/bbui"
|
import { Icon, Popover, clickOutside } from "@budibase/bbui"
|
||||||
|
|
||||||
const { renderedColumns, scroll, hiddenColumnsWidth, width, subscribe } =
|
const { visibleColumns, scroll, width, subscribe } = getContext("grid")
|
||||||
getContext("grid")
|
|
||||||
|
|
||||||
let anchor
|
let anchor
|
||||||
let open = false
|
let open = false
|
||||||
|
|
||||||
$: columnsWidth = $renderedColumns.reduce(
|
$: columnsWidth = $visibleColumns.reduce(
|
||||||
(total, col) => (total += col.width),
|
(total, col) => (total += col.width),
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
$: end = $hiddenColumnsWidth + columnsWidth - 1 - $scroll.left
|
$: end = columnsWidth - 1 - $scroll.left
|
||||||
$: left = Math.min($width - 40, end)
|
$: left = Math.min($width - 40, end)
|
||||||
|
|
||||||
const close = () => {
|
const close = () => {
|
||||||
|
@ -34,7 +33,7 @@
|
||||||
<Popover
|
<Popover
|
||||||
bind:open
|
bind:open
|
||||||
{anchor}
|
{anchor}
|
||||||
align={$renderedColumns.length ? "right" : "left"}
|
align={$visibleColumns.length ? "right" : "left"}
|
||||||
offset={0}
|
offset={0}
|
||||||
popoverTarget={document.getElementById(`add-column-button`)}
|
popoverTarget={document.getElementById(`add-column-button`)}
|
||||||
customZindex={100}
|
customZindex={100}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
datasource,
|
datasource,
|
||||||
subscribe,
|
subscribe,
|
||||||
renderedRows,
|
renderedRows,
|
||||||
renderedColumns,
|
visibleColumns,
|
||||||
rowHeight,
|
rowHeight,
|
||||||
hasNextPage,
|
hasNextPage,
|
||||||
maxScrollTop,
|
maxScrollTop,
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
let newRow = { _isNewRow: true }
|
let newRow = { _isNewRow: true }
|
||||||
let offset = 0
|
let offset = 0
|
||||||
|
|
||||||
$: firstColumn = $stickyColumn || $renderedColumns[0]
|
$: firstColumn = $stickyColumn || $visibleColumns[0]
|
||||||
$: width = GutterWidth + ($stickyColumn?.width || 0)
|
$: width = GutterWidth + ($stickyColumn?.width || 0)
|
||||||
$: $datasource, (visible = false)
|
$: $datasource, (visible = false)
|
||||||
$: invertY = shouldInvertY(offset, $rowVerticalInversionIndex, $renderedRows)
|
$: invertY = shouldInvertY(offset, $rowVerticalInversionIndex, $renderedRows)
|
||||||
|
@ -211,9 +211,8 @@
|
||||||
<div class="normal-columns" transition:fade|local={{ duration: 130 }}>
|
<div class="normal-columns" transition:fade|local={{ duration: 130 }}>
|
||||||
<GridScrollWrapper scrollHorizontally attachHandlers>
|
<GridScrollWrapper scrollHorizontally attachHandlers>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{#each $renderedColumns as column, columnIdx}
|
{#each $visibleColumns as column, columnIdx}
|
||||||
{@const cellId = `new-${column.name}`}
|
{@const cellId = `new-${column.name}`}
|
||||||
{#key cellId}
|
|
||||||
<DataCell
|
<DataCell
|
||||||
{cellId}
|
{cellId}
|
||||||
{column}
|
{column}
|
||||||
|
@ -233,7 +232,6 @@
|
||||||
<div in:fade={{ duration: 130 }} class="loading-overlay" />
|
<div in:fade={{ duration: 130 }} class="loading-overlay" />
|
||||||
{/if}
|
{/if}
|
||||||
</DataCell>
|
</DataCell>
|
||||||
{/key}
|
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</GridScrollWrapper>
|
</GridScrollWrapper>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import { GutterWidth } from "../lib/constants"
|
import { GutterWidth } from "../lib/constants"
|
||||||
|
|
||||||
const { resize, renderedColumns, stickyColumn, isReordering, scrollLeft } =
|
const { resize, visibleColumns, stickyColumn, isReordering, scrollLeft } =
|
||||||
getContext("grid")
|
getContext("grid")
|
||||||
|
|
||||||
$: offset = GutterWidth + ($stickyColumn?.width || 0)
|
$: offset = GutterWidth + ($stickyColumn?.width || 0)
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
<div class="resize-indicator" />
|
<div class="resize-indicator" />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#each $renderedColumns as column}
|
{#each $visibleColumns as column}
|
||||||
<div
|
<div
|
||||||
class="resize-slider"
|
class="resize-slider"
|
||||||
class:visible={activeColumn === column.name}
|
class:visible={activeColumn === column.name}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { derived, get } from "svelte/store"
|
import { derived } from "svelte/store"
|
||||||
import {
|
import {
|
||||||
MaxCellRenderHeight,
|
MaxCellRenderHeight,
|
||||||
MaxCellRenderWidthOverflow,
|
MaxCellRenderWidthOverflow,
|
||||||
MinColumnWidth,
|
|
||||||
ScrollBarSize,
|
ScrollBarSize,
|
||||||
} from "../lib/constants"
|
} from "../lib/constants"
|
||||||
|
|
||||||
|
@ -45,66 +44,6 @@ export const deriveStores = context => {
|
||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
|
|
||||||
// Derive visible columns
|
|
||||||
const scrollLeftRounded = derived(scrollLeft, $scrollLeft => {
|
|
||||||
const interval = MinColumnWidth
|
|
||||||
return Math.round($scrollLeft / interval) * interval
|
|
||||||
})
|
|
||||||
const renderedColumns = derived(
|
|
||||||
[visibleColumns, scrollLeftRounded, width],
|
|
||||||
([$visibleColumns, $scrollLeft, $width], set) => {
|
|
||||||
if (!$visibleColumns.length) {
|
|
||||||
set([])
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let startColIdx = 0
|
|
||||||
let rightEdge = $visibleColumns[0].width
|
|
||||||
while (
|
|
||||||
rightEdge < $scrollLeft &&
|
|
||||||
startColIdx < $visibleColumns.length - 1
|
|
||||||
) {
|
|
||||||
startColIdx++
|
|
||||||
rightEdge += $visibleColumns[startColIdx].width
|
|
||||||
}
|
|
||||||
let endColIdx = startColIdx + 1
|
|
||||||
let leftEdge = rightEdge
|
|
||||||
while (
|
|
||||||
leftEdge < $width + $scrollLeft &&
|
|
||||||
endColIdx < $visibleColumns.length
|
|
||||||
) {
|
|
||||||
leftEdge += $visibleColumns[endColIdx].width
|
|
||||||
endColIdx++
|
|
||||||
}
|
|
||||||
// Render an additional column on either side to account for
|
|
||||||
// debounce column updates based on scroll position
|
|
||||||
const next = $visibleColumns.slice(
|
|
||||||
Math.max(0, startColIdx - 1),
|
|
||||||
endColIdx + 1
|
|
||||||
)
|
|
||||||
const current = get(renderedColumns)
|
|
||||||
if (JSON.stringify(next) !== JSON.stringify(current)) {
|
|
||||||
set(next)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const hiddenColumnsWidth = derived(
|
|
||||||
[renderedColumns, visibleColumns],
|
|
||||||
([$renderedColumns, $visibleColumns]) => {
|
|
||||||
const idx = $visibleColumns.findIndex(
|
|
||||||
col => col.name === $renderedColumns[0]?.name
|
|
||||||
)
|
|
||||||
let width = 0
|
|
||||||
if (idx > 0) {
|
|
||||||
for (let i = 0; i < idx; i++) {
|
|
||||||
width += $visibleColumns[i].width
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return width
|
|
||||||
},
|
|
||||||
0
|
|
||||||
)
|
|
||||||
|
|
||||||
// Determine the row index at which we should start vertically inverting cell
|
// Determine the row index at which we should start vertically inverting cell
|
||||||
// dropdowns
|
// dropdowns
|
||||||
const rowVerticalInversionIndex = derived(
|
const rowVerticalInversionIndex = derived(
|
||||||
|
@ -130,12 +69,12 @@ export const deriveStores = context => {
|
||||||
// Determine the column index at which we should start horizontally inverting
|
// Determine the column index at which we should start horizontally inverting
|
||||||
// cell dropdowns
|
// cell dropdowns
|
||||||
const columnHorizontalInversionIndex = derived(
|
const columnHorizontalInversionIndex = derived(
|
||||||
[renderedColumns, scrollLeft, width],
|
[visibleColumns, scrollLeft, width],
|
||||||
([$renderedColumns, $scrollLeft, $width]) => {
|
([$visibleColumns, $scrollLeft, $width]) => {
|
||||||
const cutoff = $width + $scrollLeft - ScrollBarSize * 3
|
const cutoff = $width + $scrollLeft - ScrollBarSize * 3
|
||||||
let inversionIdx = $renderedColumns.length
|
let inversionIdx = $visibleColumns.length
|
||||||
for (let i = $renderedColumns.length - 1; i >= 0; i--, inversionIdx--) {
|
for (let i = $visibleColumns.length - 1; i >= 0; i--, inversionIdx--) {
|
||||||
const rightEdge = $renderedColumns[i].left + $renderedColumns[i].width
|
const rightEdge = $visibleColumns[i].left + $visibleColumns[i].width
|
||||||
if (rightEdge + MaxCellRenderWidthOverflow <= cutoff) {
|
if (rightEdge + MaxCellRenderWidthOverflow <= cutoff) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -148,8 +87,6 @@ export const deriveStores = context => {
|
||||||
scrolledRowCount,
|
scrolledRowCount,
|
||||||
visualRowCapacity,
|
visualRowCapacity,
|
||||||
renderedRows,
|
renderedRows,
|
||||||
renderedColumns,
|
|
||||||
hiddenColumnsWidth,
|
|
||||||
rowVerticalInversionIndex,
|
rowVerticalInversionIndex,
|
||||||
columnHorizontalInversionIndex,
|
columnHorizontalInversionIndex,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue