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

100 lines (99 loc) 4.21 kB
import type { Fn, Nullish } from '../../../../../@aileron/declare'; import type { ArrayNode } from '../../../../../core/nodes/ArrayNode'; import { type HandleChange, type UnionSetValueOption } from '../../../../../core/nodes/type'; import type { ArrayValue } from '../../../../../types'; import type { ArrayNodeStrategy } 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__; /** Minimum number of items required in the array (from JSON Schema minItems) */ private readonly __minItems__; /** Maximum number of items allowed in the array (from JSON Schema maxItems) */ private readonly __maxItems__; /** Default value to use when creating new array items */ private readonly __defaultItemValue__; /** Default value to use when creating new array prefixItems */ private readonly __defaultPrefixItemValues__; /** * Gets the default value for a new array item based on its position. * * Returns the appropriate default value considering `prefixItems`: * - If `prefixItems` is defined and the current length is within its range, * returns the default value from the corresponding prefixItems schema * - Otherwise, returns the default value from the `items` schema * * @returns The default value to use when adding a new item at the current position */ private get __defaultValue__(); /** Flag indicating whether the strategy is locked to prevent recursive updates */ private __locked__; /** 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 or null */ get value(): ArrayValue | Nullish; /** * Applies input value to the array node. * @param input - Array value to set * @param option - Setting options */ applyValue(input: ArrayValue | Nullish, 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 or null) */ 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, hasDefault: boolean, handleChange: HandleChange<ArrayValue | Nullish>, handleRefresh: Fn<[ArrayValue | Nullish]>, handleSetDefaultValue: Fn<[ArrayValue | Nullish]>); /** * Adds a new element to the array. * @param input - Value to add (optional) */ push(input?: ArrayValue[number], unlimited?: boolean): Promise<number>; /** * Updates the value of a specific element. * @param index - Index of the element to update * @param data - New value */ update(index: number, data: ArrayValue[number]): Promise<any>; /** * Removes a specific element. * @param index - Index of the element to remove */ remove(index: 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|null|undefined} Parsed array value or undefined or null * @private */ private __parseValue__; }