1
0
Fork 0
mirror of synced 2024-09-08 05:31:47 +12:00

Add cells for formulae and JSON

This commit is contained in:
Andrew Kingston 2023-03-14 10:18:42 +00:00
parent 4754be109a
commit 2d6c2fe904
4 changed files with 46 additions and 3 deletions

View file

@ -0,0 +1,5 @@
<script>
import TextCell from "./TextCell.svelte"
</script>
<TextCell {...$$props} readonly />

View file

@ -0,0 +1,36 @@
<script>
import LongFormCell from "./LongFormCell.svelte"
export let onChange
export let value
export let api
$: stringified = getStringifiedValue(value)
const getStringifiedValue = value => {
if (!value) {
return value
}
try {
return JSON.stringify(value, null, 2)
} catch (error) {
return null
}
}
const parse = value => {
const trimmed = value?.trim()
if (!trimmed) {
onChange(null)
return
}
try {
const parsed = JSON.parse(trimmed)
onChange(parsed)
} catch (error) {
console.log("error parsing")
}
}
</script>
<LongFormCell {...$$props} bind:api value={stringified} onChange={parse} />

View file

@ -4,4 +4,4 @@
export let api
</script>
<TextCell bind:api {...$$props} type="number" />
<TextCell {...$$props} bind:api type="number" />

View file

@ -7,6 +7,8 @@ import TextCell from "./cells/TextCell.svelte"
import BlankCell from "./cells/BlankCell.svelte"
import LongFormCell from "./cells/LongFormCell.svelte"
import BooleanCell from "./cells/BooleanCell.svelte"
import FormulaCell from "./cells/FormulaCell.svelte"
import JSONCell from "./cells/JSONCell.svelte"
const TypeComponentMap = {
text: TextCell,
@ -19,8 +21,8 @@ const TypeComponentMap = {
boolean: BooleanCell,
attachment: BlankCell,
link: RelationshipCell,
formula: BlankCell,
json: BlankCell,
formula: FormulaCell,
json: JSONCell,
}
export const getCellRenderer = column => {
return TypeComponentMap[column?.schema?.type] || TextCell