From 7811f11599ca87952c83ddf7a6e25e4ecb994ccd Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 09:46:20 +0100 Subject: [PATCH 1/3] Initial scroll conversion --- .../src/components/grid/stores/columns.ts | 1 + .../src/components/grid/stores/index.ts | 5 ++- .../grid/stores/{scroll.js => scroll.ts} | 33 ++++++++++++++++--- .../src/components/grid/stores/ui.ts | 3 +- packages/types/src/ui/stores/grid/columns.ts | 3 +- 5 files changed, 37 insertions(+), 8 deletions(-) rename packages/frontend-core/src/components/grid/stores/{scroll.js => scroll.ts} (86%) diff --git a/packages/frontend-core/src/components/grid/stores/columns.ts b/packages/frontend-core/src/components/grid/stores/columns.ts index b201cc7f7b..01cbf3af22 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.ts +++ b/packages/frontend-core/src/components/grid/stores/columns.ts @@ -180,6 +180,7 @@ export const initialise = (context: StoreContext) => { conditions: fieldSchema.conditions, related: fieldSchema.related, calculationType: fieldSchema.calculationType, + __left: 0, // TODO } // Override a few properties for primary display if (field === primaryDisplay) { diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index b5676ca241..2a68e30d25 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -66,7 +66,8 @@ export type Store = BaseStore & Menu.Store & Filter.Store & UI.Store & - Clipboard.Store & { + Clipboard.Store & + Scroll.Store & { // TODO while typing the rest of stores fetch: Writable sort: Writable @@ -85,6 +86,8 @@ export type Store = BaseStore & width: Writable fixedRowHeight: Writable rowChangeCache: Readable + bounds: Readable + height: Readable } export const attachStores = (context: Store): Store => { diff --git a/packages/frontend-core/src/components/grid/stores/scroll.js b/packages/frontend-core/src/components/grid/stores/scroll.ts similarity index 86% rename from packages/frontend-core/src/components/grid/stores/scroll.js rename to packages/frontend-core/src/components/grid/stores/scroll.ts index 9411cb93f1..0e6365e4b6 100644 --- a/packages/frontend-core/src/components/grid/stores/scroll.js +++ b/packages/frontend-core/src/components/grid/stores/scroll.ts @@ -1,4 +1,4 @@ -import { writable, derived, get } from "svelte/store" +import { writable, derived, get, Writable, Readable } from "svelte/store" import { tick } from "svelte" import { GutterWidth, @@ -8,8 +8,31 @@ import { VPadding, } from "../lib/constants" import { parseCellID } from "../lib/utils" +import { Store as StoreContext } from "." -export const createStores = () => { +interface ScrollStore { + scroll: Writable<{ + left: number + top: number + }> + scrollTop: Readable + scrollLeft: Readable +} + +interface ScrollDerivedStore { + stickyWidth: Readable + contentHeight: Readable + contentWidth: Readable + screenWidth: Readable + maxScrollTop: Readable + maxScrollLeft: Readable + showHScrollbar: Readable + showVScrollbar: Readable +} + +export type Store = ScrollStore & ScrollDerivedStore + +export const createStores = (): ScrollStore => { const scroll = writable({ left: 0, top: 0, @@ -26,7 +49,7 @@ export const createStores = () => { } } -export const deriveStores = context => { +export const deriveStores = (context: StoreContext) => { const { rows, visibleColumns, @@ -107,7 +130,7 @@ export const deriveStores = context => { } } -export const initialise = context => { +export const initialise = (context: StoreContext) => { const { focusedCellId, focusedRow, @@ -189,7 +212,7 @@ export const initialise = context => { // Ensure horizontal position is viewable // Check horizontal position of columns next const { field } = parseCellID($focusedCellId) - const column = get(columnLookupMap)[field] + const column = get(columnLookupMap)[field!] if (!column || column.primaryDisplay) { return } diff --git a/packages/frontend-core/src/components/grid/stores/ui.ts b/packages/frontend-core/src/components/grid/stores/ui.ts index 8988137e0b..45baebe4fe 100644 --- a/packages/frontend-core/src/components/grid/stores/ui.ts +++ b/packages/frontend-core/src/components/grid/stores/ui.ts @@ -8,6 +8,7 @@ import { } from "../lib/constants" import { getCellID, parseCellID } from "../lib/utils" import { Store as StoreContext } from "." +import { Row } from "@budibase/types" export interface UIStore { focusedCellId: Writable @@ -34,7 +35,7 @@ export interface UIStore { export interface UIDerivedStore { focusedRowId: Readable - focusedRow: Readable + focusedRow: Readable contentLines: Readable<3 | 2 | 1> compact: Readable selectedRowCount: Readable diff --git a/packages/types/src/ui/stores/grid/columns.ts b/packages/types/src/ui/stores/grid/columns.ts index 5f02efa8cb..56442a871f 100644 --- a/packages/types/src/ui/stores/grid/columns.ts +++ b/packages/types/src/ui/stores/grid/columns.ts @@ -17,5 +17,6 @@ export type UIColumn = FieldSchema & { } calculationType: CalculationType __idx?: number - __left?: number + __left: number + width: number } From 51688543b1a1d394042c7056d635e1d3e7883f4f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 09:49:05 +0100 Subject: [PATCH 2/3] Type anys --- .../src/components/grid/stores/scroll.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/scroll.ts b/packages/frontend-core/src/components/grid/stores/scroll.ts index 0e6365e4b6..0be8fa4a77 100644 --- a/packages/frontend-core/src/components/grid/stores/scroll.ts +++ b/packages/frontend-core/src/components/grid/stores/scroll.ts @@ -20,14 +20,14 @@ interface ScrollStore { } interface ScrollDerivedStore { - stickyWidth: Readable - contentHeight: Readable - contentWidth: Readable - screenWidth: Readable - maxScrollTop: Readable - maxScrollLeft: Readable - showHScrollbar: Readable - showVScrollbar: Readable + stickyWidth: Readable + contentHeight: Readable + contentWidth: Readable + screenWidth: Readable + maxScrollTop: Readable + maxScrollLeft: Readable + showHScrollbar: Readable + showVScrollbar: Readable } export type Store = ScrollStore & ScrollDerivedStore From b78fff03e0c9a540db4aa4ca9f1e0134abb19759 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 12:50:46 +0100 Subject: [PATCH 3/3] Revert setting some values --- packages/frontend-core/src/components/grid/stores/columns.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend-core/src/components/grid/stores/columns.ts b/packages/frontend-core/src/components/grid/stores/columns.ts index 01cbf3af22..18ef8f55c2 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.ts +++ b/packages/frontend-core/src/components/grid/stores/columns.ts @@ -180,7 +180,7 @@ export const initialise = (context: StoreContext) => { conditions: fieldSchema.conditions, related: fieldSchema.related, calculationType: fieldSchema.calculationType, - __left: 0, // TODO + __left: undefined as any, // TODO } // Override a few properties for primary display if (field === primaryDisplay) {