UNPKG

@canard/schema-form

Version:

React-based component library that renders forms based on JSON Schema with plugin system support for validators and UI components

78 lines (77 loc) 3.14 kB
import type { Fn } from '../../../@aileron/declare'; import type { ArraySchema, ArrayValue } from '../../../types'; import { AbstractNode } from '../AbstractNode'; import type { BranchNodeConstructorProps, SchemaNode, UnionSetValueOption } from '../type'; import { type IndexId } from './strategies'; /** * A node class for handling array schemas. * Manages each element of the array and provides push/pop/update/remove/clear functionality. */ export declare class ArrayNode extends AbstractNode<ArraySchema, ArrayValue> { #private; /** * Gets the value of the array node. * @returns Array value or undefined */ get value(): ArrayValue | undefined; /** * Sets the value of the array node. * @param input - Array value to set */ set value(input: ArrayValue | undefined); /** * Applies input value to the array node. * @param input - Array value to set * @param option - Setting options */ protected applyValue(this: ArrayNode, input: ArrayValue, option: UnionSetValueOption): void; /** Child nodes of ArrayNode */ /** * Gets the child nodes of the array node. * @returns List of child nodes */ get children(): import("../type").ChildNode[] | null; /** * Gets the current length of the array. * @returns Length of the array */ get length(): number; /** * Activates this ArrayNode and propagates activation to all child nodes. * @param actor - The node that requested activation * @returns {boolean} Whether activation was successful * @internal Internal implementation method. Do not call directly. */ activate(this: ArrayNode, actor?: SchemaNode): boolean; protected onChange: Fn<[input: ArrayValue | undefined]>; constructor({ key, name, jsonSchema, defaultValue, onChange, nodeFactory, parentNode, validationMode, validatorFactory, required, }: BranchNodeConstructorProps<ArraySchema>); /** * Adds a new element to the array. * @param data - Value to add (optional) * @returns {Promise<number> } the length of the array after the push operation */ push(this: ArrayNode, data?: ArrayValue[number]): Promise<number>; /** * Removes the last element from the array. * @returns {Promise<ArrayValue[number]|undefined>} the value of the removed value */ pop(this: ArrayNode): Promise<any>; /** * Updates the value of a specific element. * @param id - ID or index of the element to update * @param data - New value * @returns {Promise<ArrayValue[number]|undefined>} the value of the updated value */ update(this: ArrayNode, id: IndexId | number, data: ArrayValue[number]): Promise<any>; /** * Removes a specific element. * @param id - ID or index of the element to remove * @returns {Promise<ArrayValue[number]|undefined>} value of the removed value */ remove(this: ArrayNode, id: IndexId | number): Promise<any>; /** * Clears all elements to initialize the array. * @returns {Promise<void>} */ clear(this: ArrayNode): Promise<void>; }