@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.07 kB
TypeScript
import type { Nullish } from '../../../@aileron/declare';
import type { ArraySchema, ArrayValue } from '../../../types';
import { AbstractNode } from '../AbstractNode';
import type { BranchNodeConstructorProps, HandleChange, SchemaNode, UnionSetValueOption } from '../type';
/**
* 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;
readonly type = "array";
/**
* Gets the value of the array node.
* @returns Array value or undefined (if empty) or null (if nullable)
*/
get value(): ArrayValue | Nullish;
/**
* Sets the value of the array node.
* @param input - Array value to set
*/
set value(input: ArrayValue | Nullish);
/**
* Applies input value to the array node.
* @param input - Array value to set
* @param option - Setting options
*/
protected applyValue(this: ArrayNode, input: ArrayValue | Nullish, 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.
*/
initialize(this: ArrayNode, actor?: SchemaNode): boolean;
protected onChange: HandleChange<ArrayValue | Nullish>;
constructor(properties: 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], unlimited?: boolean): 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 index - Index of the element to update
* @param data - New value
* @returns {Promise<ArrayValue[number]|undefined>} the value of the updated value
*/
update(this: ArrayNode, index: number, data: ArrayValue[number]): Promise<any>;
/**
* Removes a specific element.
* @param index - Index of the element to remove
* @returns {Promise<ArrayValue[number]|undefined>} value of the removed value
*/
remove(this: ArrayNode, index: number): Promise<any>;
/**
* Clears all elements to initialize the array.
* @returns {Promise<void>}
*/
clear(this: ArrayNode): Promise<void>;
}