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

87 lines (86 loc) 3.45 kB
import type { Fn } from '../../../../../@aileron/declare'; import type { ArrayNode } from '../../../../../core/nodes/ArrayNode'; import { type UnionSetValueOption } from '../../../../../core/nodes/type'; import type { ArrayValue } from '../../../../../types'; import type { ArrayNodeStrategy, IndexId } from '../type'; export declare class TerminalStrategy implements ArrayNodeStrategy { /** Host ArrayNode instance that this strategy belongs to */ private readonly __host__; /** Callback function to handle value changes */ private readonly __handleChange__; /** Callback function to handle refresh operations */ private readonly __handleRefresh__; /** Default value to use when creating new array items */ private readonly __defaultItemValue__; /** Flag indicating whether the strategy is locked to prevent recursive updates */ private __locked__; /** Sequence counter for generating unique IDs for array elements */ private __seq__; /** Array of unique IDs for tracking array elements (used for element identification) */ private __ids__; /** Current value of the array node, initialized as empty array */ private __value__; /** * Gets the current value of the array. * @returns Current value of the array node or undefined */ get value(): ArrayValue | undefined; /** * Applies input value to the array node. * @param input - Array value to set * @param option - Setting options */ applyValue(input: ArrayValue, option: UnionSetValueOption): void; /** * Gets the list of child nodes. * @returns Empty array (Terminal strategy does not manage child nodes) */ get children(): null; /** * Gets the current length of the array. * @returns Length of the array (0 if value is undefined) */ get length(): number; /** * Initializes the TerminalStrategy object. * @param host - Host ArrayNode object * @param handleChange - Value change handler * @param handleRefresh - Refresh handler * @param handleSetDefaultValue - Default value setting handler */ constructor(host: ArrayNode, handleChange: Fn<[ArrayValue | undefined]>, handleRefresh: Fn<[ArrayValue | undefined]>, handleSetDefaultValue: Fn<[ArrayValue | undefined]>); /** * Adds a new element to the array. * @param input - Value to add (optional) */ push(input?: ArrayValue[number]): Promise<number>; /** * Updates the value of a specific element. * @param id - ID or index of the element to update * @param data - New value */ update(id: IndexId | number, data: ArrayValue[number]): Promise<any>; /** * Removes a specific element. * @param id - ID or index of the element to remove */ remove(id: IndexId | number): Promise<any>; /** Removes the last element from the array. */ pop(): Promise<any>; /** Clears all elements to initialize the array. */ clear(): Promise<undefined>; /** * Emits a value change event. * @param input - New array value * @param option - Option settings (default: SetValueOption.Default) * @private */ private __emitChange__; /** * Parses input value into appropriate array format. * @param input - Value to parse * @returns {ArrayValue|undefined} Parsed array value or undefined * @private */ private __parseValue__; }