From 296d5dfb55c698b335bed762e738a1a7e9f6d16c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 09:34:27 +0100 Subject: [PATCH] Type clipboard store --- .../src/components/grid/stores/clipboard.ts | 18 ++++++++++++++---- .../src/components/grid/stores/ui.ts | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/clipboard.ts b/packages/frontend-core/src/components/grid/stores/clipboard.ts index 4dce0cf47a..57688e18a3 100644 --- a/packages/frontend-core/src/components/grid/stores/clipboard.ts +++ b/packages/frontend-core/src/components/grid/stores/clipboard.ts @@ -4,8 +4,18 @@ import { parseCellID, getCellID } from "../lib/utils" import { NewRowID } from "../lib/constants" import { Store as StoreContext } from "." +type ClipboardStoreData = + | { + value: string[][] + multiCellCopy: true + } + | { + value: string | null | undefined + multiCellCopy: false + } + interface ClipboardStore { - clipboard: Writable<{ value: any; multiCellCopy: boolean }> + clipboard: Writable } interface ClipboardDerivedStore { @@ -25,7 +35,7 @@ interface ClipboardActions { export type Store = ClipboardStore & ClipboardDerivedStore & ClipboardActions export const createStores = (): ClipboardStore => { - const clipboard = writable({ + const clipboard = writable({ value: null, multiCellCopy: false, }) @@ -218,11 +228,11 @@ export const createActions = (context: StoreContext): ClipboardActions => { } else { if (multiCellPaste) { // Single to multi - duplicate value to all selected cells - const newValue = get(selectedCells).map(row => row.map(() => value)) + const newValue = get(selectedCells).map(row => row.map(() => value!)) await pasteIntoSelectedCells(newValue, progressCallback) } else { // Single to single - just update the cell's value - get(focusedCellAPI)?.setValue(value) + get(focusedCellAPI)?.setValue(value ?? null) } } } diff --git a/packages/frontend-core/src/components/grid/stores/ui.ts b/packages/frontend-core/src/components/grid/stores/ui.ts index 7196723064..8988137e0b 100644 --- a/packages/frontend-core/src/components/grid/stores/ui.ts +++ b/packages/frontend-core/src/components/grid/stores/ui.ts @@ -14,7 +14,7 @@ export interface UIStore { focusedCellAPI: Writable<{ isReadonly: () => boolean getValue: () => string - setValue: (val: string) => void + setValue: (val: string | null) => void } | null> selectedRows: Writable> hoveredRowId: Writable