Type clipboard store
This commit is contained in:
parent
b600a2763d
commit
296d5dfb55
|
@ -4,8 +4,18 @@ import { parseCellID, getCellID } from "../lib/utils"
|
||||||
import { NewRowID } from "../lib/constants"
|
import { NewRowID } from "../lib/constants"
|
||||||
import { Store as StoreContext } from "."
|
import { Store as StoreContext } from "."
|
||||||
|
|
||||||
|
type ClipboardStoreData =
|
||||||
|
| {
|
||||||
|
value: string[][]
|
||||||
|
multiCellCopy: true
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
value: string | null | undefined
|
||||||
|
multiCellCopy: false
|
||||||
|
}
|
||||||
|
|
||||||
interface ClipboardStore {
|
interface ClipboardStore {
|
||||||
clipboard: Writable<{ value: any; multiCellCopy: boolean }>
|
clipboard: Writable<ClipboardStoreData>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ClipboardDerivedStore {
|
interface ClipboardDerivedStore {
|
||||||
|
@ -25,7 +35,7 @@ interface ClipboardActions {
|
||||||
export type Store = ClipboardStore & ClipboardDerivedStore & ClipboardActions
|
export type Store = ClipboardStore & ClipboardDerivedStore & ClipboardActions
|
||||||
|
|
||||||
export const createStores = (): ClipboardStore => {
|
export const createStores = (): ClipboardStore => {
|
||||||
const clipboard = writable({
|
const clipboard = writable<ClipboardStoreData>({
|
||||||
value: null,
|
value: null,
|
||||||
multiCellCopy: false,
|
multiCellCopy: false,
|
||||||
})
|
})
|
||||||
|
@ -218,11 +228,11 @@ export const createActions = (context: StoreContext): ClipboardActions => {
|
||||||
} else {
|
} else {
|
||||||
if (multiCellPaste) {
|
if (multiCellPaste) {
|
||||||
// Single to multi - duplicate value to all selected cells
|
// 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)
|
await pasteIntoSelectedCells(newValue, progressCallback)
|
||||||
} else {
|
} else {
|
||||||
// Single to single - just update the cell's value
|
// Single to single - just update the cell's value
|
||||||
get(focusedCellAPI)?.setValue(value)
|
get(focusedCellAPI)?.setValue(value ?? null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ export interface UIStore {
|
||||||
focusedCellAPI: Writable<{
|
focusedCellAPI: Writable<{
|
||||||
isReadonly: () => boolean
|
isReadonly: () => boolean
|
||||||
getValue: () => string
|
getValue: () => string
|
||||||
setValue: (val: string) => void
|
setValue: (val: string | null) => void
|
||||||
} | null>
|
} | null>
|
||||||
selectedRows: Writable<Record<string, boolean>>
|
selectedRows: Writable<Record<string, boolean>>
|
||||||
hoveredRowId: Writable<string | null>
|
hoveredRowId: Writable<string | null>
|
||||||
|
|
Loading…
Reference in New Issue