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

Function createConfig

packages/core/src/node.ts:2944–3015  ·  view source on GitHub ↗

* Creates a new configuration option. * * @param target - An object of optional properties of FormKitConfig | FormKitConfig * @param parent - A parent FormKitNode | FormKitNode * * @returns FormKitNode | FormKitNode * * @internal

(
  target: Partial<FormKitConfig> = {},
  parent?: FormKitNode | null
)

Source from the content-addressed store, hash-verified

2942 * @internal
2943 */
2944function createConfig(
2945 target: Partial<FormKitConfig> = {},
2946 parent?: FormKitNode | null
2947): FormKitConfig {
2948 let node: FormKitNode | undefined = undefined
2949 const getExplicitInheritedValue = (prop: string) => {
2950 let currentParent = parent
2951 while (currentParent) {
2952 const parentValue = currentParent.config._t[prop]
2953 if (parentValue !== undefined) return parentValue
2954 currentParent = currentParent.parent
2955 }
2956 if (target.rootConfig) {
2957 const rootValue = target.rootConfig[prop]
2958 if (rootValue !== undefined) return rootValue
2959 }
2960 return undefined
2961 }
2962 return new Proxy(target, {
2963 get(...args) {
2964 const prop = args[1]
2965 if (prop === '_t') return target
2966 const localValue = Reflect.get(...args)
2967 // Check our local values first
2968 if (localValue !== undefined) return localValue
2969 // Input nodes default to 20ms delay unless an ancestor/root explicitly
2970 // configured a different value.
2971 if (prop === 'delay' && node?.type === 'input') {
2972 const inheritedDelay = getExplicitInheritedValue(prop)
2973 return inheritedDelay !== undefined ? inheritedDelay : 20
2974 }
2975 // Then check our parent values next
2976 if (parent) {
2977 const parentVal = parent.config[prop as string]
2978 if (parentVal !== undefined) return parentVal
2979 }
2980 if (target.rootConfig && typeof prop === 'string') {
2981 const rootValue = target.rootConfig[prop]
2982 if (rootValue !== undefined) return rootValue
2983 }
2984 // The default delay value should be 20
2985 if (prop === 'delay' && node?.type === 'input') return 20
2986 // Finally check the default values
2987 return defaultConfig[prop as string]
2988 },
2989 set(...args) {
2990 const prop = args[1] as string
2991 const value = args[2]
2992 if (prop === '_n') {
2993 node = value as FormKitNode
2994 if (target.rootConfig) target.rootConfig._add(node)
2995 return true
2996 }
2997 if (prop === '_rmn') {
2998 if (target.rootConfig) target.rootConfig._rm(node as FormKitNode)
2999 node = undefined
3000 return true
3001 }

Callers 6

createPluginFunction · 0.90
normalizeOptionsFunction · 0.90
installFunction · 0.90
useConfigFunction · 0.90
resetConfigFunction · 0.70
createContextFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected