@budibase/frontend-core 3.2.29 → 3.2.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/package.json +9 -3
  2. package/src/api/ai.ts +17 -0
  3. package/src/api/analytics.ts +39 -0
  4. package/src/api/{app.js → app.ts} +84 -5
  5. package/src/api/attachments.ts +121 -0
  6. package/src/api/auditLogs.ts +35 -0
  7. package/src/api/{auth.js → auth.ts} +44 -7
  8. package/src/api/automations.ts +158 -0
  9. package/src/api/backups.ts +50 -0
  10. package/src/api/{configs.js → configs.ts} +31 -3
  11. package/src/api/datasources.ts +132 -0
  12. package/src/api/environmentVariables.ts +58 -0
  13. package/src/api/events.ts +21 -0
  14. package/src/api/flags.ts +48 -0
  15. package/src/api/{groups.js → groups.ts} +73 -17
  16. package/src/api/{index.js → index.ts} +89 -102
  17. package/src/api/layouts.ts +35 -0
  18. package/src/api/licensing.ts +107 -0
  19. package/src/api/{logs.js → logs.ts} +7 -1
  20. package/src/api/migrations.ts +19 -0
  21. package/src/api/{other.js → other.ts} +19 -12
  22. package/src/api/{permissions.js → permissions.ts} +31 -5
  23. package/src/api/{plugins.js → plugins.ts} +18 -1
  24. package/src/api/{queries.js → queries.ts} +39 -14
  25. package/src/api/relationships.ts +31 -0
  26. package/src/api/{roles.js → roles.ts} +22 -5
  27. package/src/api/routes.ts +30 -0
  28. package/src/api/{rowActions.js → rowActions.ts} +45 -27
  29. package/src/api/rows.ts +120 -0
  30. package/src/api/screens.ts +35 -0
  31. package/src/api/{self.js → self.ts} +20 -4
  32. package/src/api/tables.ts +192 -0
  33. package/src/api/templates.ts +57 -0
  34. package/src/api/types.ts +136 -0
  35. package/src/api/{user.js → user.ts} +111 -119
  36. package/src/api/{views.js → views.ts} +18 -7
  37. package/src/api/{viewsV2.js → viewsV2.ts} +30 -27
  38. package/src/components/grid/cells/AICell.svelte +1 -0
  39. package/src/components/grid/cells/LongFormCell.svelte +1 -0
  40. package/src/components/grid/cells/RelationshipCell.svelte +1 -2
  41. package/src/components/grid/cells/TextCell.svelte +3 -0
  42. package/src/components/grid/controls/MigrationModal.svelte +5 -5
  43. package/src/components/grid/layout/Grid.svelte +5 -8
  44. package/src/components/grid/lib/constants.js +1 -1
  45. package/src/components/grid/lib/{events.js → events.ts} +3 -3
  46. package/src/components/grid/lib/utils.js +2 -0
  47. package/src/components/grid/lib/utils.ts +32 -0
  48. package/src/components/grid/stores/bounds.ts +29 -0
  49. package/src/components/grid/stores/{cache.js → cache.ts} +21 -6
  50. package/src/components/grid/stores/{clipboard.js → clipboard.ts} +55 -19
  51. package/src/components/grid/stores/{columns.js → columns.ts} +47 -19
  52. package/src/components/grid/stores/{conditions.js → conditions.ts} +32 -12
  53. package/src/components/grid/stores/{config.js → config.ts} +16 -6
  54. package/src/components/grid/stores/{datasource.js → datasource.ts} +86 -36
  55. package/src/components/grid/stores/datasources/index.ts +31 -0
  56. package/src/components/grid/stores/datasources/{nonPlus.js → nonPlus.ts} +21 -11
  57. package/src/components/grid/stores/datasources/{table.js → table.ts} +39 -21
  58. package/src/components/grid/stores/datasources/{viewV2.js → viewV2.ts} +74 -28
  59. package/src/components/grid/stores/{filter.js → filter.ts} +39 -16
  60. package/src/components/grid/stores/index.ts +143 -0
  61. package/src/components/grid/stores/{menu.js → menu.ts} +31 -6
  62. package/src/components/grid/stores/{notifications.js → notifications.ts} +12 -2
  63. package/src/components/grid/stores/{pagination.js → pagination.ts} +2 -1
  64. package/src/components/grid/stores/{reorder.js → reorder.ts} +47 -15
  65. package/src/components/grid/stores/{resize.js → resize.ts} +28 -10
  66. package/src/components/grid/stores/{rows.js → rows.ts} +167 -53
  67. package/src/components/grid/stores/{scroll.js → scroll.ts} +28 -5
  68. package/src/components/grid/stores/{sort.js → sort.ts} +13 -3
  69. package/src/components/grid/stores/{ui.js → ui.ts} +77 -20
  70. package/src/components/grid/stores/{users.js → users.ts} +36 -9
  71. package/src/components/grid/stores/{validation.js → validation.ts} +35 -12
  72. package/src/components/grid/stores/{viewport.js → viewport.ts} +14 -3
  73. package/src/{constants.js → constants.ts} +2 -2
  74. package/src/fetch/QueryFetch.js +2 -2
  75. package/src/fetch/RelationshipFetch.js +9 -6
  76. package/src/fetch/TableFetch.js +1 -2
  77. package/src/fetch/ViewFetch.js +1 -1
  78. package/src/fetch/ViewV2Fetch.js +1 -2
  79. package/src/utils/memo.d.ts +10 -0
  80. package/src/utils/relatedColumns.ts +126 -0
  81. package/tsconfig.json +14 -0
  82. package/src/api/ai.js +0 -11
  83. package/src/api/analytics.js +0 -17
  84. package/src/api/attachments.js +0 -78
  85. package/src/api/auditLogs.js +0 -63
  86. package/src/api/automations.js +0 -111
  87. package/src/api/backups.js +0 -46
  88. package/src/api/datasources.js +0 -92
  89. package/src/api/environmentVariables.js +0 -36
  90. package/src/api/events.js +0 -13
  91. package/src/api/flags.js +0 -34
  92. package/src/api/hosting.js +0 -19
  93. package/src/api/layouts.js +0 -23
  94. package/src/api/licensing.js +0 -75
  95. package/src/api/migrations.js +0 -10
  96. package/src/api/relationships.js +0 -21
  97. package/src/api/routes.js +0 -19
  98. package/src/api/rows.js +0 -117
  99. package/src/api/screens.js +0 -23
  100. package/src/api/tables.js +0 -152
  101. package/src/api/templates.js +0 -35
  102. package/src/components/grid/stores/bounds.js +0 -16
  103. package/src/components/grid/stores/index.js +0 -73
  104. package/src/utils/relatedColumns.js +0 -103
  105. /package/src/{index.js → index.ts} +0 -0
  106. /package/src/utils/{index.js → index.ts} +0 -0
@@ -1,12 +1,32 @@
1
- import { get, derived } from "svelte/store"
2
- import { FieldType, UILogicalOperator } from "@budibase/types"
1
+ import { get, derived, Writable, Readable } from "svelte/store"
2
+ import {
3
+ ArrayOperator,
4
+ BasicOperator,
5
+ FieldType,
6
+ UIColumn,
7
+ UILegacyFilter,
8
+ UILogicalOperator,
9
+ UISearchFilter,
10
+ } from "@budibase/types"
11
+ import { Store as StoreContext } from "."
3
12
  import { memo } from "../../../utils/memo"
4
13
 
5
- export const createStores = context => {
14
+ export interface FilterStore {
15
+ filter: Writable<UISearchFilter | undefined>
16
+ inlineFilters: Writable<UILegacyFilter[]>
17
+ }
18
+
19
+ export interface FilterDerivedStore {
20
+ allFilters: Readable<UISearchFilter | undefined>
21
+ }
22
+
23
+ export type Store = FilterStore & FilterDerivedStore
24
+
25
+ export const createStores = (context: StoreContext): FilterStore => {
6
26
  const { props } = context
7
27
 
8
28
  // Initialise to default props
9
- const filter = memo(get(props).initialFilter)
29
+ const filter = memo(get(props).initialFilter ?? undefined)
10
30
  const inlineFilters = memo([])
11
31
 
12
32
  return {
@@ -15,7 +35,7 @@ export const createStores = context => {
15
35
  }
16
36
  }
17
37
 
18
- export const deriveStores = context => {
38
+ export const deriveStores = (context: StoreContext): FilterDerivedStore => {
19
39
  const { filter, inlineFilters } = context
20
40
  const allFilters = derived(
21
41
  [filter, inlineFilters],
@@ -24,7 +44,7 @@ export const deriveStores = context => {
24
44
  if (!$inlineFilters?.length) {
25
45
  return $filter
26
46
  }
27
- let allFilters = {
47
+ const allFilters: UISearchFilter = {
28
48
  logicalOperator: UILogicalOperator.ALL,
29
49
  groups: [
30
50
  {
@@ -33,12 +53,13 @@ export const deriveStores = context => {
33
53
  },
34
54
  ],
35
55
  }
56
+
36
57
  // Just use inline if no filter
37
58
  if (!$filter?.groups?.length) {
38
59
  return allFilters
39
60
  }
40
61
  // Join them together if both
41
- allFilters.groups = [...allFilters.groups, ...$filter.groups]
62
+ allFilters.groups = [...allFilters.groups!, ...$filter.groups]
42
63
  return allFilters
43
64
  }
44
65
  )
@@ -48,16 +69,16 @@ export const deriveStores = context => {
48
69
  }
49
70
  }
50
71
 
51
- export const createActions = context => {
72
+ export const createActions = (context: StoreContext) => {
52
73
  const { filter, inlineFilters } = context
53
74
 
54
- const addInlineFilter = (column, value) => {
75
+ const addInlineFilter = (column: UIColumn, value: string) => {
55
76
  const filterId = `inline-${column.name}`
56
77
  const type = column.schema.type
57
- let inlineFilter = {
78
+ const inlineFilter: UILegacyFilter = {
58
79
  field: column.name,
59
80
  id: filterId,
60
- operator: "string",
81
+ operator: BasicOperator.STRING,
61
82
  valueType: "value",
62
83
  type,
63
84
  value,
@@ -66,11 +87,11 @@ export const createActions = context => {
66
87
  // Add overrides specific so the certain column type
67
88
  if (type === FieldType.NUMBER) {
68
89
  inlineFilter.value = parseFloat(value)
69
- inlineFilter.operator = "equal"
90
+ inlineFilter.operator = BasicOperator.EQUAL
70
91
  } else if (type === FieldType.BIGINT) {
71
- inlineFilter.operator = "equal"
92
+ inlineFilter.operator = BasicOperator.EQUAL
72
93
  } else if (type === FieldType.ARRAY) {
73
- inlineFilter.operator = "contains"
94
+ inlineFilter.operator = ArrayOperator.CONTAINS
74
95
  }
75
96
 
76
97
  inlineFilters.update($inlineFilters => {
@@ -95,9 +116,11 @@ export const createActions = context => {
95
116
  }
96
117
  }
97
118
 
98
- export const initialise = context => {
119
+ export const initialise = (context: StoreContext) => {
99
120
  const { filter, initialFilter } = context
100
121
 
101
122
  // Reset filter when initial filter prop changes
102
- initialFilter.subscribe(filter.set)
123
+ initialFilter.subscribe($initialFilter =>
124
+ filter.set($initialFilter ?? undefined)
125
+ )
103
126
  }
@@ -0,0 +1,143 @@
1
+ import { Writable } from "svelte/store"
2
+ import type { APIClient } from "../../../api/types"
3
+
4
+ import * as Bounds from "./bounds"
5
+ import * as Columns from "./columns"
6
+ import * as Menu from "./menu"
7
+ import * as Pagination from "./pagination"
8
+ import * as Reorder from "./reorder"
9
+ import * as Resize from "./resize"
10
+ import * as Rows from "./rows"
11
+ import * as Scroll from "./scroll"
12
+ import * as UI from "./ui"
13
+ import * as Users from "./users"
14
+ import * as Validation from "./validation"
15
+ import * as Viewport from "./viewport"
16
+ import * as Clipboard from "./clipboard"
17
+ import * as Config from "./config"
18
+ import * as Sort from "./sort"
19
+ import * as Filter from "./filter"
20
+ import * as Notifications from "./notifications"
21
+ import * as Datasource from "./datasource"
22
+ import * as Table from "./datasources/table"
23
+ import * as ViewV2 from "./datasources/viewV2"
24
+ import * as NonPlus from "./datasources/nonPlus"
25
+ import * as Cache from "./cache"
26
+ import * as Conditions from "./conditions"
27
+ import { SortOrder, UIDatasource, UISearchFilter } from "@budibase/types"
28
+ import * as Constants from "../lib/constants"
29
+
30
+ const DependencyOrderedStores = [
31
+ Sort,
32
+ Filter,
33
+ Bounds,
34
+ Table,
35
+ ViewV2,
36
+ NonPlus,
37
+ Datasource,
38
+ Columns,
39
+ Scroll,
40
+ Validation,
41
+ Rows,
42
+ Conditions,
43
+ UI,
44
+ Resize,
45
+ Viewport,
46
+ Reorder,
47
+ Users,
48
+ Menu,
49
+ Pagination,
50
+ Config as any,
51
+ Clipboard,
52
+ Notifications,
53
+ Cache,
54
+ ]
55
+
56
+ export interface BaseStoreProps {
57
+ datasource: UIDatasource
58
+ initialSortColumn: string | null
59
+ initialSortOrder: SortOrder | null
60
+ initialFilter: UISearchFilter | null
61
+ fixedRowHeight: number | null
62
+ schemaOverrides: Record<
63
+ string,
64
+ {
65
+ displayName?: string
66
+ disabled?: boolean
67
+ }
68
+ > | null
69
+ notifySuccess: (message: string) => void
70
+ notifyError: (message: string) => void
71
+ canAddRows?: boolean
72
+ canEditRows?: boolean
73
+ canDeleteRows?: boolean
74
+ canEditColumns?: boolean
75
+ canExpandRows?: boolean
76
+ canSaveSchema?: boolean
77
+ minHeight?: number
78
+ }
79
+
80
+ export interface BaseStore {
81
+ API: APIClient
82
+ gridID: string
83
+ props: Writable<BaseStoreProps>
84
+ subscribe: any
85
+ dispatch: (event: string, data: any) => any
86
+ Constants: typeof Constants
87
+ }
88
+
89
+ export type Store = BaseStore &
90
+ Columns.Store &
91
+ Table.Store &
92
+ ViewV2.Store &
93
+ NonPlus.Store &
94
+ Datasource.Store &
95
+ Validation.Store &
96
+ Users.Store &
97
+ Menu.Store &
98
+ Filter.Store &
99
+ UI.Store &
100
+ Clipboard.Store &
101
+ Scroll.Store &
102
+ Rows.Store &
103
+ Reorder.Store &
104
+ Resize.Store &
105
+ Config.Store &
106
+ Conditions.Store &
107
+ Cache.Store &
108
+ Viewport.Store &
109
+ Notifications.Store &
110
+ Sort.Store &
111
+ Bounds.Store
112
+
113
+ export const attachStores = (context: BaseStore): Store => {
114
+ // Atomic store creation
115
+ for (let store of DependencyOrderedStores) {
116
+ if ("createStores" in store) {
117
+ context = { ...context, ...store.createStores?.(context) }
118
+ }
119
+ }
120
+
121
+ // Derived store creation
122
+ for (let store of DependencyOrderedStores) {
123
+ if ("deriveStores" in store) {
124
+ context = { ...context, ...store.deriveStores?.(context) }
125
+ }
126
+ }
127
+
128
+ // Action creation
129
+ for (let store of DependencyOrderedStores) {
130
+ if ("createActions" in store) {
131
+ context = { ...context, ...store.createActions?.(context) }
132
+ }
133
+ }
134
+
135
+ // Initialise any store logic
136
+ for (let store of DependencyOrderedStores) {
137
+ if ("initialise" in store) {
138
+ store.initialise?.(context)
139
+ }
140
+ }
141
+
142
+ return context as Store
143
+ }
@@ -1,8 +1,33 @@
1
- import { writable, get } from "svelte/store"
1
+ import { writable, get, Writable } from "svelte/store"
2
+
3
+ import { Store as StoreContext } from "."
2
4
  import { parseCellID } from "../lib/utils"
3
5
 
6
+ interface MenuStoreData {
7
+ left: number
8
+ top: number
9
+ visible: boolean
10
+ multiRowMode: boolean
11
+ multiCellMode: boolean
12
+ }
13
+
14
+ interface MenuStore {
15
+ menu: Writable<MenuStoreData>
16
+ }
17
+
18
+ interface MenuActions {
19
+ menu: MenuStore["menu"] & {
20
+ actions: {
21
+ open: (cellId: string, e: MouseEvent) => void
22
+ close: () => void
23
+ }
24
+ }
25
+ }
26
+
27
+ export type Store = MenuStore & MenuActions
28
+
4
29
  export const createStores = () => {
5
- const menu = writable({
30
+ const menu = writable<MenuStoreData>({
6
31
  left: 0,
7
32
  top: 0,
8
33
  visible: false,
@@ -14,7 +39,7 @@ export const createStores = () => {
14
39
  }
15
40
  }
16
41
 
17
- export const createActions = context => {
42
+ export const createActions = (context: StoreContext): MenuActions => {
18
43
  const {
19
44
  menu,
20
45
  focusedCellId,
@@ -25,7 +50,7 @@ export const createActions = context => {
25
50
  selectedCellCount,
26
51
  } = context
27
52
 
28
- const open = (cellId, e) => {
53
+ const open = (cellId: string, e: MouseEvent) => {
29
54
  e.preventDefault()
30
55
  e.stopPropagation()
31
56
 
@@ -37,14 +62,14 @@ export const createActions = context => {
37
62
  }
38
63
 
39
64
  // Compute bounds of cell relative to outer data node
40
- const targetBounds = e.target.getBoundingClientRect()
65
+ const targetBounds = (e.target as HTMLElement).getBoundingClientRect()
41
66
  const dataBounds = dataNode.getBoundingClientRect()
42
67
 
43
68
  // Check if there are multiple rows selected, and if this is one of them
44
69
  let multiRowMode = false
45
70
  if (get(selectedRowCount) > 1) {
46
71
  const { rowId } = parseCellID(cellId)
47
- if (get(selectedRows)[rowId]) {
72
+ if (rowId !== undefined && get(selectedRows)[rowId]) {
48
73
  multiRowMode = true
49
74
  }
50
75
  }
@@ -1,7 +1,17 @@
1
1
  import { notifications as BBUINotifications } from "@budibase/bbui"
2
- import { derived } from "svelte/store"
2
+ import { derived, Readable } from "svelte/store"
3
+ import { Store as StoreContext } from "."
3
4
 
4
- export const createStores = context => {
5
+ interface NotificationStore {
6
+ notifications: Readable<{
7
+ success: (message: string) => void
8
+ error: (message: string) => void
9
+ }>
10
+ }
11
+
12
+ export type Store = NotificationStore
13
+
14
+ export const createStores = (context: StoreContext): NotificationStore => {
5
15
  const { notifySuccess, notifyError } = context
6
16
 
7
17
  // Normally we would not derive a store in "createStores" as it should be
@@ -1,6 +1,7 @@
1
1
  import { derived } from "svelte/store"
2
+ import { Store as StoreContext } from "."
2
3
 
3
- export const initialise = context => {
4
+ export const initialise = (context: StoreContext) => {
4
5
  const { scrolledRowCount, rows, visualRowCapacity } = context
5
6
 
6
7
  // Derive how many rows we have in total
@@ -1,7 +1,24 @@
1
- import { get, writable, derived } from "svelte/store"
1
+ import { get, writable, derived, Writable, Readable } from "svelte/store"
2
2
  import { parseEventLocation } from "../lib/utils"
3
+ import { Store as StoreContext } from "."
3
4
 
4
- const reorderInitialState = {
5
+ interface Breakpoint {
6
+ x: number
7
+ column: string
8
+ insertAfter: boolean
9
+ }
10
+
11
+ interface ReorderInitialStoreData {
12
+ sourceColumn: string | null
13
+ targetColumn: string | null
14
+ insertAfter?: boolean
15
+ breakpoints: Breakpoint[]
16
+ gridLeft: number
17
+ width: number
18
+ increment?: number
19
+ }
20
+
21
+ const reorderInitialState: ReorderInitialStoreData = {
5
22
  sourceColumn: null,
6
23
  targetColumn: null,
7
24
  insertAfter: false,
@@ -11,7 +28,14 @@ const reorderInitialState = {
11
28
  increment: 0,
12
29
  }
13
30
 
14
- export const createStores = () => {
31
+ interface ReorderInitialStore {
32
+ reorder: Writable<ReorderInitialStoreData>
33
+ isReordering: Readable<boolean>
34
+ }
35
+
36
+ export type Store = ReorderInitialStore
37
+
38
+ export const createStores = (): ReorderInitialStore => {
15
39
  const reorder = writable(reorderInitialState)
16
40
  const isReordering = derived(
17
41
  reorder,
@@ -24,7 +48,7 @@ export const createStores = () => {
24
48
  }
25
49
  }
26
50
 
27
- export const createActions = context => {
51
+ export const createActions = (context: StoreContext) => {
28
52
  const {
29
53
  reorder,
30
54
  columns,
@@ -40,11 +64,11 @@ export const createActions = context => {
40
64
  maxScrollLeft,
41
65
  } = context
42
66
  let latestX = 0
43
- let autoScrollInterval
44
- let isAutoScrolling
67
+ let autoScrollInterval: NodeJS.Timeout
68
+ let isAutoScrolling: boolean
45
69
 
46
70
  // Callback when dragging on a colum header and starting reordering
47
- const startReordering = (column, e) => {
71
+ const startReordering = (column: string, e: MouseEvent | TouchEvent) => {
48
72
  const $scrollableColumns = get(scrollableColumns)
49
73
  const $bounds = get(bounds)
50
74
  const $stickyWidth = get(stickyWidth)
@@ -87,7 +111,7 @@ export const createActions = context => {
87
111
  }
88
112
 
89
113
  // Callback when moving the mouse when reordering columns
90
- const onReorderMouseMove = e => {
114
+ const onReorderMouseMove = (e: MouseEvent | TouchEvent) => {
91
115
  // Immediately handle the current position
92
116
  const { x } = parseEventLocation(e)
93
117
  latestX = x
@@ -122,7 +146,7 @@ export const createActions = context => {
122
146
  const $scrollLeft = get(scrollLeft)
123
147
 
124
148
  // Compute the closest breakpoint to the current position
125
- let breakpoint
149
+ let breakpoint: Breakpoint | undefined
126
150
  let minDistance = Number.MAX_SAFE_INTEGER
127
151
  const mouseX = latestX - $reorder.gridLeft + $scrollLeft
128
152
  $reorder.breakpoints.forEach(point => {
@@ -139,8 +163,8 @@ export const createActions = context => {
139
163
  ) {
140
164
  reorder.update(state => ({
141
165
  ...state,
142
- targetColumn: breakpoint.column,
143
- insertAfter: breakpoint.insertAfter,
166
+ targetColumn: breakpoint!.column,
167
+ insertAfter: breakpoint!.insertAfter,
144
168
  }))
145
169
  }
146
170
  }
@@ -157,7 +181,7 @@ export const createActions = context => {
157
181
  const { increment } = get(reorder)
158
182
  scroll.update(state => ({
159
183
  ...state,
160
- left: Math.max(0, Math.min($maxLeft, state.left + increment)),
184
+ left: Math.max(0, Math.min($maxLeft, state.left + increment!)),
161
185
  }))
162
186
  considerReorderPosition()
163
187
  }, 10)
@@ -185,7 +209,11 @@ export const createActions = context => {
185
209
  const { sourceColumn, targetColumn, insertAfter } = get(reorder)
186
210
  reorder.set(reorderInitialState)
187
211
  if (sourceColumn !== targetColumn) {
188
- await moveColumn({ sourceColumn, targetColumn, insertAfter })
212
+ await moveColumn({
213
+ sourceColumn: sourceColumn!,
214
+ targetColumn: targetColumn!,
215
+ insertAfter,
216
+ })
189
217
  }
190
218
  }
191
219
 
@@ -195,6 +223,10 @@ export const createActions = context => {
195
223
  sourceColumn,
196
224
  targetColumn,
197
225
  insertAfter = false,
226
+ }: {
227
+ sourceColumn: string
228
+ targetColumn: string
229
+ insertAfter?: boolean
198
230
  }) => {
199
231
  // Find the indices in the overall columns array
200
232
  const $columns = get(columns)
@@ -232,7 +264,7 @@ export const createActions = context => {
232
264
  }
233
265
 
234
266
  // Moves a column one place left (as appears visually)
235
- const moveColumnLeft = async column => {
267
+ const moveColumnLeft = async (column: string) => {
236
268
  const $visibleColumns = get(visibleColumns)
237
269
  const $columnLookupMap = get(columnLookupMap)
238
270
  const sourceIdx = $columnLookupMap[column].__idx
@@ -243,7 +275,7 @@ export const createActions = context => {
243
275
  }
244
276
 
245
277
  // Moves a column one place right (as appears visually)
246
- const moveColumnRight = async column => {
278
+ const moveColumnRight = async (column: string) => {
247
279
  const $visibleColumns = get(visibleColumns)
248
280
  const $columnLookupMap = get(columnLookupMap)
249
281
  const sourceIdx = $columnLookupMap[column].__idx
@@ -1,8 +1,19 @@
1
- import { writable, get, derived } from "svelte/store"
1
+ import { writable, get, derived, Writable, Readable } from "svelte/store"
2
2
  import { MinColumnWidth, DefaultColumnWidth } from "../lib/constants"
3
3
  import { parseEventLocation } from "../lib/utils"
4
+ import { Store as StoreContext } from "."
5
+ import { UIColumn } from "@budibase/types"
4
6
 
5
- const initialState = {
7
+ interface ResizeInitialStoreData {
8
+ initialMouseX: number | null
9
+ initialWidth: number | null
10
+ column: string | null
11
+ width: number
12
+ left: number
13
+ related?: UIColumn["related"]
14
+ }
15
+
16
+ const initialState: ResizeInitialStoreData = {
6
17
  initialMouseX: null,
7
18
  initialWidth: null,
8
19
  column: null,
@@ -10,7 +21,14 @@ const initialState = {
10
21
  left: 0,
11
22
  }
12
23
 
13
- export const createStores = () => {
24
+ interface ResizeInitialStore {
25
+ resize: Writable<ResizeInitialStoreData>
26
+ isResizing: Readable<boolean>
27
+ }
28
+
29
+ export type Store = ResizeInitialStore
30
+
31
+ export const createStores = (): ResizeInitialStore => {
14
32
  const resize = writable(initialState)
15
33
  const isResizing = derived(resize, $resize => $resize.column != null, false)
16
34
  return {
@@ -19,11 +37,11 @@ export const createStores = () => {
19
37
  }
20
38
  }
21
39
 
22
- export const createActions = context => {
40
+ export const createActions = (context: StoreContext) => {
23
41
  const { resize, ui, datasource } = context
24
42
 
25
43
  // Starts resizing a certain column
26
- const startResizing = (column, e) => {
44
+ const startResizing = (column: UIColumn, e: MouseEvent | TouchEvent) => {
27
45
  const { x } = parseEventLocation(e)
28
46
 
29
47
  // Prevent propagation to stop reordering triggering
@@ -50,11 +68,11 @@ export const createActions = context => {
50
68
  }
51
69
 
52
70
  // Handler for moving the mouse to resize columns
53
- const onResizeMouseMove = e => {
71
+ const onResizeMouseMove = (e: MouseEvent | TouchEvent) => {
54
72
  const { initialMouseX, initialWidth, width, column, related } = get(resize)
55
73
  const { x } = parseEventLocation(e)
56
- const dx = x - initialMouseX
57
- const newWidth = Math.round(Math.max(MinColumnWidth, initialWidth + dx))
74
+ const dx = x - initialMouseX!
75
+ const newWidth = Math.round(Math.max(MinColumnWidth, initialWidth! + dx))
58
76
 
59
77
  // Ignore small changes
60
78
  if (Math.abs(width - newWidth) < 5) {
@@ -63,7 +81,7 @@ export const createActions = context => {
63
81
 
64
82
  // Update column state
65
83
  if (!related) {
66
- datasource.actions.addSchemaMutation(column, { width })
84
+ datasource.actions.addSchemaMutation(column!, { width })
67
85
  } else {
68
86
  datasource.actions.addSubSchemaMutation(related.subField, related.field, {
69
87
  width,
@@ -95,7 +113,7 @@ export const createActions = context => {
95
113
  }
96
114
 
97
115
  // Resets a column size back to default
98
- const resetSize = async column => {
116
+ const resetSize = async (column: { name: string }) => {
99
117
  datasource.actions.addSchemaMutation(column.name, {
100
118
  width: DefaultColumnWidth,
101
119
  })