UNPKG

jsx-slack

Version:

Build JSON object for Slack Block Kit surfaces from JSX

2 lines (1 loc) 1.28 kB
import{JSXSlackError as f}from"../../error.mjs";import{JSXSlack as u}from"../../jsx.mjs";import{createComponent as O}from"../../jsx-internals.mjs";import{Optgroup as p}from"../composition/Optgroup.mjs";import{Option as d,optionSelectedSymbol as g}from"../composition/Option.mjs";import{alias as S,resolveTagName as k}from"../utils.mjs";const $=Symbol("jsx-slack-select-fragment-selected-options"),h=O("SelectFragment",({children:y,from:s})=>{let i=0,t;const m=`<${(s==null?void 0:s.$$jsxslackComponent.name)||"SelectFragment"}>`,l=[],c=u.Children.toArray(y).reduce((a,e)=>{if(!u.isValidElement(e))return a;let o=e;e.$$jsxslack.type==="option"&&(o=S(e,d,!1)),e.$$jsxslack.type==="optgroup"&&(o=S(e,p,!1));const{type:n}=o.$$jsxslack;if(n===d)i+=1,o[g]&&l.push(o);else if(n===p)i+=o.options.length,l.push(...o.options.filter(r=>r[g]));else{const r=k(e);throw new f(`${m} must contain either of <Option> or <Optgroup>${r?` but it is included ${r}`:""}.`,e)}if(t&&t!==n)throw new f(`<Option> and <Optgroup> cannot be mixed in the immediate children of ${m}.`,e);return t=n,[...a,o]},[]);return i>0?Object.defineProperty(t===p?{option_groups:c}:{options:c},$,{value:l}):{options:[]}}),x=h;export{x as SelectFragment,h as SelectFragmentInternal,$ as selectFragmentSelectedOptionsSymbol};