From 4a5279dfb637d6ede69d33bd0b2f552d7b8f22fb Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 20:38:43 +0100 Subject: [PATCH] Inital ts conversion --- .../src/components/grid/stores/index.ts | 3 +- .../grid/stores/{resize.js => resize.ts} | 37 ++++++++++++++----- .../src/components/grid/stores/ui.ts | 5 +++ 3 files changed, 34 insertions(+), 11 deletions(-) rename packages/frontend-core/src/components/grid/stores/{resize.js => resize.ts} (76%) diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index ba4ac5a830..1706865981 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -85,7 +85,8 @@ export type Store = BaseStore & bounds: Readable height: Readable } & Rows.Store & - Reorder.Store + Reorder.Store & + Resize.Store export const attachStores = (context: Store): Store => { // Atomic store creation diff --git a/packages/frontend-core/src/components/grid/stores/resize.js b/packages/frontend-core/src/components/grid/stores/resize.ts similarity index 76% rename from packages/frontend-core/src/components/grid/stores/resize.js rename to packages/frontend-core/src/components/grid/stores/resize.ts index c242dd9a60..84c4b758a3 100644 --- a/packages/frontend-core/src/components/grid/stores/resize.js +++ b/packages/frontend-core/src/components/grid/stores/resize.ts @@ -1,8 +1,18 @@ -import { writable, get, derived } from "svelte/store" +import { writable, get, derived, Writable, Readable } from "svelte/store" import { MinColumnWidth, DefaultColumnWidth } from "../lib/constants" import { parseEventLocation } from "../lib/utils" +import { Store as StoreContext } from "." -const initialState = { +interface ResizeInitialStoreData { + initialMouseX: number | null + initialWidth: number | null + column: string | null + width: number + left: number + related?: any +} + +const initialState: ResizeInitialStoreData = { initialMouseX: null, initialWidth: null, column: null, @@ -10,7 +20,14 @@ const initialState = { left: 0, } -export const createStores = () => { +interface ResizeInitialStore { + resize: Writable + isResizing: Readable +} + +export type Store = ResizeInitialStore + +export const createStores = (): ResizeInitialStore => { const resize = writable(initialState) const isResizing = derived(resize, $resize => $resize.column != null, false) return { @@ -19,11 +36,11 @@ export const createStores = () => { } } -export const createActions = context => { +export const createActions = (context: StoreContext) => { const { resize, ui, datasource } = context // Starts resizing a certain column - const startResizing = (column, e) => { + const startResizing = (column: any, e: any) => { const { x } = parseEventLocation(e) // Prevent propagation to stop reordering triggering @@ -50,11 +67,11 @@ export const createActions = context => { } // Handler for moving the mouse to resize columns - const onResizeMouseMove = e => { + const onResizeMouseMove = (e: any) => { const { initialMouseX, initialWidth, width, column, related } = get(resize) const { x } = parseEventLocation(e) - const dx = x - initialMouseX - const newWidth = Math.round(Math.max(MinColumnWidth, initialWidth + dx)) + const dx = x - initialMouseX! + const newWidth = Math.round(Math.max(MinColumnWidth, initialWidth! + dx)) // Ignore small changes if (Math.abs(width - newWidth) < 5) { @@ -63,7 +80,7 @@ export const createActions = context => { // Update column state if (!related) { - datasource.actions.addSchemaMutation(column, { width }) + datasource.actions.addSchemaMutation(column!, { width }) } else { datasource.actions.addSubSchemaMutation(related.subField, related.field, { width, @@ -95,7 +112,7 @@ export const createActions = context => { } // Resets a column size back to default - const resetSize = async column => { + const resetSize = async (column: { name: string }) => { datasource.actions.addSchemaMutation(column.name, { width: DefaultColumnWidth, }) diff --git a/packages/frontend-core/src/components/grid/stores/ui.ts b/packages/frontend-core/src/components/grid/stores/ui.ts index 3cde73207e..d689cdb4f5 100644 --- a/packages/frontend-core/src/components/grid/stores/ui.ts +++ b/packages/frontend-core/src/components/grid/stores/ui.ts @@ -52,6 +52,11 @@ interface UIActionStore { selectRange: (source: string | null, target: string | null) => void } } + ui: { + actions: { + blur: () => void + } + } } export type Store = UIStore & UIDerivedStore & UIActionStore