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

143 lines (142 loc) 5.83 kB
import type { Fn, Nullish } from '../../../../../@aileron/declare'; import type { ArrayNode } from '../../../../../core/nodes/ArrayNode'; import { type ChildNode, type HandleChange, type SchemaNodeFactory, type UnionSetValueOption } from '../../../../../core/nodes/type'; import type { AllowedValue, ArrayValue } from '../../../../../types'; import type { ArrayNodeStrategy } from '../type'; export declare class BranchStrategy 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__; /** Factory function for creating new schema nodes */ private readonly __nodeFactory__; /** 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__; /** Flag indicating whether the strategy is locked to prevent recursive updates */ private __locked__; /** Flag indicating whether the strategy is already processing a batch */ private __batched__; /** Revision counter for generating unique keys for array elements */ private __revision__; /** Array of unique keys for each element in the array, maintaining order */ private __keys__; /** Map storing actual data and corresponding schema nodes for each array element */ private __sourceMap__; /** Flag indicating whether the array value is not changed */ private __idle__; private __nullish__; /** Flag indicating whether the array edges are expired */ private __expired__; /** Expire the array node's value and edges */ private __expire__; /** Current value of the array node */ private __value__; /** * Gets the current value of the array. * @returns Current value of the array node or undefined (if empty) or null (if nullable) */ 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; private __children__; /** * Gets the child nodes of the array node. * @returns List of child nodes */ get children(): ChildNode[]; /** * Gets the current length of the array. * @returns Length of the array */ get length(): number; /** * Propagates activation to all child nodes. * @internal Internal implementation method. Do not call directly. */ initialize(): void; /** * Initializes the BranchStrategy object. * @param host - Host ArrayNode object * @param handleChange - Value change handler * @param handleRefresh - Refresh handler * @param handleSetDefaultValue - Default value setting handler * @param nodeFactory - Node creation factory */ constructor(host: ArrayNode, hasDefault: boolean, handleChange: HandleChange<ArrayValue | Nullish>, handleRefresh: Fn<[ArrayValue | Nullish]>, handleSetDefaultValue: Fn<[ArrayValue | Nullish]>, nodeFactory: SchemaNodeFactory); /** * Adds a new element to the array. * @param data - Value to add (optional) * @returns Returns itself (this) for method chaining */ push(data?: ArrayValue[number], unlimited?: boolean, option?: UnionSetValueOption): Promise<number>; /** * Updates the value of a specific element. * @param index - Index of the element to update * @param data - New value * @returns Returns itself (this) for method chaining */ update(index: number, data: ArrayValue[number], option?: UnionSetValueOption): Promise<string | number | boolean | import("../../../../../types").VirtualNodeValue | ArrayValue | import("winglet/json-schema/dist").ObjectValue | Nullish>; /** * Removes a specific element. * @param index - Index of the element to remove * @returns Returns itself (this) for method chaining */ remove(index: number, option?: UnionSetValueOption): Promise<AllowedValue>; /** Removes the last element from the array. */ pop(): Promise<AllowedValue>; /** Clears all elements to initialize the array. */ clear(option?: UnionSetValueOption): Promise<undefined>; /** * Determines whether to queue or immediately process value changes. * * In batch mode: Publishes RequestEmitChange event for deferred processing * In sync mode: Immediately calls handleEmitChange for instant updates * * @param option - Change options (optional) * @private */ private __emitChange__; /** * Emits a value change event. * @param option - Option settings (default: SetValueOption.Default) * @private */ private __handleEmitChange__; /** * Gets information about child nodes. * @returns Array containing key and node information * @private */ private get __edges__(); /** * Converts internal array state to an object array. * @returns Array containing the values of the array * @private */ private __toArray__; /** * Creates a function to handle value changes for a specific element. * @param key - Child node Key * @returns {HandleChange} Value change handler * @private */ private __handleChangeFactory__; /** * Updates the names of array elements. * @private */ private __updateChildName__; /** * Publishes a child node update event. * @private */ private __publishUpdateChildren__; }