UNPKG

jsx-slack

Version:

Build JSON object for Slack Block Kit surfaces from JSX

2 lines (1 loc) 1.61 kB
import{JSXSlack as n}from"../../jsx.mjs";import{createComponent as c,cleanMeta as s,createElementInternal as d}from"../../jsx-internals.mjs";import{Select as f}from"../elements/Select.mjs";import{Textarea as u}from"../input/Textarea.mjs";import{availableActionTypes as y}from"../layout/Actions.mjs";import{Divider as v}from"../layout/Divider.mjs";import{Header as b}from"../layout/Header.mjs";import{Image as k}from"../layout/Image.mjs";import{Input as l,knownInputs as g}from"../layout/Input.mjs";import{availableSectionAccessoryTypes as h,Section as x}from"../layout/Section.mjs";import{Video as I}from"../layout/Video.mjs";import{generateBlocksContainer as S,generateActionsValidator as M,generateSectionValidator as w}from"./utils.mjs";const T=S({name:"Home",availableBlockTypes:{actions:M([...y].filter(e=>e!=="workflow_button")),context:!0,divider:!0,header:!0,image:!0,input:!0,section:w([...h].filter(e=>e!=="workflow_button")),video:!0},aliases:{header:b,hr:v,img:k,input:l,section:x,select:f,textarea:u,video:I},typesToCheckMissingLabel:g}),_=c("Home",e=>{let t;const m=n.Children.toArray(e.children).reduce((o,r)=>{if(n.isValidElement(r)){const{type:a,props:i}=r.$$jsxslack;if(a===l||a==="input"){if(i.type==="hidden")return t=t||{},t[i.name]=i.value,o;if(i.type==="submit")return o}}return typeof r=="object"?[...o,r]:o},[]),p=typeof e.privateMetadata=="string"?e.privateMetadata:typeof e.privateMetadata=="function"?e.privateMetadata(t):t&&JSON.stringify(t);return{type:"home",callback_id:e.callbackId,external_id:e.externalId,private_metadata:p,blocks:s(d(T,{children:m}))}});export{_ as Home};