MCPcopy Create free account
hub / github.com/formkit/formkit / getNode

Function getNode

packages/core/src/node.ts:2798–2836  ·  view source on GitHub ↗

* Fetches a node from the tree by its address. * * @param node - A FormKitNode | FormKitNode * @param _context - A FormKitContext | FormKitContext * @param locator - A string or FormKitAddress | FormKitAddress to find in the tree. * * @returns A {@link FormKitNode | For

(
  node: FormKitNode,
  _context: FormKitContext,
  locator: string | FormKitAddress
)

Source from the content-addressed store, hash-verified

2796 * @internal
2797 */
2798function getNode(
2799 node: FormKitNode,
2800 _context: FormKitContext,
2801 locator: string | FormKitAddress
2802): FormKitNode | undefined {
2803 const address =
2804 typeof locator === 'string' ? locator.split(node.config.delimiter) : locator
2805 if (!address.length) return undefined
2806 const first = address[0]
2807 let pointer: FormKitNode | null | undefined = node.parent
2808 if (!pointer) {
2809 // This address names the root node, remove it to get child name:
2810 if (String(address[0]) === String(node.name)) address.shift()
2811 // All root nodes start at themselves ultimately:
2812 pointer = node
2813 }
2814 // Any addresses starting with $parent should discard it
2815 if (first === '$parent') address.shift()
2816 while (pointer && address.length) {
2817 const name = address.shift() as string | number
2818 switch (name) {
2819 case '$root':
2820 pointer = node.root
2821 break
2822 case '$parent':
2823 pointer = pointer.parent
2824 break
2825 case '$self':
2826 pointer = node
2827 break
2828 default:
2829 pointer =
2830 (pointer.children.find(
2831 (c) => !('__FKP' in c) && String(c.name) === String(name)
2832 ) as FormKitNode | undefined) || select(pointer, name)
2833 }
2834 }
2835 return pointer || undefined
2836}
2837
2838/**
2839 * Perform selections on a subtree using the address "selector" methods.

Callers 15

getFunction · 0.90
useFormKitContextByIdFunction · 0.90
useFormKitNodeByIdFunction · 0.90
ssr.spec.tsFile · 0.90
plugin.spec.tsFile · 0.90
form.spec.tsFile · 0.90
text.spec.tsFile · 0.90
select.spec.tsFile · 0.90
group.spec.tsFile · 0.90
file.spec.tsFile · 0.90
list.spec.tsFile · 0.90

Calls 1

selectFunction · 0.70

Tested by 4

mountedFunction · 0.72
swapSchemaFunction · 0.72
isDirtyFunction · 0.72
submitFunction · 0.72