Skip to content

Commit

Permalink
fix(element): support nested array children, close koishijs/koishi#890
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Dec 23, 2022
1 parent c3a73ba commit ba0a9b2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/element/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Awaitable, camelize, capitalize, defineProperty, Dict, hyphenate, is, isNullable } from 'cosmokit'
import { Awaitable, camelize, defineProperty, Dict, hyphenate, is, isNullable, makeArray } from 'cosmokit'

const kElement = Symbol.for('satori.element')

Expand Down Expand Up @@ -67,11 +67,12 @@ function Element(type: string, ...args: any[]) {
const el = Object.create(ElementConstructor.prototype)
let attrs: Dict = {}, children: Element[] = []
if (args[0] && typeof args[0] === 'object' && !isElement(args[0]) && !Array.isArray(args[0])) {
for (const [key, value] of Object.entries(args.shift())) {
const props = args.shift()
for (const [key, value] of Object.entries(props)) {
if (isNullable(value)) continue
// https://github.com/reactjs/rfcs/pull/107
if (key === 'children') {
children = toElementArray(value as Element.Fragment)
args.push(...makeArray(value))
} else {
attrs[key] = value
}
Expand Down

0 comments on commit ba0a9b2

Please sign in to comment.