Inital ts conversion
This commit is contained in:
parent
2d4d9e84b7
commit
4a5279dfb6
|
@ -85,7 +85,8 @@ export type Store = BaseStore &
|
||||||
bounds: Readable<any>
|
bounds: Readable<any>
|
||||||
height: Readable<number>
|
height: Readable<number>
|
||||||
} & Rows.Store &
|
} & Rows.Store &
|
||||||
Reorder.Store
|
Reorder.Store &
|
||||||
|
Resize.Store
|
||||||
|
|
||||||
export const attachStores = (context: Store): Store => {
|
export const attachStores = (context: Store): Store => {
|
||||||
// Atomic store creation
|
// Atomic store creation
|
||||||
|
|
|
@ -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 { MinColumnWidth, DefaultColumnWidth } from "../lib/constants"
|
||||||
import { parseEventLocation } from "../lib/utils"
|
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,
|
initialMouseX: null,
|
||||||
initialWidth: null,
|
initialWidth: null,
|
||||||
column: null,
|
column: null,
|
||||||
|
@ -10,7 +20,14 @@ const initialState = {
|
||||||
left: 0,
|
left: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createStores = () => {
|
interface ResizeInitialStore {
|
||||||
|
resize: Writable<ResizeInitialStoreData>
|
||||||
|
isResizing: Readable<boolean>
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Store = ResizeInitialStore
|
||||||
|
|
||||||
|
export const createStores = (): ResizeInitialStore => {
|
||||||
const resize = writable(initialState)
|
const resize = writable(initialState)
|
||||||
const isResizing = derived(resize, $resize => $resize.column != null, false)
|
const isResizing = derived(resize, $resize => $resize.column != null, false)
|
||||||
return {
|
return {
|
||||||
|
@ -19,11 +36,11 @@ export const createStores = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createActions = context => {
|
export const createActions = (context: StoreContext) => {
|
||||||
const { resize, ui, datasource } = context
|
const { resize, ui, datasource } = context
|
||||||
|
|
||||||
// Starts resizing a certain column
|
// Starts resizing a certain column
|
||||||
const startResizing = (column, e) => {
|
const startResizing = (column: any, e: any) => {
|
||||||
const { x } = parseEventLocation(e)
|
const { x } = parseEventLocation(e)
|
||||||
|
|
||||||
// Prevent propagation to stop reordering triggering
|
// Prevent propagation to stop reordering triggering
|
||||||
|
@ -50,11 +67,11 @@ export const createActions = context => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler for moving the mouse to resize columns
|
// Handler for moving the mouse to resize columns
|
||||||
const onResizeMouseMove = e => {
|
const onResizeMouseMove = (e: any) => {
|
||||||
const { initialMouseX, initialWidth, width, column, related } = get(resize)
|
const { initialMouseX, initialWidth, width, column, related } = get(resize)
|
||||||
const { x } = parseEventLocation(e)
|
const { x } = parseEventLocation(e)
|
||||||
const dx = x - initialMouseX
|
const dx = x - initialMouseX!
|
||||||
const newWidth = Math.round(Math.max(MinColumnWidth, initialWidth + dx))
|
const newWidth = Math.round(Math.max(MinColumnWidth, initialWidth! + dx))
|
||||||
|
|
||||||
// Ignore small changes
|
// Ignore small changes
|
||||||
if (Math.abs(width - newWidth) < 5) {
|
if (Math.abs(width - newWidth) < 5) {
|
||||||
|
@ -63,7 +80,7 @@ export const createActions = context => {
|
||||||
|
|
||||||
// Update column state
|
// Update column state
|
||||||
if (!related) {
|
if (!related) {
|
||||||
datasource.actions.addSchemaMutation(column, { width })
|
datasource.actions.addSchemaMutation(column!, { width })
|
||||||
} else {
|
} else {
|
||||||
datasource.actions.addSubSchemaMutation(related.subField, related.field, {
|
datasource.actions.addSubSchemaMutation(related.subField, related.field, {
|
||||||
width,
|
width,
|
||||||
|
@ -95,7 +112,7 @@ export const createActions = context => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resets a column size back to default
|
// Resets a column size back to default
|
||||||
const resetSize = async column => {
|
const resetSize = async (column: { name: string }) => {
|
||||||
datasource.actions.addSchemaMutation(column.name, {
|
datasource.actions.addSchemaMutation(column.name, {
|
||||||
width: DefaultColumnWidth,
|
width: DefaultColumnWidth,
|
||||||
})
|
})
|
|
@ -52,6 +52,11 @@ interface UIActionStore {
|
||||||
selectRange: (source: string | null, target: string | null) => void
|
selectRange: (source: string | null, target: string | null) => void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ui: {
|
||||||
|
actions: {
|
||||||
|
blur: () => void
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Store = UIStore & UIDerivedStore & UIActionStore
|
export type Store = UIStore & UIDerivedStore & UIActionStore
|
||||||
|
|
Loading…
Reference in New Issue