@budibase/frontend-core 2.7.36-alpha.1 → 2.7.36
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.
- package/package.json +4 -4
- package/src/api/analytics.js +2 -2
- package/src/api/datasources.js +1 -15
- package/src/api/index.js +2 -16
- package/src/api/rows.js +1 -3
- package/src/components/grid/cells/AttachmentCell.svelte +1 -3
- package/src/components/grid/cells/GridCell.svelte +1 -1
- package/src/components/grid/cells/GutterCell.svelte +14 -9
- package/src/components/grid/cells/HeaderCell.svelte +5 -7
- package/src/components/grid/cells/LongFormCell.svelte +1 -1
- package/src/components/grid/cells/OptionsCell.svelte +5 -4
- package/src/components/grid/cells/RelationshipCell.svelte +11 -22
- package/src/components/grid/controls/AddColumnButton.svelte +1 -1
- package/src/components/grid/controls/BulkDeleteHandler.svelte +8 -2
- package/src/components/grid/controls/ColumnWidthButton.svelte +92 -0
- package/src/components/grid/controls/HideColumnsButton.svelte +4 -9
- package/src/components/grid/controls/RowHeightButton.svelte +71 -0
- package/src/components/grid/controls/SortButton.svelte +4 -3
- package/src/components/grid/layout/Grid.svelte +59 -66
- package/src/components/grid/layout/GridBody.svelte +2 -3
- package/src/components/grid/layout/GridRow.svelte +2 -3
- package/src/components/grid/layout/GridScrollWrapper.svelte +0 -6
- package/src/components/grid/layout/HeaderRow.svelte +3 -3
- package/src/components/grid/layout/NewRow.svelte +5 -37
- package/src/components/grid/layout/StickyColumn.svelte +8 -10
- package/src/components/grid/lib/constants.js +3 -4
- package/src/components/grid/lib/websocket.js +2 -3
- package/src/components/grid/overlays/KeyboardManager.svelte +0 -6
- package/src/components/grid/overlays/MenuOverlay.svelte +1 -3
- package/src/components/grid/overlays/ReorderOverlay.svelte +1 -1
- package/src/components/grid/overlays/ResizeOverlay.svelte +1 -1
- package/src/components/grid/overlays/ScrollOverlay.svelte +2 -25
- package/src/components/grid/stores/columns.js +6 -37
- package/src/components/grid/stores/index.js +0 -6
- package/src/components/grid/stores/menu.js +9 -15
- package/src/components/grid/stores/rows.js +16 -18
- package/src/components/grid/stores/scroll.js +7 -5
- package/src/components/grid/stores/ui.js +4 -19
- package/src/components/grid/stores/viewport.js +6 -17
- package/src/fetch/DataFetch.js +2 -4
- package/src/utils/index.js +0 -1
- package/src/components/grid/controls/SizeButton.svelte +0 -135
- package/src/components/grid/stores/config.js +0 -27
- package/src/components/grid/stores/filter.js +0 -19
- package/src/components/grid/stores/sort.js +0 -27
- package/src/utils/memo.js +0 -43
|
@@ -46,7 +46,7 @@ export const createStores = () => {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export const deriveStores = context => {
|
|
49
|
-
const { table, columns, stickyColumn, API, dispatch
|
|
49
|
+
const { table, columns, stickyColumn, API, dispatch } = context
|
|
50
50
|
|
|
51
51
|
// Updates the tables primary display column
|
|
52
52
|
const changePrimaryDisplay = async column => {
|
|
@@ -56,23 +56,6 @@ export const deriveStores = context => {
|
|
|
56
56
|
})
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
// Updates the width of all columns
|
|
60
|
-
const changeAllColumnWidths = async width => {
|
|
61
|
-
columns.update(state => {
|
|
62
|
-
return state.map(col => ({
|
|
63
|
-
...col,
|
|
64
|
-
width,
|
|
65
|
-
}))
|
|
66
|
-
})
|
|
67
|
-
if (get(stickyColumn)) {
|
|
68
|
-
stickyColumn.update(state => ({
|
|
69
|
-
...state,
|
|
70
|
-
width,
|
|
71
|
-
}))
|
|
72
|
-
}
|
|
73
|
-
await saveChanges()
|
|
74
|
-
}
|
|
75
|
-
|
|
76
59
|
// Persists column changes by saving metadata against table schema
|
|
77
60
|
const saveChanges = async () => {
|
|
78
61
|
const $columns = get(columns)
|
|
@@ -108,9 +91,7 @@ export const deriveStores = context => {
|
|
|
108
91
|
table.set(newTable)
|
|
109
92
|
|
|
110
93
|
// Update server
|
|
111
|
-
|
|
112
|
-
await API.saveTable(newTable)
|
|
113
|
-
}
|
|
94
|
+
await API.saveTable(newTable)
|
|
114
95
|
|
|
115
96
|
// Broadcast change to external state can be updated, as this change
|
|
116
97
|
// will not be received by the builder websocket because we caused it ourselves
|
|
@@ -124,19 +105,17 @@ export const deriveStores = context => {
|
|
|
124
105
|
saveChanges,
|
|
125
106
|
saveTable,
|
|
126
107
|
changePrimaryDisplay,
|
|
127
|
-
changeAllColumnWidths,
|
|
128
108
|
},
|
|
129
109
|
},
|
|
130
110
|
}
|
|
131
111
|
}
|
|
132
112
|
|
|
133
113
|
export const initialise = context => {
|
|
134
|
-
const { table, columns, stickyColumn, schemaOverrides
|
|
135
|
-
context
|
|
114
|
+
const { table, columns, stickyColumn, schemaOverrides } = context
|
|
136
115
|
|
|
137
116
|
const schema = derived(
|
|
138
|
-
[table, schemaOverrides
|
|
139
|
-
([$table, $schemaOverrides
|
|
117
|
+
[table, schemaOverrides],
|
|
118
|
+
([$table, $schemaOverrides]) => {
|
|
140
119
|
if (!$table?.schema) {
|
|
141
120
|
return null
|
|
142
121
|
}
|
|
@@ -163,16 +142,6 @@ export const initialise = context => {
|
|
|
163
142
|
}
|
|
164
143
|
}
|
|
165
144
|
})
|
|
166
|
-
|
|
167
|
-
// Apply whitelist if specified
|
|
168
|
-
if ($columnWhitelist?.length) {
|
|
169
|
-
Object.keys(newSchema).forEach(key => {
|
|
170
|
-
if (!$columnWhitelist.includes(key)) {
|
|
171
|
-
delete newSchema[key]
|
|
172
|
-
}
|
|
173
|
-
})
|
|
174
|
-
}
|
|
175
|
-
|
|
176
145
|
return newSchema
|
|
177
146
|
}
|
|
178
147
|
)
|
|
@@ -240,7 +209,7 @@ export const initialise = context => {
|
|
|
240
209
|
}
|
|
241
210
|
stickyColumn.set({
|
|
242
211
|
name: primaryDisplay,
|
|
243
|
-
label: $schema[primaryDisplay].
|
|
212
|
+
label: $schema[primaryDisplay].name || primaryDisplay,
|
|
244
213
|
schema: $schema[primaryDisplay],
|
|
245
214
|
width: $schema[primaryDisplay].width || DefaultColumnWidth,
|
|
246
215
|
visible: true,
|
|
@@ -11,14 +11,8 @@ import * as Users from "./users"
|
|
|
11
11
|
import * as Validation from "./validation"
|
|
12
12
|
import * as Viewport from "./viewport"
|
|
13
13
|
import * as Clipboard from "./clipboard"
|
|
14
|
-
import * as Config from "./config"
|
|
15
|
-
import * as Sort from "./sort"
|
|
16
|
-
import * as Filter from "./filter"
|
|
17
14
|
|
|
18
15
|
const DependencyOrderedStores = [
|
|
19
|
-
Config,
|
|
20
|
-
Sort,
|
|
21
|
-
Filter,
|
|
22
16
|
Bounds,
|
|
23
17
|
Scroll,
|
|
24
18
|
Rows,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { writable } from "svelte/store"
|
|
1
|
+
import { writable, get } from "svelte/store"
|
|
2
|
+
import { GutterWidth } from "../lib/constants"
|
|
2
3
|
|
|
3
4
|
export const createStores = () => {
|
|
4
5
|
const menu = writable({
|
|
@@ -13,25 +14,18 @@ export const createStores = () => {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export const deriveStores = context => {
|
|
16
|
-
const { menu, focusedCellId,
|
|
17
|
+
const { menu, bounds, focusedCellId, stickyColumn, rowHeight } = context
|
|
17
18
|
|
|
18
19
|
const open = (cellId, e) => {
|
|
20
|
+
const $bounds = get(bounds)
|
|
21
|
+
const $stickyColumn = get(stickyColumn)
|
|
22
|
+
const $rowHeight = get(rowHeight)
|
|
19
23
|
e.preventDefault()
|
|
20
|
-
|
|
21
|
-
// Get DOM node for grid data wrapper to compute relative position to
|
|
22
|
-
const gridNode = document.getElementById(`grid-${rand}`)
|
|
23
|
-
const dataNode = gridNode?.getElementsByClassName("grid-data-outer")?.[0]
|
|
24
|
-
if (!dataNode) {
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Compute bounds of cell relative to outer data node
|
|
29
|
-
const targetBounds = e.target.getBoundingClientRect()
|
|
30
|
-
const dataBounds = dataNode.getBoundingClientRect()
|
|
31
24
|
focusedCellId.set(cellId)
|
|
32
25
|
menu.set({
|
|
33
|
-
left:
|
|
34
|
-
|
|
26
|
+
left:
|
|
27
|
+
e.clientX - $bounds.left + GutterWidth + ($stickyColumn?.width || 0),
|
|
28
|
+
top: e.clientY - $bounds.top + $rowHeight,
|
|
35
29
|
visible: true,
|
|
36
30
|
})
|
|
37
31
|
}
|
|
@@ -4,13 +4,18 @@ import { notifications } from "@budibase/bbui"
|
|
|
4
4
|
import { NewRowID, RowPageSize } from "../lib/constants"
|
|
5
5
|
import { tick } from "svelte"
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const initialSortState = {
|
|
8
|
+
column: null,
|
|
9
|
+
order: "ascending",
|
|
10
|
+
}
|
|
8
11
|
|
|
9
12
|
export const createStores = () => {
|
|
10
13
|
const rows = writable([])
|
|
11
14
|
const table = writable(null)
|
|
15
|
+
const filter = writable([])
|
|
12
16
|
const loading = writable(false)
|
|
13
17
|
const loaded = writable(false)
|
|
18
|
+
const sort = writable(initialSortState)
|
|
14
19
|
const rowChangeCache = writable({})
|
|
15
20
|
const inProgressChanges = writable({})
|
|
16
21
|
const hasNextPage = writable(false)
|
|
@@ -42,8 +47,10 @@ export const createStores = () => {
|
|
|
42
47
|
rows,
|
|
43
48
|
rowLookupMap,
|
|
44
49
|
table,
|
|
50
|
+
filter,
|
|
45
51
|
loaded,
|
|
46
52
|
loading,
|
|
53
|
+
sort,
|
|
47
54
|
rowChangeCache,
|
|
48
55
|
inProgressChanges,
|
|
49
56
|
hasNextPage,
|
|
@@ -91,18 +98,15 @@ export const deriveStores = context => {
|
|
|
91
98
|
// Reset everything when table ID changes
|
|
92
99
|
let unsubscribe = null
|
|
93
100
|
let lastResetKey = null
|
|
94
|
-
tableId.subscribe(
|
|
101
|
+
tableId.subscribe($tableId => {
|
|
95
102
|
// Unsub from previous fetch if one exists
|
|
96
103
|
unsubscribe?.()
|
|
97
104
|
fetch.set(null)
|
|
98
105
|
instanceLoaded.set(false)
|
|
99
106
|
loading.set(true)
|
|
100
107
|
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
await tick()
|
|
104
|
-
const $filter = get(filter)
|
|
105
|
-
const $sort = get(sort)
|
|
108
|
+
// Reset state
|
|
109
|
+
filter.set([])
|
|
106
110
|
|
|
107
111
|
// Create new fetch model
|
|
108
112
|
const newFetch = fetchData({
|
|
@@ -112,9 +116,9 @@ export const deriveStores = context => {
|
|
|
112
116
|
tableId: $tableId,
|
|
113
117
|
},
|
|
114
118
|
options: {
|
|
115
|
-
filter:
|
|
116
|
-
sortColumn:
|
|
117
|
-
sortOrder:
|
|
119
|
+
filter: [],
|
|
120
|
+
sortColumn: initialSortState.column,
|
|
121
|
+
sortOrder: initialSortState.order,
|
|
118
122
|
limit: RowPageSize,
|
|
119
123
|
paginate: true,
|
|
120
124
|
},
|
|
@@ -220,10 +224,7 @@ export const deriveStores = context => {
|
|
|
220
224
|
const addRow = async (row, idx, bubble = false) => {
|
|
221
225
|
try {
|
|
222
226
|
// Create row
|
|
223
|
-
const newRow = await API.saveRow(
|
|
224
|
-
{ ...row, tableId: get(tableId) },
|
|
225
|
-
SuppressErrors
|
|
226
|
-
)
|
|
227
|
+
const newRow = await API.saveRow({ ...row, tableId: get(tableId) })
|
|
227
228
|
|
|
228
229
|
// Update state
|
|
229
230
|
if (idx != null) {
|
|
@@ -350,10 +351,7 @@ export const deriveStores = context => {
|
|
|
350
351
|
...state,
|
|
351
352
|
[rowId]: true,
|
|
352
353
|
}))
|
|
353
|
-
const saved = await API.saveRow(
|
|
354
|
-
{ ...row, ...get(rowChangeCache)[rowId] },
|
|
355
|
-
SuppressErrors
|
|
356
|
-
)
|
|
354
|
+
const saved = await API.saveRow({ ...row, ...get(rowChangeCache)[rowId] })
|
|
357
355
|
|
|
358
356
|
// Update state after a successful change
|
|
359
357
|
if (saved?._id) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { writable, derived, get } from "svelte/store"
|
|
2
2
|
import { tick } from "svelte"
|
|
3
|
-
import { Padding, GutterWidth
|
|
3
|
+
import { Padding, GutterWidth } from "../lib/constants"
|
|
4
4
|
|
|
5
5
|
export const createStores = () => {
|
|
6
6
|
const scroll = writable({
|
|
@@ -138,13 +138,14 @@ export const initialise = context => {
|
|
|
138
138
|
const $scroll = get(scroll)
|
|
139
139
|
const $bounds = get(bounds)
|
|
140
140
|
const $rowHeight = get(rowHeight)
|
|
141
|
+
const verticalOffset = 60
|
|
141
142
|
|
|
142
143
|
// Ensure vertical position is viewable
|
|
143
144
|
if ($focusedRow) {
|
|
144
145
|
// Ensure row is not below bottom of screen
|
|
145
146
|
const rowYPos = $focusedRow.__idx * $rowHeight
|
|
146
147
|
const bottomCutoff =
|
|
147
|
-
$scroll.top + $bounds.height - $rowHeight -
|
|
148
|
+
$scroll.top + $bounds.height - $rowHeight - verticalOffset
|
|
148
149
|
let delta = rowYPos - bottomCutoff
|
|
149
150
|
if (delta > 0) {
|
|
150
151
|
scroll.update(state => ({
|
|
@@ -155,7 +156,7 @@ export const initialise = context => {
|
|
|
155
156
|
|
|
156
157
|
// Ensure row is not above top of screen
|
|
157
158
|
else {
|
|
158
|
-
const delta = $scroll.top - rowYPos +
|
|
159
|
+
const delta = $scroll.top - rowYPos + verticalOffset
|
|
159
160
|
if (delta > 0) {
|
|
160
161
|
scroll.update(state => ({
|
|
161
162
|
...state,
|
|
@@ -170,12 +171,13 @@ export const initialise = context => {
|
|
|
170
171
|
const $visibleColumns = get(visibleColumns)
|
|
171
172
|
const columnName = $focusedCellId?.split("-")[1]
|
|
172
173
|
const column = $visibleColumns.find(col => col.name === columnName)
|
|
174
|
+
const horizontalOffset = 50
|
|
173
175
|
if (!column) {
|
|
174
176
|
return
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
// Ensure column is not cutoff on left edge
|
|
178
|
-
let delta = $scroll.left - column.left +
|
|
180
|
+
let delta = $scroll.left - column.left + horizontalOffset
|
|
179
181
|
if (delta > 0) {
|
|
180
182
|
scroll.update(state => ({
|
|
181
183
|
...state,
|
|
@@ -186,7 +188,7 @@ export const initialise = context => {
|
|
|
186
188
|
// Ensure column is not cutoff on right edge
|
|
187
189
|
else {
|
|
188
190
|
const rightEdge = column.left + column.width
|
|
189
|
-
const rightBound = $bounds.width + $scroll.left -
|
|
191
|
+
const rightBound = $bounds.width + $scroll.left - horizontalOffset
|
|
190
192
|
delta = rightEdge - rightBound
|
|
191
193
|
if (delta > 0) {
|
|
192
194
|
scroll.update(state => ({
|
|
@@ -8,16 +8,13 @@ import {
|
|
|
8
8
|
NewRowID,
|
|
9
9
|
} from "../lib/constants"
|
|
10
10
|
|
|
11
|
-
export const createStores =
|
|
12
|
-
const { props } = context
|
|
11
|
+
export const createStores = () => {
|
|
13
12
|
const focusedCellId = writable(null)
|
|
14
13
|
const focusedCellAPI = writable(null)
|
|
15
14
|
const selectedRows = writable({})
|
|
16
15
|
const hoveredRowId = writable(null)
|
|
17
|
-
const rowHeight = writable(
|
|
16
|
+
const rowHeight = writable(DefaultRowHeight)
|
|
18
17
|
const previousFocusedRowId = writable(null)
|
|
19
|
-
const gridFocused = writable(false)
|
|
20
|
-
const isDragging = writable(false)
|
|
21
18
|
|
|
22
19
|
// Derive the current focused row ID
|
|
23
20
|
const focusedRowId = derived(
|
|
@@ -49,8 +46,6 @@ export const createStores = context => {
|
|
|
49
46
|
previousFocusedRowId,
|
|
50
47
|
hoveredRowId,
|
|
51
48
|
rowHeight,
|
|
52
|
-
gridFocused,
|
|
53
|
-
isDragging,
|
|
54
49
|
selectedRows: {
|
|
55
50
|
...selectedRows,
|
|
56
51
|
actions: {
|
|
@@ -99,9 +94,9 @@ export const deriveStores = context => {
|
|
|
99
94
|
|
|
100
95
|
// Derive the amount of content lines to show in cells depending on row height
|
|
101
96
|
const contentLines = derived(rowHeight, $rowHeight => {
|
|
102
|
-
if ($rowHeight
|
|
97
|
+
if ($rowHeight === LargeRowHeight) {
|
|
103
98
|
return 3
|
|
104
|
-
} else if ($rowHeight
|
|
99
|
+
} else if ($rowHeight === MediumRowHeight) {
|
|
105
100
|
return 2
|
|
106
101
|
}
|
|
107
102
|
return 1
|
|
@@ -134,7 +129,6 @@ export const initialise = context => {
|
|
|
134
129
|
hoveredRowId,
|
|
135
130
|
table,
|
|
136
131
|
rowHeight,
|
|
137
|
-
initialRowHeight,
|
|
138
132
|
} = context
|
|
139
133
|
|
|
140
134
|
// Ensure we clear invalid rows from state if they disappear
|
|
@@ -191,13 +185,4 @@ export const initialise = context => {
|
|
|
191
185
|
table.subscribe($table => {
|
|
192
186
|
rowHeight.set($table?.rowHeight || DefaultRowHeight)
|
|
193
187
|
})
|
|
194
|
-
|
|
195
|
-
// Reset row height when initial row height prop changes
|
|
196
|
-
initialRowHeight.subscribe(height => {
|
|
197
|
-
if (height) {
|
|
198
|
-
rowHeight.set(height)
|
|
199
|
-
} else {
|
|
200
|
-
rowHeight.set(get(table)?.rowHeight || DefaultRowHeight)
|
|
201
|
-
}
|
|
202
|
-
})
|
|
203
188
|
}
|
|
@@ -108,22 +108,11 @@ export const deriveStores = context => {
|
|
|
108
108
|
// Determine the row index at which we should start vertically inverting cell
|
|
109
109
|
// dropdowns
|
|
110
110
|
const rowVerticalInversionIndex = derived(
|
|
111
|
-
[
|
|
112
|
-
([$
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const minBottom =
|
|
117
|
-
$height - ScrollBarSize * 3 - MaxCellRenderHeight + offset
|
|
118
|
-
const lastIdx = Math.floor(minBottom / $rowHeight)
|
|
119
|
-
|
|
120
|
-
// Compute the first row index with space to render popovers above it
|
|
121
|
-
const minTop = MaxCellRenderHeight + offset
|
|
122
|
-
const firstIdx = Math.ceil(minTop / $rowHeight)
|
|
123
|
-
|
|
124
|
-
// Use the greater of the two indices so that we prefer content below,
|
|
125
|
-
// unless there is room to render the entire popover above
|
|
126
|
-
return Math.max(lastIdx, firstIdx)
|
|
111
|
+
[visualRowCapacity, rowHeight],
|
|
112
|
+
([$visualRowCapacity, $rowHeight]) => {
|
|
113
|
+
return (
|
|
114
|
+
$visualRowCapacity - Math.ceil(MaxCellRenderHeight / $rowHeight) - 2
|
|
115
|
+
)
|
|
127
116
|
}
|
|
128
117
|
)
|
|
129
118
|
|
|
@@ -136,7 +125,7 @@ export const deriveStores = context => {
|
|
|
136
125
|
let inversionIdx = $renderedColumns.length
|
|
137
126
|
for (let i = $renderedColumns.length - 1; i >= 0; i--, inversionIdx--) {
|
|
138
127
|
const rightEdge = $renderedColumns[i].left + $renderedColumns[i].width
|
|
139
|
-
if (rightEdge + MaxCellRenderWidthOverflow
|
|
128
|
+
if (rightEdge + MaxCellRenderWidthOverflow < cutoff) {
|
|
140
129
|
break
|
|
141
130
|
}
|
|
142
131
|
}
|
package/src/fetch/DataFetch.js
CHANGED
|
@@ -136,10 +136,8 @@ export default class DataFetch {
|
|
|
136
136
|
this.options.sortOrder = "ascending"
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
// If no sort column,
|
|
140
|
-
|
|
141
|
-
const sortValid = this.options.sortColumn && schema[this.options.sortColumn]
|
|
142
|
-
if (!sortValid) {
|
|
139
|
+
// If no sort column, use the primary display and fallback to first column
|
|
140
|
+
if (!this.options.sortColumn) {
|
|
143
141
|
let newSortColumn
|
|
144
142
|
if (definition?.primaryDisplay && schema[definition.primaryDisplay]) {
|
|
145
143
|
newSortColumn = definition.primaryDisplay
|
package/src/utils/index.js
CHANGED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { getContext } from "svelte"
|
|
3
|
-
import { ActionButton, Popover, Label } from "@budibase/bbui"
|
|
4
|
-
import {
|
|
5
|
-
DefaultColumnWidth,
|
|
6
|
-
LargeRowHeight,
|
|
7
|
-
MediumRowHeight,
|
|
8
|
-
SmallRowHeight,
|
|
9
|
-
} from "../lib/constants"
|
|
10
|
-
|
|
11
|
-
const { stickyColumn, columns, rowHeight, table } = getContext("grid")
|
|
12
|
-
|
|
13
|
-
// Some constants for column width options
|
|
14
|
-
const smallColSize = 120
|
|
15
|
-
const mediumColSize = DefaultColumnWidth
|
|
16
|
-
const largeColSize = DefaultColumnWidth * 1.5
|
|
17
|
-
|
|
18
|
-
// Row height sizes
|
|
19
|
-
const rowSizeOptions = [
|
|
20
|
-
{
|
|
21
|
-
label: "Small",
|
|
22
|
-
size: SmallRowHeight,
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
label: "Medium",
|
|
26
|
-
size: MediumRowHeight,
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
label: "Large",
|
|
30
|
-
size: LargeRowHeight,
|
|
31
|
-
},
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
let open = false
|
|
35
|
-
let anchor
|
|
36
|
-
|
|
37
|
-
// Column width sizes
|
|
38
|
-
$: allCols = $columns.concat($stickyColumn ? [$stickyColumn] : [])
|
|
39
|
-
$: allSmall = allCols.every(col => col.width === smallColSize)
|
|
40
|
-
$: allMedium = allCols.every(col => col.width === mediumColSize)
|
|
41
|
-
$: allLarge = allCols.every(col => col.width === largeColSize)
|
|
42
|
-
$: custom = !allSmall && !allMedium && !allLarge
|
|
43
|
-
$: columnSizeOptions = [
|
|
44
|
-
{
|
|
45
|
-
label: "Small",
|
|
46
|
-
size: smallColSize,
|
|
47
|
-
selected: allSmall,
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
label: "Medium",
|
|
51
|
-
size: mediumColSize,
|
|
52
|
-
selected: allMedium,
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
label: "Large",
|
|
56
|
-
size: largeColSize,
|
|
57
|
-
selected: allLarge,
|
|
58
|
-
},
|
|
59
|
-
]
|
|
60
|
-
|
|
61
|
-
const changeRowHeight = height => {
|
|
62
|
-
columns.actions.saveTable({
|
|
63
|
-
...$table,
|
|
64
|
-
rowHeight: height,
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
</script>
|
|
68
|
-
|
|
69
|
-
<div bind:this={anchor}>
|
|
70
|
-
<ActionButton
|
|
71
|
-
icon="MoveUpDown"
|
|
72
|
-
quiet
|
|
73
|
-
size="M"
|
|
74
|
-
on:click={() => (open = !open)}
|
|
75
|
-
selected={open}
|
|
76
|
-
disabled={!allCols.length}
|
|
77
|
-
>
|
|
78
|
-
Size
|
|
79
|
-
</ActionButton>
|
|
80
|
-
</div>
|
|
81
|
-
|
|
82
|
-
<Popover bind:open {anchor} align="left">
|
|
83
|
-
<div class="content">
|
|
84
|
-
<div class="size">
|
|
85
|
-
<Label>Row height</Label>
|
|
86
|
-
<div class="options">
|
|
87
|
-
{#each rowSizeOptions as option}
|
|
88
|
-
<ActionButton
|
|
89
|
-
quiet
|
|
90
|
-
selected={$rowHeight === option.size}
|
|
91
|
-
on:click={() => changeRowHeight(option.size)}
|
|
92
|
-
>
|
|
93
|
-
{option.label}
|
|
94
|
-
</ActionButton>
|
|
95
|
-
{/each}
|
|
96
|
-
</div>
|
|
97
|
-
</div>
|
|
98
|
-
<div class="size">
|
|
99
|
-
<Label>Column width</Label>
|
|
100
|
-
<div class="options">
|
|
101
|
-
{#each columnSizeOptions as option}
|
|
102
|
-
<ActionButton
|
|
103
|
-
quiet
|
|
104
|
-
on:click={() => columns.actions.changeAllColumnWidths(option.size)}
|
|
105
|
-
selected={option.selected}
|
|
106
|
-
>
|
|
107
|
-
{option.label}
|
|
108
|
-
</ActionButton>
|
|
109
|
-
{/each}
|
|
110
|
-
{#if custom}
|
|
111
|
-
<ActionButton selected={custom} quiet>Custom</ActionButton>
|
|
112
|
-
{/if}
|
|
113
|
-
</div>
|
|
114
|
-
</div>
|
|
115
|
-
</div>
|
|
116
|
-
</Popover>
|
|
117
|
-
|
|
118
|
-
<style>
|
|
119
|
-
.content {
|
|
120
|
-
padding: 12px;
|
|
121
|
-
}
|
|
122
|
-
.size {
|
|
123
|
-
display: flex;
|
|
124
|
-
flex-direction: column;
|
|
125
|
-
gap: 8px;
|
|
126
|
-
}
|
|
127
|
-
.size:first-child {
|
|
128
|
-
margin-bottom: 16px;
|
|
129
|
-
}
|
|
130
|
-
.options {
|
|
131
|
-
display: flex;
|
|
132
|
-
align-items: center;
|
|
133
|
-
gap: 8px;
|
|
134
|
-
}
|
|
135
|
-
</style>
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { writable } from "svelte/store"
|
|
2
|
-
import { derivedMemo } from "../../../utils"
|
|
3
|
-
|
|
4
|
-
export const createStores = context => {
|
|
5
|
-
const config = writable(context.props)
|
|
6
|
-
const getProp = prop => derivedMemo(config, $config => $config[prop])
|
|
7
|
-
|
|
8
|
-
// Derive and memoize some props so that we can react to them in isolation
|
|
9
|
-
const tableId = getProp("tableId")
|
|
10
|
-
const initialSortColumn = getProp("initialSortColumn")
|
|
11
|
-
const initialSortOrder = getProp("initialSortOrder")
|
|
12
|
-
const initialFilter = getProp("initialFilter")
|
|
13
|
-
const initialRowHeight = getProp("initialRowHeight")
|
|
14
|
-
const schemaOverrides = getProp("schemaOverrides")
|
|
15
|
-
const columnWhitelist = getProp("columnWhitelist")
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
config,
|
|
19
|
-
tableId,
|
|
20
|
-
initialSortColumn,
|
|
21
|
-
initialSortOrder,
|
|
22
|
-
initialFilter,
|
|
23
|
-
initialRowHeight,
|
|
24
|
-
schemaOverrides,
|
|
25
|
-
columnWhitelist,
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { writable } from "svelte/store"
|
|
2
|
-
|
|
3
|
-
export const createStores = context => {
|
|
4
|
-
const { props } = context
|
|
5
|
-
|
|
6
|
-
// Initialise to default props
|
|
7
|
-
const filter = writable(props.initialFilter)
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
filter,
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const initialise = context => {
|
|
15
|
-
const { filter, initialFilter } = context
|
|
16
|
-
|
|
17
|
-
// Reset filter when initial filter prop changes
|
|
18
|
-
initialFilter.subscribe(filter.set)
|
|
19
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { writable } from "svelte/store"
|
|
2
|
-
|
|
3
|
-
export const createStores = context => {
|
|
4
|
-
const { props } = context
|
|
5
|
-
|
|
6
|
-
// Initialise to default props
|
|
7
|
-
const sort = writable({
|
|
8
|
-
column: props.initialSortColumn,
|
|
9
|
-
order: props.initialSortOrder || "ascending",
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
sort,
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const initialise = context => {
|
|
18
|
-
const { sort, initialSortColumn, initialSortOrder } = context
|
|
19
|
-
|
|
20
|
-
// Reset sort when initial sort props change
|
|
21
|
-
initialSortColumn.subscribe(newSortColumn => {
|
|
22
|
-
sort.update(state => ({ ...state, column: newSortColumn }))
|
|
23
|
-
})
|
|
24
|
-
initialSortOrder.subscribe(newSortOrder => {
|
|
25
|
-
sort.update(state => ({ ...state, order: newSortOrder }))
|
|
26
|
-
})
|
|
27
|
-
}
|
package/src/utils/memo.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { writable, get, derived } from "svelte/store"
|
|
2
|
-
|
|
3
|
-
// A simple svelte store which deeply compares all changes and ensures that
|
|
4
|
-
// subscribed children will only fire when a new value is actually set
|
|
5
|
-
export const memo = initialValue => {
|
|
6
|
-
const store = writable(initialValue)
|
|
7
|
-
|
|
8
|
-
const tryUpdateValue = (newValue, currentValue) => {
|
|
9
|
-
// Sanity check for primitive equality
|
|
10
|
-
if (currentValue === newValue) {
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// Otherwise deep compare via JSON stringify
|
|
15
|
-
const currentString = JSON.stringify(currentValue)
|
|
16
|
-
const newString = JSON.stringify(newValue)
|
|
17
|
-
if (currentString !== newString) {
|
|
18
|
-
store.set(newValue)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
subscribe: store.subscribe,
|
|
24
|
-
set: newValue => {
|
|
25
|
-
const currentValue = get(store)
|
|
26
|
-
tryUpdateValue(newValue, currentValue)
|
|
27
|
-
},
|
|
28
|
-
update: updateFn => {
|
|
29
|
-
const currentValue = get(store)
|
|
30
|
-
let mutableCurrentValue = JSON.parse(JSON.stringify(currentValue))
|
|
31
|
-
const newValue = updateFn(mutableCurrentValue)
|
|
32
|
-
tryUpdateValue(newValue, currentValue)
|
|
33
|
-
},
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Enriched version of svelte's derived store which returns a memo
|
|
38
|
-
export const derivedMemo = (store, derivation) => {
|
|
39
|
-
const derivedStore = derived(store, derivation)
|
|
40
|
-
const memoStore = memo(get(derivedStore))
|
|
41
|
-
derivedStore.subscribe(memoStore.set)
|
|
42
|
-
return memoStore
|
|
43
|
-
}
|