($selectedCellId = null)}
id={`sheet-${rand}-body`}
+ style={sheetStyles}
>
diff --git a/packages/client/src/components/app/spreadsheet/SpreadsheetCell.svelte b/packages/client/src/components/app/spreadsheet/SpreadsheetCell.svelte
index 2501d47726..b8138a501d 100644
--- a/packages/client/src/components/app/spreadsheet/SpreadsheetCell.svelte
+++ b/packages/client/src/components/app/spreadsheet/SpreadsheetCell.svelte
@@ -8,8 +8,8 @@
export let selected = false
export let reorderSource = false
export let reorderTarget = false
- export let id = null
- export let column
+ export let left
+ export let width
@@ -52,6 +51,8 @@
background: var(--cell-background);
position: absolute;
transition: border-color 130ms ease-out;
+ width: var(--width);
+ transform: translateX(var(--left));
}
.cell.row-hovered {
background: var(--cell-background-hover);
@@ -88,9 +89,10 @@
/* Sticky styles */
.cell.sticky {
position: sticky;
- left: 40px;
z-index: 2;
border-left-color: transparent;
+ transform: none;
+ left: 40px;
}
.cell.sticky.selected {
z-index: 3;
@@ -112,6 +114,7 @@
/* Label cells */
.cell.label {
+ width: 40px;
padding: 0 12px;
border-left-width: 0;
position: sticky;
diff --git a/packages/client/src/components/app/spreadsheet/SpreadsheetRow.svelte b/packages/client/src/components/app/spreadsheet/SpreadsheetRow.svelte
index c64deaa63f..fcba9caf88 100644
--- a/packages/client/src/components/app/spreadsheet/SpreadsheetRow.svelte
+++ b/packages/client/src/components/app/spreadsheet/SpreadsheetRow.svelte
@@ -20,14 +20,18 @@
selectedRows,
changeCache,
spreadsheetAPI,
- visibleRows,
+ visibleCells,
cellHeight,
} = getContext("spreadsheet")
$: rowSelected = !!$selectedRows[row._id]
$: rowHovered = $hoveredRowId === row._id
$: data = { ...row, ...$changeCache[row._id] }
- $: visible = rowIdx >= $visibleRows[0] && rowIdx <= $visibleRows[1]
+ $: visibleColumns = [
+ $columns[0],
+ ...$columns.slice($visibleCells.x[0], $visibleCells.x[1]),
+ ]
+ $: containsSelectedCell = $selectedCellId?.split("-")[0] === row._id
const getCellForField = field => {
const type = field.schema.type
@@ -53,64 +57,66 @@
}
-{#if visible}
-
diff --git a/packages/client/src/components/app/spreadsheet/stores/reorder.js b/packages/client/src/components/app/spreadsheet/stores/reorder.js
index 972db3a6ce..db6d1831ec 100644
--- a/packages/client/src/components/app/spreadsheet/stores/reorder.js
+++ b/packages/client/src/components/app/spreadsheet/stores/reorder.js
@@ -27,17 +27,16 @@ export const createReorderStores = context => {
let breakpoints = []
const cols = get(columns)
cols.forEach((col, idx) => {
- const header = document.getElementById(`sheet-${rand}-header-${idx}`)
- const bounds = header.getBoundingClientRect()
- breakpoints.push(bounds.x)
+ breakpoints.push(col.left)
if (idx === cols.length - 1) {
- breakpoints.push(bounds.x + bounds.width)
+ breakpoints.push(col.left + col.width)
}
})
+ console.log(breakpoints, e.clientX)
// Get bounds of the selected header and sheet body
- const self = document.getElementById(`sheet-${rand}-header-${columnIdx}`)
- const selfBounds = self.getBoundingClientRect()
+
+ const self = cols[columnIdx]
const body = document.getElementById(`sheet-${rand}-body`)
const bodyBounds = body.getBoundingClientRect()
@@ -49,9 +48,9 @@ export const createReorderStores = context => {
initialMouseX: e.clientX,
})
placeholder.set({
- initialX: selfBounds.x - bodyBounds.x,
- x: selfBounds.x - bodyBounds.x,
- width: selfBounds.width,
+ initialX: self.left - bodyBounds.x,
+ x: self.left - bodyBounds.x,
+ width: self.width,
height: (get(rows).length + 2) * 32,
})
@@ -103,13 +102,15 @@ export const createReorderStores = context => {
const stopReordering = () => {
// Swap position of columns
let { columnIdx, swapColumnIdx } = get(reorder)
- const newColumns = get(columns).slice()
- const removed = newColumns.splice(columnIdx, 1)
- if (--swapColumnIdx < columnIdx) {
- swapColumnIdx++
- }
- newColumns.splice(swapColumnIdx, 0, removed[0])
- columns.set(newColumns)
+ columns.update(state => {
+ const removed = state.splice(columnIdx, 1)
+ if (--swapColumnIdx < columnIdx) {
+ swapColumnIdx++
+ }
+ state.splice(swapColumnIdx, 0, removed[0])
+ state = state.map((col, idx) => ({ ...col, idx }))
+ return state
+ })
// Reset state
reorder.set(reorderInitialState)
diff --git a/packages/client/src/components/app/spreadsheet/stores/resize.js b/packages/client/src/components/app/spreadsheet/stores/resize.js
index aab716df99..8327f0e79d 100644
--- a/packages/client/src/components/app/spreadsheet/stores/resize.js
+++ b/packages/client/src/components/app/spreadsheet/stores/resize.js
@@ -23,17 +23,16 @@ export const createResizeStore = context => {
const resize = writable(initialState)
const startResizing = (idx, e) => {
+ const $columns = get(columns)
// Prevent propagation to stop reordering triggering
e.stopPropagation()
- sheet = document.getElementById(`sheet-${rand}`)
- styles = getComputedStyle(sheet)
- width = parseInt(styles.getPropertyValue(`--col-${idx}-width`))
- left = parseInt(styles.getPropertyValue(`--col-${idx}-left`))
+ width = $columns[idx].width
+ left = $columns[idx].left
initialWidth = width
initialMouseX = e.clientX
columnIdx = idx
- columnCount = get(columns).length
+ columnCount = $columns.length
// Add mouse event listeners to handle resizing
document.addEventListener("mousemove", onResizeMouseMove)
@@ -48,17 +47,54 @@ export const createResizeStore = context => {
return
}
+ columns.update(state => {
+ state[columnIdx].width = newWidth
+ let offset = state[columnIdx].left + newWidth
+ for (let i = columnIdx + 1; i < state.length; i++) {
+ state[i].left = offset
+ offset += state[i].width
+ }
+ return state
+ })
+
+ // let newStyle = `--col-${columnIdx}-width:${newWidth}px;`
+ //
+ // let offset = left + newWidth
+ // for (let i = columnIdx + 1; i < columnCount; i++) {
+ // const colWidth = parseInt(styles.getPropertyValue(`--col-${i}-width`))
+ // newStyle += `--col-${i}-left:${offset}px;`
+ // offset += colWidth
+ // }
+ //
+ // sheet.style.cssText += newStyle
+
+
+ // let cells = sheet.querySelectorAll(`[data-col="${columnIdx}"]`)
+ // let left
+ // cells.forEach(cell => {
+ // cell.style.width = `${newWidth}px`
+ // cell.dataset.width = newWidth
+ // if (!left) {
+ // left = parseInt(cell.dataset.left)
+ // }
+ // })
+ //
+ // let offset = left + newWidth
+ // for (let i = columnIdx + 1; i < columnCount; i++) {
+ // cells = sheet.querySelectorAll(`[data-col="${i}"]`)
+ // let colWidth
+ // cells.forEach(cell => {
+ // cell.style.transform = `translateX(${offset}px)`
+ // cell.dataset.left = offset
+ // if (!colWidth) {
+ // colWidth = parseInt(cell.dataset.width)
+ // }
+ // })
+ // offset += colWidth
+ // }
- let newStyle = `--col-${columnIdx}-width:${newWidth}px;`
- let offset = left + newWidth
- for (let i = columnIdx + 1; i < columnCount; i++) {
- const colWidth = 160//parseInt(styles.getPropertyValue(`--col-${i}-width`))
- newStyle += `--col-${i}-left:${offset}px;`
- offset += colWidth
- }
- sheet.style.cssText += newStyle
width = newWidth
// Update width of column