main

mattermost/focalboard

Last updated at: 29/12/2023 09:46

imageBlock.ts

TLDR

This file defines a type ImageBlock and a function createImageBlock for creating an image block. It also exports both the type and function for use in other modules.

Methods

createImageBlock

This method creates an image block object. It takes an optional block object as a parameter. If block is provided, it uses the fileId from block to initialize the fields property of the image block. Otherwise, it sets the fileId to an empty string. The method returns the created image block object.

Classes

None

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Block, createBlock} from './block'
import {ContentBlock} from './contentBlock'

type ImageBlockFields = {
    fileId: string
}

type ImageBlock = ContentBlock & {
    type: 'image'
    fields: ImageBlockFields
}

function createImageBlock(block?: Block): ImageBlock {
    return {
        ...createBlock(block),
        type: 'image',
        fields: {
            fileId: block?.fields.fileId || '',
        },
    }
}

export {ImageBlock, createImageBlock}