@budibase/frontend-core 2.5.6-alpha.9 → 2.5.7

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 (64) hide show
  1. package/package.json +4 -6
  2. package/src/components/index.js +0 -1
  3. package/src/constants.js +0 -1
  4. package/src/fetch/DataFetch.js +21 -27
  5. package/src/fetch/QueryFetch.js +1 -1
  6. package/src/themes/midnight.css +0 -3
  7. package/src/themes/nord.css +0 -3
  8. package/src/utils/utils.js +0 -20
  9. package/src/components/grid/cells/AttachmentCell.svelte +0 -153
  10. package/src/components/grid/cells/BooleanCell.svelte +0 -44
  11. package/src/components/grid/cells/DataCell.svelte +0 -86
  12. package/src/components/grid/cells/DateCell.svelte +0 -77
  13. package/src/components/grid/cells/FormulaCell.svelte +0 -5
  14. package/src/components/grid/cells/GridCell.svelte +0 -159
  15. package/src/components/grid/cells/HeaderCell.svelte +0 -237
  16. package/src/components/grid/cells/JSONCell.svelte +0 -36
  17. package/src/components/grid/cells/LongFormCell.svelte +0 -117
  18. package/src/components/grid/cells/MultiSelectCell.svelte +0 -7
  19. package/src/components/grid/cells/NumberCell.svelte +0 -7
  20. package/src/components/grid/cells/OptionsCell.svelte +0 -239
  21. package/src/components/grid/cells/RelationshipCell.svelte +0 -503
  22. package/src/components/grid/cells/TextCell.svelte +0 -110
  23. package/src/components/grid/controls/AddColumnButton.svelte +0 -16
  24. package/src/components/grid/controls/AddRowButton.svelte +0 -18
  25. package/src/components/grid/controls/BetaButton.svelte +0 -46
  26. package/src/components/grid/controls/DeleteButton.svelte +0 -72
  27. package/src/components/grid/controls/HideColumnsButton.svelte +0 -91
  28. package/src/components/grid/controls/RowHeightButton.svelte +0 -70
  29. package/src/components/grid/controls/SortButton.svelte +0 -107
  30. package/src/components/grid/index.js +0 -1
  31. package/src/components/grid/layout/Avatar.svelte +0 -24
  32. package/src/components/grid/layout/Grid.svelte +0 -250
  33. package/src/components/grid/layout/GridBody.svelte +0 -38
  34. package/src/components/grid/layout/GridRow.svelte +0 -57
  35. package/src/components/grid/layout/GridScrollWrapper.svelte +0 -84
  36. package/src/components/grid/layout/HeaderRow.svelte +0 -30
  37. package/src/components/grid/layout/NewRowTop.svelte +0 -247
  38. package/src/components/grid/layout/RowCount.svelte +0 -9
  39. package/src/components/grid/layout/StickyColumn.svelte +0 -245
  40. package/src/components/grid/layout/UserAvatars.svelte +0 -20
  41. package/src/components/grid/lib/constants.js +0 -11
  42. package/src/components/grid/lib/events.js +0 -29
  43. package/src/components/grid/lib/renderers.js +0 -29
  44. package/src/components/grid/lib/utils.js +0 -26
  45. package/src/components/grid/lib/websocket.js +0 -63
  46. package/src/components/grid/overlays/KeyboardManager.svelte +0 -180
  47. package/src/components/grid/overlays/MenuOverlay.svelte +0 -95
  48. package/src/components/grid/overlays/ReorderOverlay.svelte +0 -63
  49. package/src/components/grid/overlays/ResizeOverlay.svelte +0 -70
  50. package/src/components/grid/overlays/ScrollOverlay.svelte +0 -121
  51. package/src/components/grid/stores/bounds.js +0 -16
  52. package/src/components/grid/stores/clipboard.js +0 -34
  53. package/src/components/grid/stores/columns.js +0 -206
  54. package/src/components/grid/stores/index.js +0 -48
  55. package/src/components/grid/stores/menu.js +0 -49
  56. package/src/components/grid/stores/pagination.js +0 -24
  57. package/src/components/grid/stores/reorder.js +0 -155
  58. package/src/components/grid/stores/resize.js +0 -124
  59. package/src/components/grid/stores/rows.js +0 -462
  60. package/src/components/grid/stores/scroll.js +0 -201
  61. package/src/components/grid/stores/ui.js +0 -168
  62. package/src/components/grid/stores/users.js +0 -115
  63. package/src/components/grid/stores/validation.js +0 -45
  64. package/src/components/grid/stores/viewport.js +0 -141
@@ -1,168 +0,0 @@
1
- import { writable, get, derived } from "svelte/store"
2
- import {
3
- DefaultRowHeight,
4
- LargeRowHeight,
5
- MediumRowHeight,
6
- } from "../lib/constants"
7
-
8
- export const createStores = () => {
9
- const focusedCellId = writable(null)
10
- const focusedCellAPI = writable(null)
11
- const selectedRows = writable({})
12
- const hoveredRowId = writable(null)
13
- const rowHeight = writable(DefaultRowHeight)
14
- const previousFocusedRowId = writable(null)
15
-
16
- // Derive the current focused row ID
17
- const focusedRowId = derived(
18
- focusedCellId,
19
- $focusedCellId => {
20
- return $focusedCellId?.split("-")[0]
21
- },
22
- null
23
- )
24
-
25
- return {
26
- focusedCellId,
27
- focusedCellAPI,
28
- focusedRowId,
29
- previousFocusedRowId,
30
- selectedRows,
31
- hoveredRowId,
32
- rowHeight,
33
- }
34
- }
35
-
36
- export const deriveStores = context => {
37
- const {
38
- focusedCellId,
39
- selectedRows,
40
- hoveredRowId,
41
- enrichedRows,
42
- rowLookupMap,
43
- rowHeight,
44
- } = context
45
-
46
- // Derive the row that contains the selected cell
47
- const focusedRow = derived(
48
- [focusedCellId, rowLookupMap, enrichedRows],
49
- ([$focusedCellId, $rowLookupMap, $enrichedRows]) => {
50
- const rowId = $focusedCellId?.split("-")[0]
51
-
52
- if (rowId === "new") {
53
- // Edge case for new row
54
- return { _id: rowId }
55
- } else {
56
- // All normal rows
57
- const index = $rowLookupMap[rowId]
58
- return $enrichedRows[index]
59
- }
60
- },
61
- null
62
- )
63
-
64
- // Callback when leaving the grid, deselecting all focussed or selected items
65
- const blur = () => {
66
- focusedCellId.set(null)
67
- selectedRows.set({})
68
- hoveredRowId.set(null)
69
- }
70
-
71
- const contentLines = derived(rowHeight, $rowHeight => {
72
- if ($rowHeight === LargeRowHeight) {
73
- return 3
74
- } else if ($rowHeight === MediumRowHeight) {
75
- return 2
76
- }
77
- return 1
78
- })
79
-
80
- return {
81
- focusedRow,
82
- contentLines,
83
- ui: {
84
- actions: {
85
- blur,
86
- },
87
- },
88
- }
89
- }
90
-
91
- export const initialise = context => {
92
- const {
93
- focusedRowId,
94
- previousFocusedRowId,
95
- rows,
96
- focusedCellId,
97
- selectedRows,
98
- hoveredRowId,
99
- table,
100
- rowHeight,
101
- } = context
102
-
103
- // Ensure we clear invalid rows from state if they disappear
104
- rows.subscribe(() => {
105
- const $focusedCellId = get(focusedCellId)
106
- const $selectedRows = get(selectedRows)
107
- const $hoveredRowId = get(hoveredRowId)
108
- const hasRow = rows.actions.hasRow
109
-
110
- // Check selected cell
111
- const selectedRowId = $focusedCellId?.split("-")[0]
112
- if (selectedRowId && !hasRow(selectedRowId)) {
113
- focusedCellId.set(null)
114
- }
115
-
116
- // Check hovered row
117
- if ($hoveredRowId && !hasRow($hoveredRowId)) {
118
- hoveredRowId.set(null)
119
- }
120
-
121
- // Check selected rows
122
- let newSelectedRows = { ...$selectedRows }
123
- let selectedRowsNeedsUpdate = false
124
- const selectedIds = Object.keys($selectedRows)
125
- for (let i = 0; i < selectedIds.length; i++) {
126
- if (!hasRow(selectedIds[i])) {
127
- delete newSelectedRows[selectedIds[i]]
128
- selectedRowsNeedsUpdate = true
129
- }
130
- }
131
- if (selectedRowsNeedsUpdate) {
132
- selectedRows.set(newSelectedRows)
133
- }
134
- })
135
-
136
- // Remember the last focused row ID so that we can store the previous one
137
- let lastFocusedRowId = null
138
- focusedRowId.subscribe(id => {
139
- previousFocusedRowId.set(lastFocusedRowId)
140
- lastFocusedRowId = id
141
- })
142
-
143
- // Reset selected rows when selected cell changes
144
- focusedCellId.subscribe(id => {
145
- if (id) {
146
- selectedRows.set({})
147
- }
148
- })
149
-
150
- // Unset selected cell when rows are selected
151
- selectedRows.subscribe(rows => {
152
- if (Object.keys(rows || {}).length) {
153
- focusedCellId.set(null)
154
- }
155
- })
156
-
157
- // Remove hovered row when a cell is selected
158
- focusedCellId.subscribe(cell => {
159
- if (cell && get(hoveredRowId)) {
160
- hoveredRowId.set(null)
161
- }
162
- })
163
-
164
- // Pull row height from table
165
- table.subscribe($table => {
166
- rowHeight.set($table?.rowHeight || DefaultRowHeight)
167
- })
168
- }
@@ -1,115 +0,0 @@
1
- import { writable, get, derived } from "svelte/store"
2
-
3
- export const createStores = () => {
4
- const users = writable([])
5
- const userId = writable(null)
6
-
7
- // Enrich users with unique colours
8
- const enrichedUsers = derived(
9
- [users, userId],
10
- ([$users, $userId]) => {
11
- return (
12
- $users
13
- .slice()
14
- // Place current user first
15
- .sort((a, b) => {
16
- if (a.id === $userId) {
17
- return -1
18
- } else if (b.id === $userId) {
19
- return 1
20
- } else {
21
- return 0
22
- }
23
- })
24
- // Enrich users with colors
25
- .map((user, idx) => {
26
- // Generate random colour hue
27
- let hue = 1
28
- for (let i = 0; i < user.email.length && i < 5; i++) {
29
- hue *= user.email.charCodeAt(i + 1)
30
- hue /= 17
31
- }
32
- hue = hue % 360
33
- const color =
34
- idx === 0
35
- ? "var(--spectrum-global-color-blue-400)"
36
- : `hsl(${hue}, 50%, 40%)`
37
-
38
- // Generate friendly label
39
- let label = user.email
40
- if (user.firstName) {
41
- label = user.firstName
42
- if (user.lastName) {
43
- label += ` ${user.lastName}`
44
- }
45
- }
46
-
47
- return {
48
- ...user,
49
- color,
50
- label,
51
- }
52
- })
53
- )
54
- },
55
- []
56
- )
57
-
58
- return {
59
- users: {
60
- ...users,
61
- subscribe: enrichedUsers.subscribe,
62
- },
63
- userId,
64
- }
65
- }
66
-
67
- export const deriveStores = context => {
68
- const { users, userId } = context
69
-
70
- // Generate a lookup map of cell ID to the user that has it selected, to make
71
- // lookups inside cells extremely fast
72
- const selectedCellMap = derived(
73
- [users, userId],
74
- ([$enrichedUsers, $userId]) => {
75
- let map = {}
76
- $enrichedUsers.forEach(user => {
77
- if (user.focusedCellId && user.id !== $userId) {
78
- map[user.focusedCellId] = user
79
- }
80
- })
81
- return map
82
- },
83
- {}
84
- )
85
-
86
- const updateUser = user => {
87
- const $users = get(users)
88
- const index = $users.findIndex(x => x.id === user.id)
89
- if (index === -1) {
90
- users.set([...$users, user])
91
- } else {
92
- users.update(state => {
93
- state[index] = user
94
- return state.slice()
95
- })
96
- }
97
- }
98
-
99
- const removeUser = user => {
100
- users.update(state => {
101
- return state.filter(x => x.id !== user.id)
102
- })
103
- }
104
-
105
- return {
106
- users: {
107
- ...users,
108
- actions: {
109
- updateUser,
110
- removeUser,
111
- },
112
- },
113
- selectedCellMap,
114
- }
115
- }
@@ -1,45 +0,0 @@
1
- import { writable, get } from "svelte/store"
2
-
3
- export const createStores = () => {
4
- const validation = writable({})
5
-
6
- const setError = (cellId, error) => {
7
- if (!cellId) {
8
- return
9
- }
10
- validation.update(state => ({
11
- ...state,
12
- [cellId]: error,
13
- }))
14
- }
15
-
16
- return {
17
- validation: {
18
- ...validation,
19
- actions: {
20
- setError,
21
- },
22
- },
23
- }
24
- }
25
-
26
- export const initialise = context => {
27
- const { validation, previousFocusedRowId, columns, stickyColumn } = context
28
-
29
- // Remove validation errors from previous focused row
30
- previousFocusedRowId.subscribe(id => {
31
- if (id) {
32
- const $columns = get(columns)
33
- const $stickyColumn = get(stickyColumn)
34
- validation.update(state => {
35
- $columns.forEach(column => {
36
- state[`${id}-${column.name}`] = null
37
- })
38
- if ($stickyColumn) {
39
- state[`${id}-${$stickyColumn.name}`] = null
40
- }
41
- return state
42
- })
43
- }
44
- })
45
- }
@@ -1,141 +0,0 @@
1
- import { derived, get } from "svelte/store"
2
- import {
3
- MaxCellRenderHeight,
4
- MaxCellRenderWidthOverflow,
5
- ScrollBarSize,
6
- } from "../lib/constants"
7
-
8
- export const deriveStores = context => {
9
- const {
10
- rowHeight,
11
- visibleColumns,
12
- enrichedRows,
13
- scrollTop,
14
- scrollLeft,
15
- width,
16
- height,
17
- } = context
18
-
19
- // Derive visible rows
20
- // Split into multiple stores containing primitives to optimise invalidation
21
- // as much as possible
22
- const scrolledRowCount = derived(
23
- [scrollTop, rowHeight],
24
- ([$scrollTop, $rowHeight]) => {
25
- return Math.floor($scrollTop / $rowHeight)
26
- },
27
- 0
28
- )
29
- const visualRowCapacity = derived(
30
- [height, rowHeight],
31
- ([$height, $rowHeight]) => {
32
- return Math.ceil($height / $rowHeight) + 1
33
- },
34
- 0
35
- )
36
- const renderedRows = derived(
37
- [enrichedRows, scrolledRowCount, visualRowCapacity],
38
- ([$enrichedRows, $scrolledRowCount, $visualRowCapacity]) => {
39
- return $enrichedRows.slice(
40
- $scrolledRowCount,
41
- $scrolledRowCount + $visualRowCapacity
42
- )
43
- },
44
- []
45
- )
46
-
47
- // Derive visible columns
48
- const renderedColumns = derived(
49
- [visibleColumns, scrollLeft, width],
50
- ([$visibleColumns, $scrollLeft, $width]) => {
51
- if (!$visibleColumns.length) {
52
- return []
53
- }
54
- let startColIdx = 0
55
- let rightEdge = $visibleColumns[0].width
56
- while (
57
- rightEdge < $scrollLeft &&
58
- startColIdx < $visibleColumns.length - 1
59
- ) {
60
- startColIdx++
61
- rightEdge += $visibleColumns[startColIdx].width
62
- }
63
- let endColIdx = startColIdx + 1
64
- let leftEdge = rightEdge
65
- while (
66
- leftEdge < $width + $scrollLeft &&
67
- endColIdx < $visibleColumns.length
68
- ) {
69
- leftEdge += $visibleColumns[endColIdx].width
70
- endColIdx++
71
- }
72
- const nextRenderedColumns = $visibleColumns.slice(startColIdx, endColIdx)
73
-
74
- // Cautiously shrink the number of rendered columns.
75
- // This is to avoid rapidly shrinking and growing the visible column count
76
- // which results in remounting cells
77
- const currentCount = get(renderedColumns).length
78
- if (currentCount === nextRenderedColumns.length + 1) {
79
- return $visibleColumns.slice(startColIdx, endColIdx + 1)
80
- } else {
81
- return nextRenderedColumns
82
- }
83
- },
84
- []
85
- )
86
-
87
- const hiddenColumnsWidth = derived(
88
- [renderedColumns, visibleColumns],
89
- ([$renderedColumns, $visibleColumns]) => {
90
- const idx = $visibleColumns.findIndex(
91
- col => col.name === $renderedColumns[0]?.name
92
- )
93
- let width = 0
94
- if (idx > 0) {
95
- for (let i = 0; i < idx; i++) {
96
- width += $visibleColumns[i].width
97
- }
98
- }
99
- return width
100
- },
101
- 0
102
- )
103
-
104
- // Determine the row index at which we should start vertically inverting cell
105
- // dropdowns
106
- const rowVerticalInversionIndex = derived(
107
- [visualRowCapacity, rowHeight],
108
- ([$visualRowCapacity, $rowHeight]) => {
109
- return (
110
- $visualRowCapacity - Math.ceil(MaxCellRenderHeight / $rowHeight) - 2
111
- )
112
- }
113
- )
114
-
115
- // Determine the column index at which we should start horizontally inverting
116
- // cell dropdowns
117
- const columnHorizontalInversionIndex = derived(
118
- [renderedColumns, scrollLeft, width],
119
- ([$renderedColumns, $scrollLeft, $width]) => {
120
- const cutoff = $width + $scrollLeft - ScrollBarSize * 3
121
- let inversionIdx = $renderedColumns.length
122
- for (let i = $renderedColumns.length - 1; i >= 0; i--, inversionIdx--) {
123
- const rightEdge = $renderedColumns[i].left + $renderedColumns[i].width
124
- if (rightEdge + MaxCellRenderWidthOverflow < cutoff) {
125
- break
126
- }
127
- }
128
- return inversionIdx
129
- }
130
- )
131
-
132
- return {
133
- scrolledRowCount,
134
- visualRowCapacity,
135
- renderedRows,
136
- renderedColumns,
137
- hiddenColumnsWidth,
138
- rowVerticalInversionIndex,
139
- columnHorizontalInversionIndex,
140
- }
141
- }