@budibase/frontend-core 3.3.6 → 3.4.1
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 +2 -2
- package/src/components/grid/cells/DataCell.svelte +10 -3
- package/src/components/grid/lib/renderers.ts +0 -1
- package/src/components/grid/stores/columns.ts +1 -0
- package/src/components/grid/stores/rows.ts +37 -17
- package/src/utils/components.ts +26 -0
- package/src/utils/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/frontend-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "Budibase frontend core libraries used in builder and client",
|
|
5
5
|
"author": "Budibase",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"svelte-check": "^4.1.0"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "981ad8df214145efca562e441f1f9d1cf647d339"
|
|
24
24
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import GridCell from "./GridCell.svelte"
|
|
4
4
|
import { getCellRenderer } from "../lib/renderers"
|
|
5
5
|
import { derived, writable } from "svelte/store"
|
|
6
|
+
import TextCell from "./TextCell.svelte"
|
|
6
7
|
|
|
7
8
|
const {
|
|
8
9
|
rows,
|
|
@@ -36,11 +37,17 @@
|
|
|
36
37
|
|
|
37
38
|
let api
|
|
38
39
|
|
|
40
|
+
// Get the appropriate cell renderer and value
|
|
41
|
+
$: hasCustomFormat = column.format && !row._isNewRow
|
|
42
|
+
$: renderer = hasCustomFormat ? TextCell : getCellRenderer(column)
|
|
43
|
+
$: value = hasCustomFormat ? row.__formatted?.[column.name] : row[column.name]
|
|
44
|
+
|
|
39
45
|
// Get the error for this cell if the cell is focused or selected
|
|
40
46
|
$: error = getErrorStore(rowFocused, cellId)
|
|
41
47
|
|
|
42
48
|
// Determine if the cell is editable
|
|
43
49
|
$: readonly =
|
|
50
|
+
hasCustomFormat ||
|
|
44
51
|
columns.actions.isReadonly(column) ||
|
|
45
52
|
(!$config.canEditRows && !row._isNewRow)
|
|
46
53
|
|
|
@@ -69,7 +76,7 @@
|
|
|
69
76
|
onKeyDown: (...params) => api?.onKeyDown?.(...params),
|
|
70
77
|
isReadonly: () => readonly,
|
|
71
78
|
getType: () => column.schema.type,
|
|
72
|
-
getValue: () =>
|
|
79
|
+
getValue: () => value,
|
|
73
80
|
setValue: (value, options = { apply: true }) => {
|
|
74
81
|
validation.actions.setError(cellId, null)
|
|
75
82
|
updateValue({
|
|
@@ -136,9 +143,9 @@
|
|
|
136
143
|
}}
|
|
137
144
|
>
|
|
138
145
|
<svelte:component
|
|
139
|
-
this={
|
|
146
|
+
this={renderer}
|
|
140
147
|
bind:api
|
|
141
|
-
value
|
|
148
|
+
{value}
|
|
142
149
|
schema={column.schema}
|
|
143
150
|
onChange={cellAPI.setValue}
|
|
144
151
|
{focused}
|
|
@@ -188,6 +188,7 @@ export const initialise = (context: StoreContext) => {
|
|
|
188
188
|
conditions: fieldSchema.conditions,
|
|
189
189
|
related: fieldSchema.related,
|
|
190
190
|
calculationType: fieldSchema.calculationType,
|
|
191
|
+
format: fieldSchema.format,
|
|
191
192
|
__left: undefined as any, // TODO
|
|
192
193
|
__idx: undefined as any, // TODO
|
|
193
194
|
}
|
|
@@ -16,6 +16,7 @@ import { Store as StoreContext } from "."
|
|
|
16
16
|
|
|
17
17
|
interface IndexedUIRow extends UIRow {
|
|
18
18
|
__idx: number
|
|
19
|
+
__formatted: Record<string, any>
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
interface RowStore {
|
|
@@ -114,26 +115,44 @@ export const createStores = (): RowStore => {
|
|
|
114
115
|
export const deriveStores = (context: StoreContext): RowDerivedStore => {
|
|
115
116
|
const { rows, enrichedSchema } = context
|
|
116
117
|
|
|
117
|
-
// Enrich rows with an index property and
|
|
118
|
+
// Enrich rows with an index property and additional values
|
|
118
119
|
const enrichedRows = derived(
|
|
119
120
|
[rows, enrichedSchema],
|
|
120
121
|
([$rows, $enrichedSchema]) => {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
map
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
122
|
+
// Find columns which require additional processing
|
|
123
|
+
const cols = Object.values($enrichedSchema || {})
|
|
124
|
+
const relatedColumns = cols.filter(col => col.related)
|
|
125
|
+
const formattedColumns = cols.filter(col => col.format)
|
|
126
|
+
|
|
127
|
+
return $rows.map<IndexedUIRow>((row, idx) => {
|
|
128
|
+
// Derive any values that need enriched from related rows
|
|
129
|
+
const relatedValues = relatedColumns.reduce<Record<string, string>>(
|
|
130
|
+
(map, column) => {
|
|
131
|
+
const fromField = $enrichedSchema![column.related!.field]
|
|
132
|
+
map[column.name] = getRelatedTableValues(
|
|
133
|
+
row,
|
|
134
|
+
{ ...column, related: column.related! },
|
|
135
|
+
fromField
|
|
136
|
+
)
|
|
137
|
+
return map
|
|
138
|
+
},
|
|
139
|
+
{}
|
|
140
|
+
)
|
|
141
|
+
// Derive any display-only formatted values for this row
|
|
142
|
+
const formattedValues = formattedColumns.reduce<Record<string, any>>(
|
|
143
|
+
(map, column) => {
|
|
144
|
+
map[column.name] = column.format!(row)
|
|
145
|
+
return map
|
|
146
|
+
},
|
|
147
|
+
{}
|
|
148
|
+
)
|
|
149
|
+
return {
|
|
150
|
+
...row,
|
|
151
|
+
...relatedValues,
|
|
152
|
+
__formatted: formattedValues,
|
|
153
|
+
__idx: idx,
|
|
154
|
+
}
|
|
155
|
+
})
|
|
137
156
|
}
|
|
138
157
|
)
|
|
139
158
|
|
|
@@ -791,6 +810,7 @@ export const createActions = (context: StoreContext): RowActionStore => {
|
|
|
791
810
|
let clone: Row = { ...row }
|
|
792
811
|
delete clone.__idx
|
|
793
812
|
delete clone.__metadata
|
|
813
|
+
delete clone.__formatted
|
|
794
814
|
if (!get(hasBudibaseIdentifiers) && isGeneratedRowID(clone._id!)) {
|
|
795
815
|
delete clone._id
|
|
796
816
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ComponentDefinition, ComponentSetting } from "@budibase/types"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Gets the definition of this component's settings from the manifest
|
|
5
|
+
*/
|
|
6
|
+
export const getSettingsDefinition = (
|
|
7
|
+
definition: ComponentDefinition
|
|
8
|
+
): ComponentSetting[] => {
|
|
9
|
+
if (!definition) {
|
|
10
|
+
return []
|
|
11
|
+
}
|
|
12
|
+
let settings: ComponentSetting[] = []
|
|
13
|
+
definition.settings?.forEach(setting => {
|
|
14
|
+
if (setting.section) {
|
|
15
|
+
settings = settings.concat(
|
|
16
|
+
(setting.settings || [])?.map(childSetting => ({
|
|
17
|
+
...childSetting,
|
|
18
|
+
sectionDependsOn: setting.dependsOn,
|
|
19
|
+
}))
|
|
20
|
+
)
|
|
21
|
+
} else {
|
|
22
|
+
settings.push(setting)
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
return settings
|
|
26
|
+
}
|
package/src/utils/index.ts
CHANGED