1
0
Fork 0
mirror of synced 2024-09-17 01:38:40 +12:00

Improve rendering performance and simplify component props

This commit is contained in:
Andrew Kingston 2023-03-10 10:25:26 +00:00
parent 809c56de9f
commit dfd6633bee
5 changed files with 32 additions and 30 deletions

View file

@ -68,11 +68,9 @@
<div class="header row"> <div class="header row">
<!-- Field headers --> <!-- Field headers -->
<SheetCell <SheetCell
header
foo
label
width="40" width="40"
on:click={$config.allowSelectRows && selectAll} on:click={$config.allowSelectRows && selectAll}
center
> >
{#if $config.allowSelectRows} {#if $config.allowSelectRows}
<Checkbox value={rowCount && selectedRowCount === rowCount} /> <Checkbox value={rowCount && selectedRowCount === rowCount} />
@ -92,10 +90,10 @@
{@const containsSelectedRow = $selectedCellRow?._id === row._id} {@const containsSelectedRow = $selectedCellRow?._id === row._id}
<div class="row" on:mouseenter={() => ($hoveredRowId = row._id)}> <div class="row" on:mouseenter={() => ($hoveredRowId = row._id)}>
<SheetCell <SheetCell
label
rowSelected={rowSelected || containsSelectedRow} rowSelected={rowSelected || containsSelectedRow}
{rowHovered} {rowHovered}
width="40" width="40"
center
> >
<div <div
on:click={() => selectRow(row._id)} on:click={() => selectRow(row._id)}
@ -120,7 +118,6 @@
rowSelected={rowSelected || containsSelectedRow} rowSelected={rowSelected || containsSelectedRow}
{rowHovered} {rowHovered}
rowIdx={idx} rowIdx={idx}
sticky
selected={$selectedCellId === cellId} selected={$selectedCellId === cellId}
selectedUser={$selectedCellMap[cellId]} selectedUser={$selectedCellMap[cellId]}
on:click={() => ($selectedCellId = cellId)} on:click={() => ($selectedCellId = cellId)}
@ -150,9 +147,9 @@
> >
<SheetCell <SheetCell
rowHovered={$hoveredRowId === "new"} rowHovered={$hoveredRowId === "new"}
label
on:click={addRow} on:click={addRow}
width="40" width="40"
center
> >
<Icon name="Add" size="S" /> <Icon name="Add" size="S" />
</SheetCell> </SheetCell>
@ -172,8 +169,10 @@
<style> <style>
.sticky-column { .sticky-column {
flex: 0 0 calc(var(--width) + 0px); flex: 0 0 var(--width);
} }
/* Add shadow when scrolled */
.sticky-column.scrolled :global(.cell:last-child:after) { .sticky-column.scrolled :global(.cell:last-child:after) {
content: " "; content: " ";
position: absolute; position: absolute;
@ -182,6 +181,8 @@
left: 100%; left: 100%;
background: linear-gradient(to right, rgba(0, 0, 0, 0.08), transparent); background: linear-gradient(to right, rgba(0, 0, 0, 0.08), transparent);
} }
/* Don't show borders between cells in the sticky column */
.sticky-column :global(.cell:not(:last-child)) { .sticky-column :global(.cell:not(:last-child)) {
border-right: none; border-right: none;
} }
@ -191,6 +192,10 @@
position: relative; position: relative;
z-index: 2; z-index: 2;
} }
.header :global(.cell) {
background: var(--spectrum-global-color-gray-100);
border-bottom: none;
}
.row { .row {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
@ -206,6 +211,10 @@
} }
/* Styles for label cell */ /* Styles for label cell */
.checkbox,
.number {
padding: 0 var(--cell-padding);
}
.checkbox { .checkbox {
display: none; display: none;
} }

View file

@ -9,10 +9,9 @@
export let multi = false export let multi = false
export let readonly = false export let readonly = false
const options = schema?.constraints?.inclusion || []
let open = false let open = false
$: options = schema?.constraints?.inclusion || []
$: editable = selected && !readonly $: editable = selected && !readonly
$: values = Array.isArray(value) ? value : [value].filter(x => x != null) $: values = Array.isArray(value) ? value : [value].filter(x => x != null)
$: unselectedOptions = options.filter(x => !values.includes(x)) $: unselectedOptions = options.filter(x => !values.includes(x))

View file

@ -1,8 +1,6 @@
<script> <script>
export let label = false
export let rowSelected = false export let rowSelected = false
export let rowHovered = false export let rowHovered = false
export let sticky = false
export let selected = false export let selected = false
export let reorderSource = false export let reorderSource = false
export let reorderTarget = false export let reorderTarget = false
@ -10,7 +8,6 @@
export let center = false export let center = false
export let selectedUser = null export let selectedUser = null
export let rowIdx export let rowIdx
export let foo
$: style = getStyle(width, selectedUser) $: style = getStyle(width, selectedUser)
@ -25,11 +22,8 @@
<div <div
class="cell" class="cell"
class:foo
class:label
class:row-selected={rowSelected} class:row-selected={rowSelected}
class:row-hovered={rowHovered} class:row-hovered={rowHovered}
class:sticky
class:selected class:selected
class:selected-other={selectedUser != null} class:selected-other={selectedUser != null}
class:reorder-source={reorderSource} class:reorder-source={reorderSource}
@ -105,19 +99,6 @@
height: calc(var(--cell-height) + 2px); height: calc(var(--cell-height) + 2px);
} }
/* Label cells */
.cell.label {
padding: var(--cell-padding);
flex: 0 0 40px;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.cell.foo {
background: var(--spectrum-global-color-gray-100);
}
/* Other user email */ /* Other user email */
.user { .user {
position: absolute; position: absolute;

View file

@ -5,6 +5,7 @@ export const createUIStores = context => {
const selectedCellId = writable(null) const selectedCellId = writable(null)
const selectedRows = writable({}) const selectedRows = writable({})
const hoveredRowId = writable(null) const hoveredRowId = writable(null)
const selectedCellAPI = writable(null)
// Derive the row that contains the selected cell. // Derive the row that contains the selected cell.
const selectedCellRow = derived( const selectedCellRow = derived(
@ -74,6 +75,7 @@ export const createUIStores = context => {
selectedRows, selectedRows,
hoveredRowId, hoveredRowId,
selectedCellRow, selectedCellRow,
selectedCellAPI,
ui: { ui: {
actions: { actions: {
blur, blur,

View file

@ -44,8 +44,19 @@ export const createViewportStores = context => {
leftEdge += $columns[endColIdx].width leftEdge += $columns[endColIdx].width
endColIdx++ endColIdx++
} }
return $columns.slice(startColIdx, endColIdx) const nextVisibleColumns = $columns.slice(startColIdx, endColIdx)
}
// Cautiously shrink the number of rendered columns.
// This is to avoid rapidly shrinking and growing the visible column count
// which results in remounting cells
const currentCount = get(visibleColumns).length
if (currentCount === nextVisibleColumns.length + 1) {
return $columns.slice(startColIdx, endColIdx + 1)
} else {
return nextVisibleColumns
}
},
[]
) )
// Fetch next page when approaching end of data // Fetch next page when approaching end of data