2021-04-08 16:57:24 +02:00
|
|
|
<script>
|
|
|
|
import StringRenderer from "./StringRenderer.svelte"
|
|
|
|
import BooleanRenderer from "./BooleanRenderer.svelte"
|
|
|
|
import DateTimeRenderer from "./DateTimeRenderer.svelte"
|
|
|
|
import RelationshipRenderer from "./RelationshipRenderer.svelte"
|
|
|
|
import AttachmentRenderer from "./AttachmentRenderer.svelte"
|
2021-08-19 17:54:44 +02:00
|
|
|
import ArrayRenderer from "./ArrayRenderer.svelte"
|
2021-10-18 16:08:57 +02:00
|
|
|
import InternalRenderer from "./InternalRenderer.svelte"
|
2022-02-21 14:19:29 +01:00
|
|
|
import { processStringSync } from "@budibase/string-templates"
|
2021-10-13 10:29:01 +02:00
|
|
|
|
2021-04-12 16:12:59 +02:00
|
|
|
export let row
|
2021-04-08 16:57:24 +02:00
|
|
|
export let schema
|
|
|
|
export let value
|
2021-04-09 15:21:27 +02:00
|
|
|
export let customRenderers = []
|
2021-04-08 16:57:24 +02:00
|
|
|
|
2021-10-12 18:32:15 +02:00
|
|
|
let renderer
|
2021-04-12 16:24:33 +02:00
|
|
|
const typeMap = {
|
|
|
|
boolean: BooleanRenderer,
|
|
|
|
datetime: DateTimeRenderer,
|
|
|
|
link: RelationshipRenderer,
|
|
|
|
attachment: AttachmentRenderer,
|
|
|
|
string: StringRenderer,
|
|
|
|
options: StringRenderer,
|
|
|
|
number: StringRenderer,
|
|
|
|
longform: StringRenderer,
|
2021-08-19 17:54:44 +02:00
|
|
|
array: ArrayRenderer,
|
2021-10-18 16:08:57 +02:00
|
|
|
internal: InternalRenderer,
|
2021-04-12 16:24:33 +02:00
|
|
|
}
|
2022-06-27 15:44:52 +02:00
|
|
|
$: type = getType(schema)
|
2021-05-04 12:32:22 +02:00
|
|
|
$: customRenderer = customRenderers?.find(x => x.column === schema?.name)
|
2021-10-13 12:39:36 +02:00
|
|
|
$: renderer = customRenderer?.component ?? typeMap[type] ?? StringRenderer
|
2022-02-18 12:58:18 +01:00
|
|
|
$: width = schema?.width || "150px"
|
2022-02-21 14:19:29 +01:00
|
|
|
$: cellValue = getCellValue(value, schema.template)
|
|
|
|
|
2022-06-27 15:44:52 +02:00
|
|
|
const getType = schema => {
|
|
|
|
// Use a string renderer for dates if we use a custom template
|
|
|
|
if (schema?.type === "datetime" && schema?.template) {
|
|
|
|
return "string"
|
|
|
|
}
|
|
|
|
return schema?.type || "string"
|
|
|
|
}
|
|
|
|
|
2022-02-21 14:19:29 +01:00
|
|
|
const getCellValue = (value, template) => {
|
|
|
|
if (!template) {
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
return processStringSync(template, { value })
|
|
|
|
}
|
2021-04-08 16:57:24 +02:00
|
|
|
</script>
|
|
|
|
|
2022-02-21 14:19:29 +01:00
|
|
|
{#if renderer && (customRenderer || (cellValue != null && cellValue !== ""))}
|
2022-02-21 15:47:01 +01:00
|
|
|
<div style="--max-cell-width: {schema.width ? 'none' : '200px'};">
|
|
|
|
<svelte:component
|
|
|
|
this={renderer}
|
|
|
|
{row}
|
|
|
|
{schema}
|
|
|
|
value={cellValue}
|
|
|
|
on:clickrelationship
|
|
|
|
>
|
|
|
|
<slot />
|
|
|
|
</svelte:component>
|
|
|
|
</div>
|
2021-04-08 16:57:24 +02:00
|
|
|
{/if}
|
2022-02-21 15:47:01 +01:00
|
|
|
|
|
|
|
<style>
|
|
|
|
div {
|
|
|
|
display: contents;
|
|
|
|
}
|
|
|
|
</style>
|