Merge pull request #15240 from Budibase/typing/stores-grid-menu

Typing grid menu store
This commit is contained in:
Adria Navarro 2024-12-30 14:57:11 +01:00 committed by GitHub
commit a759b465e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 6 deletions

View File

@ -62,7 +62,8 @@ export type Store = BaseStore &
NonPlus.Store &
Datasource.Store &
Validation.Store &
Users.Store & {
Users.Store &
Menu.Store & {
// TODO while typing the rest of stores
fetch: Writable<any>
filter: Writable<any>
@ -80,6 +81,11 @@ export type Store = BaseStore &
schemaOverrides: Writable<any>
focusedCellId: Writable<any>
previousFocusedRowId: Writable<string>
gridID: string
selectedRows: Writable<any>
selectedRowCount: Writable<any>
selectedCellMap: Writable<any>
selectedCellCount: Writable<any>
}
export const attachStores = (context: Store): Store => {

View File

@ -1,8 +1,24 @@
import { writable, get } from "svelte/store"
import { writable, get, Writable } from "svelte/store"
import { Store as StoreContext } from "."
import { parseCellID } from "../lib/utils"
interface MenuStoreData {
left: number
top: number
visible: boolean
multiRowMode: boolean
multiCellMode: boolean
}
interface MenuStore {
menu: Writable<MenuStoreData>
}
export type Store = MenuStore
export const createStores = () => {
const menu = writable({
const menu = writable<MenuStoreData>({
left: 0,
top: 0,
visible: false,
@ -14,7 +30,7 @@ export const createStores = () => {
}
}
export const createActions = context => {
export const createActions = (context: StoreContext) => {
const {
menu,
focusedCellId,
@ -25,7 +41,7 @@ export const createActions = context => {
selectedCellCount,
} = context
const open = (cellId, e) => {
const open = (cellId: string, e: MouseEvent) => {
e.preventDefault()
e.stopPropagation()
@ -37,7 +53,7 @@ export const createActions = context => {
}
// Compute bounds of cell relative to outer data node
const targetBounds = e.target.getBoundingClientRect()
const targetBounds = (e.target as HTMLElement).getBoundingClientRect()
const dataBounds = dataNode.getBoundingClientRect()
// Check if there are multiple rows selected, and if this is one of them