@canard/schema-form
Version:
React-based component library that renders forms based on JSON Schema with plugin system support for validators and UI components
131 lines (130 loc) • 5.08 kB
TypeScript
import type { Fn } from '../../../../../@aileron/declare';
import type { ArrayNode } from '../../../../../core/nodes/ArrayNode';
import { type ChildNode, type SchemaNodeFactory, type UnionSetValueOption } from '../../../../../core/nodes/type';
import type { AllowedValue, ArrayValue } from '../../../../../types';
import type { ArrayNodeStrategy } from '../type';
type IndexId = `[${number}]`;
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__;
/** Flag indicating whether the strategy is locked to prevent recursive updates */
private __locked__;
/** Flag indicating whether the array has pending changes that need to be emitted */
private __dirty__;
/** Flag indicating whether the array value should be treated as undefined */
private __undefined__;
/** Setter for dirty flag that also resets undefined state when changes occur */
private set __changed__(value);
/** Sequence counter for generating unique IDs for array elements */
private __seq__;
/** Array of unique IDs for each element in the array, maintaining order */
private __ids__;
/** Map storing actual data and corresponding schema nodes for each array element */
private __sourceMap__;
/**
* Gets the current value of the array.
* @returns Current value of the array node or undefined (if empty)
*/
get value(): AllowedValue[] | 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 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.
*/
activate(): 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, handleChange: Fn<[ArrayValue | undefined]>, handleRefresh: Fn<[ArrayValue | undefined]>, handleSetDefaultValue: Fn<[ArrayValue | undefined]>, 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]): Promise<number>;
/**
* Updates the value of a specific element.
* @param id - ID or index of the element to update
* @param data - New value
* @returns Returns itself (this) for method chaining
*/
update(id: IndexId | number, data: ArrayValue[number]): Promise<string | number | boolean | ArrayValue | import("winglet/json-schema/dist").ObjectValue | import("../../../../../types").VirtualNodeValue | null | undefined>;
/**
* Removes a specific element.
* @param id - ID or index of the element to remove
* @returns Returns itself (this) for method chaining
*/
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 option - Option settings (default: SetValueOption.Default)
* @private
*/
private __emitChange__;
/**
* Gets information about child nodes.
* @returns Array containing ID 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 id - Element ID
* @returns Value change function
* @private
*/
private __handleChangeFactory__;
/**
* Updates the names of array elements.
* @private
*/
private __updateChildName__;
/**
* Publishes a child node update event.
* @private
*/
private __publishUpdateChildren__;
/**
* Publishes a value change request event.
* @param option - Change options (optional)
* @private
*/
private __publishRequestEmitChange__;
}
export {};