| 882 | } |
| 883 | |
| 884 | function createElement( |
| 885 | lib: FormKitComponentLibrary, |
| 886 | node: FormKitSchemaNode |
| 887 | ): RenderNodes { |
| 888 | const [condition, element, attrs, children, alternate, iterator, resolve] = |
| 889 | parseNode(lib, node) |
| 890 | |
| 891 | let createNodes: RenderNodes = ((iterationData?: Record<string, unknown>) => { |
| 892 | if (condition && element === null && children) { |
| 893 | return condition() |
| 894 | ? children(iterationData) |
| 895 | : alternate && alternate(iterationData) |
| 896 | } |
| 897 | |
| 898 | if (element && (!condition || condition())) { |
| 899 | if (element === 'text') { |
| 900 | return children ? String(children(iterationData)) : '' |
| 901 | } |
| 902 | |
| 903 | if (element === 'slot' && children) { |
| 904 | return children(iterationData) |
| 905 | } |
| 906 | |
| 907 | const resolvedEl = |
| 908 | resolve && typeof element === 'string' |
| 909 | ? (lib[element] || (globalThis as any)[element]) |
| 910 | : element |
| 911 | |
| 912 | if (!resolvedEl) { |
| 913 | return null |
| 914 | } |
| 915 | |
| 916 | let normalizedAttrs = normalizeAttrs( |
| 917 | resolvedEl as string | ComponentType<any> | null, |
| 918 | attrs() |
| 919 | ) |
| 920 | const slots: RenderableSlots | null = children?.slot |
| 921 | ? createSlots(children, iterationData) |
| 922 | : null |
| 923 | |
| 924 | if (slots) { |
| 925 | return h( |
| 926 | resolvedEl as ComponentType<any>, |
| 927 | { |
| 928 | ...(normalizedAttrs || {}), |
| 929 | slots, |
| 930 | }, |
| 931 | slots.default ? slots.default() : null |
| 932 | ) |
| 933 | } |
| 934 | |
| 935 | let renderedChildren = |
| 936 | normalizedAttrs && |
| 937 | typeof normalizedAttrs === 'object' && |
| 938 | 'dangerouslySetInnerHTML' in normalizedAttrs |
| 939 | ? null |
| 940 | : ((children ? children(iterationData) : null) as ReactNode) |
| 941 | |