MCPcopy Index your code
hub / github.com/formkit/formkit / parseNode

Function parseNode

packages/react/src/FormKitSchema.ts:747–865  ·  view source on GitHub ↗
(
    lib: FormKitComponentLibrary,
    _node: FormKitSchemaNode
  )

Source from the content-addressed store, hash-verified

745 }
746
747 function parseNode(
748 lib: FormKitComponentLibrary,
749 _node: FormKitSchemaNode
750 ): RenderContent {
751 let element: RenderContent[1] = null
752 let attrs: () => any = () => null
753 let condition: false | (() => any) = false
754 let children: RenderContent[3] = null
755 let alternate: RenderContent[4] = null
756 let iterator: RenderContent[5] = null
757 let resolve = false
758
759 const node = sugar(_node)
760
761 if (isDOM(node)) {
762 element = node.$el
763 attrs = node.$el !== 'text' ? parseAttrs(node.attrs, node.bind) : () => null
764 } else if (isComponent(node)) {
765 if (typeof node.$cmp === 'string') {
766 if (has(lib, node.$cmp)) {
767 element = lib[node.$cmp]
768 } else {
769 element = node.$cmp
770 resolve = true
771 }
772 } else {
773 element = node.$cmp
774 }
775 attrs = parseAttrs(node.props, node.bind)
776 } else if (isConditional(node)) {
777 ;[condition, children, alternate] = parseCondition(lib, node)
778 }
779
780 if (!isConditional(node) && 'if' in node) {
781 condition = provider(compile(node.if as string))
782 } else if (!isConditional(node) && element === null) {
783 condition = () => true
784 }
785
786 if ('children' in node) {
787 if (typeof node.children === 'string') {
788 if (node.children.startsWith('$slots.')) {
789 element = element === 'text' ? 'slot' : element
790 children = provider(compile(node.children))
791 } else if (node.children.startsWith('$') && node.children.length > 1) {
792 const value = provider(compile(node.children))
793 children = () => String(value())
794 } else {
795 children = () => String(node.children)
796 }
797 } else if (Array.isArray(node.children)) {
798 children = createElements(lib, node.children)
799 } else if (node.children) {
800 const [childCondition, c, a] = parseCondition(lib, node.children)
801 children = (iterationData?: Record<string, unknown>) =>
802 childCondition && childCondition()
803 ? c && c(iterationData)
804 : a && a(iterationData)

Callers 1

createElementFunction · 0.70

Calls 13

sugarFunction · 0.90
isDOMFunction · 0.90
isComponentFunction · 0.90
hasFunction · 0.90
isConditionalFunction · 0.90
compileFunction · 0.90
valueFunction · 0.85
cFunction · 0.85
parseAttrsFunction · 0.70
parseConditionFunction · 0.70
providerFunction · 0.70
createElementsFunction · 0.70

Tested by

no test coverage detected