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

Function use

packages/core/src/node.ts:2666–2687  ·  view source on GitHub ↗
(
  node: FormKitNode,
  context: FormKitContext,
  plugin: FormKitPlugin | FormKitPlugin[] | Set<FormKitPlugin>,
  run = true,
  library = true
)

Source from the content-addressed store, hash-verified

2664 * @internal
2665 */
2666export function use(
2667 node: FormKitNode,
2668 context: FormKitContext,
2669 plugin: FormKitPlugin | FormKitPlugin[] | Set<FormKitPlugin>,
2670 run = true,
2671 library = true
2672): FormKitNode {
2673 if (Array.isArray(plugin) || plugin instanceof Set) {
2674 plugin.forEach((p: FormKitPlugin) => use(node, context, p))
2675 return node
2676 }
2677 if (!context.plugins.has(plugin)) {
2678 if (library && typeof plugin.library === 'function') plugin.library(node)
2679 // When plugins return false, they are never added as to the plugins Set
2680 // meaning they only ever have access to the single node they were added on.
2681 if (run && plugin(node) !== false) {
2682 context.plugins.add(plugin)
2683 node.children.forEach((child) => child.use(plugin))
2684 }
2685 }
2686 return node
2687}
2688
2689/**
2690 * Moves a node in the parent’s children to the given index.

Callers 1

nodeInitFunction · 0.70

Calls 1

pluginFunction · 0.85

Tested by

no test coverage detected