Merge pull request #15251 from Budibase/typing/stores-grid-scroll
Typing grid scroll store
This commit is contained in:
commit
d7f288e2e6
|
@ -180,6 +180,7 @@ export const initialise = (context: StoreContext) => {
|
||||||
conditions: fieldSchema.conditions,
|
conditions: fieldSchema.conditions,
|
||||||
related: fieldSchema.related,
|
related: fieldSchema.related,
|
||||||
calculationType: fieldSchema.calculationType,
|
calculationType: fieldSchema.calculationType,
|
||||||
|
__left: undefined as any, // TODO
|
||||||
}
|
}
|
||||||
// Override a few properties for primary display
|
// Override a few properties for primary display
|
||||||
if (field === primaryDisplay) {
|
if (field === primaryDisplay) {
|
||||||
|
|
|
@ -66,7 +66,8 @@ export type Store = BaseStore &
|
||||||
Menu.Store &
|
Menu.Store &
|
||||||
Filter.Store &
|
Filter.Store &
|
||||||
UI.Store &
|
UI.Store &
|
||||||
Clipboard.Store & {
|
Clipboard.Store &
|
||||||
|
Scroll.Store & {
|
||||||
// TODO while typing the rest of stores
|
// TODO while typing the rest of stores
|
||||||
fetch: Writable<any>
|
fetch: Writable<any>
|
||||||
sort: Writable<any>
|
sort: Writable<any>
|
||||||
|
@ -85,6 +86,8 @@ export type Store = BaseStore &
|
||||||
width: Writable<number>
|
width: Writable<number>
|
||||||
fixedRowHeight: Writable<number>
|
fixedRowHeight: Writable<number>
|
||||||
rowChangeCache: Readable<any>
|
rowChangeCache: Readable<any>
|
||||||
|
bounds: Readable<any>
|
||||||
|
height: Readable<number>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const attachStores = (context: Store): Store => {
|
export const attachStores = (context: Store): Store => {
|
||||||
|
|
|
@ -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 { tick } from "svelte"
|
||||||
import {
|
import {
|
||||||
GutterWidth,
|
GutterWidth,
|
||||||
|
@ -8,8 +8,31 @@ import {
|
||||||
VPadding,
|
VPadding,
|
||||||
} from "../lib/constants"
|
} from "../lib/constants"
|
||||||
import { parseCellID } from "../lib/utils"
|
import { parseCellID } from "../lib/utils"
|
||||||
|
import { Store as StoreContext } from "."
|
||||||
|
|
||||||
export const createStores = () => {
|
interface ScrollStore {
|
||||||
|
scroll: Writable<{
|
||||||
|
left: number
|
||||||
|
top: number
|
||||||
|
}>
|
||||||
|
scrollTop: Readable<number>
|
||||||
|
scrollLeft: Readable<number>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ScrollDerivedStore {
|
||||||
|
stickyWidth: Readable<number>
|
||||||
|
contentHeight: Readable<number>
|
||||||
|
contentWidth: Readable<number>
|
||||||
|
screenWidth: Readable<number>
|
||||||
|
maxScrollTop: Readable<number>
|
||||||
|
maxScrollLeft: Readable<number>
|
||||||
|
showHScrollbar: Readable<number>
|
||||||
|
showVScrollbar: Readable<number>
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Store = ScrollStore & ScrollDerivedStore
|
||||||
|
|
||||||
|
export const createStores = (): ScrollStore => {
|
||||||
const scroll = writable({
|
const scroll = writable({
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
|
@ -26,7 +49,7 @@ export const createStores = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deriveStores = context => {
|
export const deriveStores = (context: StoreContext) => {
|
||||||
const {
|
const {
|
||||||
rows,
|
rows,
|
||||||
visibleColumns,
|
visibleColumns,
|
||||||
|
@ -107,7 +130,7 @@ export const deriveStores = context => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initialise = context => {
|
export const initialise = (context: StoreContext) => {
|
||||||
const {
|
const {
|
||||||
focusedCellId,
|
focusedCellId,
|
||||||
focusedRow,
|
focusedRow,
|
||||||
|
@ -189,7 +212,7 @@ export const initialise = context => {
|
||||||
// Ensure horizontal position is viewable
|
// Ensure horizontal position is viewable
|
||||||
// Check horizontal position of columns next
|
// Check horizontal position of columns next
|
||||||
const { field } = parseCellID($focusedCellId)
|
const { field } = parseCellID($focusedCellId)
|
||||||
const column = get(columnLookupMap)[field]
|
const column = get(columnLookupMap)[field!]
|
||||||
if (!column || column.primaryDisplay) {
|
if (!column || column.primaryDisplay) {
|
||||||
return
|
return
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@ import {
|
||||||
} from "../lib/constants"
|
} from "../lib/constants"
|
||||||
import { getCellID, parseCellID } from "../lib/utils"
|
import { getCellID, parseCellID } from "../lib/utils"
|
||||||
import { Store as StoreContext } from "."
|
import { Store as StoreContext } from "."
|
||||||
|
import { Row } from "@budibase/types"
|
||||||
|
|
||||||
export interface UIStore {
|
export interface UIStore {
|
||||||
focusedCellId: Writable<string | null>
|
focusedCellId: Writable<string | null>
|
||||||
|
@ -34,7 +35,7 @@ export interface UIStore {
|
||||||
|
|
||||||
export interface UIDerivedStore {
|
export interface UIDerivedStore {
|
||||||
focusedRowId: Readable<string | null>
|
focusedRowId: Readable<string | null>
|
||||||
focusedRow: Readable<string | undefined>
|
focusedRow: Readable<Row | undefined>
|
||||||
contentLines: Readable<3 | 2 | 1>
|
contentLines: Readable<3 | 2 | 1>
|
||||||
compact: Readable<boolean>
|
compact: Readable<boolean>
|
||||||
selectedRowCount: Readable<number>
|
selectedRowCount: Readable<number>
|
||||||
|
|
|
@ -17,5 +17,6 @@ export type UIColumn = FieldSchema & {
|
||||||
}
|
}
|
||||||
calculationType: CalculationType
|
calculationType: CalculationType
|
||||||
__idx?: number
|
__idx?: number
|
||||||
__left?: number
|
__left: number
|
||||||
|
width: number
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue