( section: string, el: string | null | (() => FormKitSchemaNode), fragment = false )
| 83 | |
| 84 | /*@__NO_SIDE_EFFECTS__*/ |
| 85 | export function createSection( |
| 86 | section: string, |
| 87 | el: string | null | (() => FormKitSchemaNode), |
| 88 | fragment = false |
| 89 | ): FormKitSection< |
| 90 | FormKitExtendableSchemaRoot | FormKitSchemaExtendableSection |
| 91 | > { |
| 92 | return ( |
| 93 | ...children: Array< |
| 94 | FormKitSchemaExtendableSection | string | FormKitSchemaCondition |
| 95 | > |
| 96 | ) => { |
| 97 | const extendable = (extensions: FormKitSectionsSchema) => { |
| 98 | const node = !el || typeof el === 'string' ? { $el: el } : el() |
| 99 | if (isDOM(node) || isComponent(node)) { |
| 100 | if (!node.meta) { |
| 101 | node.meta = { section } |
| 102 | } else { |
| 103 | node.meta.section = section |
| 104 | } |
| 105 | if (children.length && !node.children) { |
| 106 | node.children = [ |
| 107 | ...children.map((child) => |
| 108 | typeof child === 'function' ? child(extensions) : child |
| 109 | ), |
| 110 | ] |
| 111 | } |
| 112 | if (isDOM(node)) { |
| 113 | node.attrs = { |
| 114 | class: `$classes.${section}`, |
| 115 | ...(node.attrs || {}), |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | return { |
| 120 | if: `$slots.${section}`, |
| 121 | then: `$slots.${section}`, |
| 122 | else: |
| 123 | section in extensions |
| 124 | ? extendSchema(node, extensions[section]) |
| 125 | : node, |
| 126 | } |
| 127 | } |
| 128 | extendable._s = section |
| 129 | return fragment ? createRoot(extendable) : extendable |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Returns an extendable schema root node. |
no test coverage detected