1
0
Fork 0
mirror of synced 2024-07-03 13:30:46 +12:00

Clean components

This commit is contained in:
Adria Navarro 2024-03-27 10:21:26 +01:00
parent b99a51d48b
commit 39ac734edd
3 changed files with 27 additions and 20 deletions

View file

@ -1,7 +1,6 @@
<script>
import { onMount, getContext } from "svelte"
import { Dropzone } from "@budibase/bbui"
import { FieldType } from "@budibase/types"
export let value
export let focused = false
@ -11,17 +10,13 @@
export let invertX = false
export let invertY = false
export let schema
export let maximum
const { API, notifications } = getContext("grid")
const imageExtensions = ["png", "tiff", "gif", "raw", "jpg", "jpeg"]
let isOpen = false
$: isSingle = schema?.type === FieldType.ATTACHMENT_SINGLE
$: arrayValue = (value && !Array.isArray(value) ? [value] : value) || []
$: maximum = isSingle ? 1 : schema.constraints?.length?.maximum
$: editable = focused && !readonly
$: {
if (!focused) {
@ -74,15 +69,6 @@
}
}
const onFileChange = e => {
let value = e.detail
if (isSingle) {
value = value[0] || null
}
onChange(value)
}
onMount(() => {
api = {
focus: () => open(),
@ -96,7 +82,7 @@
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div class="attachment-cell" class:editable on:click={editable ? open : null}>
{#each arrayValue as attachment}
{#each value || [] as attachment}
{#if isImage(attachment.extension)}
<img src={attachment.url} alt={attachment.extension} />
{:else}
@ -110,10 +96,10 @@
{#if isOpen}
<div class="dropzone" class:invertX class:invertY>
<Dropzone
value={arrayValue}
{value}
compact
on:change={onFileChange}
{maximum}
on:change={e => onChange(e.detail)}
maximum={maximum || schema.constraints?.length?.maximum}
{processFiles}
{deleteAttachments}
{handleFileTooLarge}

View file

@ -0,0 +1,20 @@
<script>
import AttachmentCell from "./AttachmentCell.svelte"
export let value
export let onChange
$: arrayValue = (!Array.isArray(value) && value ? [value] : value) || []
$: onFileChange = value => {
value = value[0] || null
onChange(value)
}
</script>
<AttachmentCell
{...$$restProps}
maximum={1}
value={arrayValue}
onChange={onFileChange}
/>

View file

@ -11,6 +11,7 @@ import BooleanCell from "../cells/BooleanCell.svelte"
import FormulaCell from "../cells/FormulaCell.svelte"
import JSONCell from "../cells/JSONCell.svelte"
import AttachmentCell from "../cells/AttachmentCell.svelte"
import AttachmentSingleCell from "../cells/AttachmentSingleCell.svelte"
import BBReferenceCell from "../cells/BBReferenceCell.svelte"
const TypeComponentMap = {
@ -23,7 +24,7 @@ const TypeComponentMap = {
[FieldType.NUMBER]: NumberCell,
[FieldType.BOOLEAN]: BooleanCell,
[FieldType.ATTACHMENT]: AttachmentCell,
[FieldType.ATTACHMENT_SINGLE]: AttachmentCell,
[FieldType.ATTACHMENT_SINGLE]: AttachmentSingleCell,
[FieldType.LINK]: RelationshipCell,
[FieldType.FORMULA]: FormulaCell,
[FieldType.JSON]: JSONCell,