From 5ab0652c8715f3fa3582dcd3cccf84d355a86485 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Sat, 1 Apr 2023 10:50:42 +0100 Subject: [PATCH] Fix scroll not working in new row --- .../src/components/sheet/layout/NewRow.svelte | 6 +- .../components/sheet/layout/NewRowTop.svelte | 75 +++++++++---------- .../src/components/sheet/layout/Sheet.svelte | 2 - .../sheet/layout/SheetScrollWrapper.svelte | 40 +++++++++- .../src/components/sheet/stores/wheel.js | 54 ------------- 5 files changed, 76 insertions(+), 101 deletions(-) delete mode 100644 packages/frontend-core/src/components/sheet/stores/wheel.js diff --git a/packages/frontend-core/src/components/sheet/layout/NewRow.svelte b/packages/frontend-core/src/components/sheet/layout/NewRow.svelte index f0d4c29e5b..0be62434f1 100644 --- a/packages/frontend-core/src/components/sheet/layout/NewRow.svelte +++ b/packages/frontend-core/src/components/sheet/layout/NewRow.svelte @@ -70,11 +70,7 @@ -
+
diff --git a/packages/frontend-core/src/components/sheet/layout/NewRowTop.svelte b/packages/frontend-core/src/components/sheet/layout/NewRowTop.svelte index abda73b0fc..0ffbd57fc3 100644 --- a/packages/frontend-core/src/components/sheet/layout/NewRowTop.svelte +++ b/packages/frontend-core/src/components/sheet/layout/NewRowTop.svelte @@ -72,53 +72,52 @@ {#if firstColumn} -
+
($hoveredRowId = "new")} on:mouseleave={() => ($hoveredRowId = null)} > -
0} - > - +
0} > -
-
1
- {#if $config.allowExpandRows} - - {/if} -
- - {#if $stickyColumn} - {@const cellId = `new-${$stickyColumn.name}`} - - {/if} -
+ > +
+
1
+ {#if $config.allowExpandRows} + + {/if} +
+
+ {#if $stickyColumn} + {@const cellId = `new-${$stickyColumn.name}`} + + {/if} +
+ +
{#each $renderedColumns as column} diff --git a/packages/frontend-core/src/components/sheet/layout/Sheet.svelte b/packages/frontend-core/src/components/sheet/layout/Sheet.svelte index 57bfdea45d..a618c98a3e 100644 --- a/packages/frontend-core/src/components/sheet/layout/Sheet.svelte +++ b/packages/frontend-core/src/components/sheet/layout/Sheet.svelte @@ -15,7 +15,6 @@ import { createMenuStores } from "../stores/menu" import { createMaxScrollStores } from "../stores/max-scroll" import { createPaginationStores } from "../stores/pagination" - import { createWheelStores } from "../stores/wheel" import DeleteButton from "../controls/DeleteButton.svelte" import SheetBody from "./SheetBody.svelte" import ResizeOverlay from "../overlays/ResizeOverlay.svelte" @@ -76,7 +75,6 @@ context = { ...context, ...createUserStores(context) } context = { ...context, ...createMenuStores(context) } context = { ...context, ...createPaginationStores(context) } - context = { ...context, ...createWheelStores(context) } // Reference some stores for local use const { isResizing, isReordering, ui, loaded, rowHeight } = context diff --git a/packages/frontend-core/src/components/sheet/layout/SheetScrollWrapper.svelte b/packages/frontend-core/src/components/sheet/layout/SheetScrollWrapper.svelte index 1e701c4cc2..31953d1d46 100644 --- a/packages/frontend-core/src/components/sheet/layout/SheetScrollWrapper.svelte +++ b/packages/frontend-core/src/components/sheet/layout/SheetScrollWrapper.svelte @@ -1,5 +1,6 @@
($selectedCellId = null)} >
diff --git a/packages/frontend-core/src/components/sheet/stores/wheel.js b/packages/frontend-core/src/components/sheet/stores/wheel.js deleted file mode 100644 index 82dc757fc2..0000000000 --- a/packages/frontend-core/src/components/sheet/stores/wheel.js +++ /dev/null @@ -1,54 +0,0 @@ -import { get } from "svelte/store" -import { domDebounce } from "../../../utils/utils" - -export const createWheelStores = context => { - const { - maxScrollLeft, - maxScrollTop, - hoveredRowId, - renderedRows, - bounds, - scroll, - rowHeight, - } = context - - // Handles a wheel even and updates the scroll offsets - const handleWheel = e => { - e.preventDefault() - const modifier = e.ctrlKey || e.metaKey - let x = modifier ? e.deltaY : e.deltaX - let y = modifier ? e.deltaX : e.deltaY - debouncedHandleWheel(x, y, e.clientY) - } - const debouncedHandleWheel = domDebounce((deltaX, deltaY, clientY) => { - const { top, left } = get(scroll) - const $rowHeight = get(rowHeight) - - // Calculate new scroll top - let newScrollTop = top + deltaY - newScrollTop = Math.max(0, Math.min(newScrollTop, get(maxScrollTop))) - - // Calculate new scroll left - let newScrollLeft = left + deltaX - newScrollLeft = Math.max(0, Math.min(newScrollLeft, get(maxScrollLeft))) - - // Update state - scroll.set({ - left: newScrollLeft, - top: newScrollTop, - }) - - // Hover row under cursor - const y = clientY - get(bounds).top + (newScrollTop % $rowHeight) - const hoveredRow = get(renderedRows)[Math.floor(y / $rowHeight)] - hoveredRowId.set(hoveredRow?._id) - }) - - return { - wheel: { - actions: { - handleWheel, - }, - }, - } -}