jsx-slack
Version:
Build JSON object for Slack Block Kit surfaces from JSX
2 lines (1 loc) • 1.5 kB
JavaScript
import{JSXSlackError as p}from"../../error.mjs";import{JSXSlack as f}from"../../jsx.mjs";import{createComponent as h}from"../../jsx-internals.mjs";import{availableActionTypes as $}from"../layout/Actions.mjs";import{availableSectionAccessoryTypes as b}from"../layout/Section.mjs";import{resolveTagName as y,alias as k}from"../utils.mjs";const u=({aliases:n,availableBlockTypes:i,typesToCheckMissingLabel:t,name:e})=>h(e,({children:c})=>f.Children.toArray(c).reduce((m,o)=>{const d=y(o),r=f.isValidElement(o)&&typeof o.$$jsxslack.type=="string"&&n[o.$$jsxslack.type]&&k(o,n[o.$$jsxslack.type])||o;if(typeof r=="object"&&r){const a=r,l=i[a.type];if(l)return typeof l=="function"&&l(a),[...m,a];let s="";throw d&&(s=`Provided by ${d}`,(t||[]).includes(a.type)&&(s+='. Are you missing the definition of "label" prop to use the input component?')),new p(`<${e}> has detected an invalid block type as the layout block: "${a.type}"${s?` (${s})`:""}`,o)}return m},[])),v=(n=[...$])=>i=>{const t=(i.elements||[]).find(({type:e})=>!n.includes(e));if(t){const e=y(t);throw new p(`<Actions> block has detected an incompatible element with the root container${e?`: ${e}`:"."}`,t)}},w=(n=b)=>i=>{var t;const e=(t=i.accessory)==null?void 0:t.type;if(e&&!n.includes(e)){const c=y(i.accessory);throw new p(`<Section> block has detected an incompatible accessory with the root container${c?`: ${c}`:"."}`,i.accessory)}};export{v as generateActionsValidator,u as generateBlocksContainer,w as generateSectionValidator};