@canard/schema-form
Version:
React-based component library that renders forms based on JSON Schema with plugin system support for validators and UI components
197 lines (196 loc) • 8.35 kB
TypeScript
import type { Fn, Nullish } from '../../../../../@aileron/declare';
import type { ObjectNode } from '../../../../../core/nodes/ObjectNode';
import { type ChildNode, type HandleChange, type SchemaNodeFactory, type UnionSetValueOption } from '../../../../../core/nodes/type';
import type { ObjectValue } from '../../../../../types';
import type { ObjectNodeStrategy } from '../type';
export declare class BranchStrategy implements ObjectNodeStrategy {
/** Host ObjectNode instance that this strategy belongs to */
private readonly __host__;
/** Flag indicating whether to ignore additional properties */
private readonly __ignoreAdditionalProperties__;
/** Callback function to handle value changes */
private readonly __handleChange__;
/** Callback function to handle refresh operations */
private readonly __handleRefresh__;
/** Callback function to handle computed properties updates */
private readonly __handleUpdateComputedProperties__;
/** Array of schema property keys in order */
private readonly __propertyKeys__;
/** Set of all oneOf schema keys, undefined if no oneOf schema exists */
private readonly __oneOfKeySet__?;
/** Array of key sets for each oneOf branch, undefined if no oneOf schema exists */
private readonly __oneOfKeySetList__?;
/** Array of child node arrays for each oneOf branch */
private readonly __oneOfChildNodeMapList__?;
/** Set of all anyOf schema keys, undefined if no anyOf schema exists */
private readonly __anyOfKeySet__?;
/** Array of key sets for each anyOf branch, undefined if no anyOf schema exists */
private readonly __anyOfKeySetList__?;
/** Array of child node arrays for each anyOf branch */
private readonly __anyOfChildNodeMapList__?;
/** Array of child nodes for regular properties (non-oneOf) */
private readonly __propertyChildren__;
/** Map of field conditions for conditional schema properties */
private readonly __fieldConditionMap__?;
/** Map of property keys to child nodes */
private readonly __childNodeMap__;
/** Flag indicating whether the node is in isolation mode (affects condition processing) */
private __isolated__;
/** Flag indicating whether the strategy is already processing a batch */
private __batched__;
/** Flag indicating whether the strategy is locked to prevent recursive updates */
private __locked__;
/** Current committed value of the object node */
private __value__;
/** Draft value containing pending changes before commit */
private __draft__;
/** Flag indicating whether the object value is expired */
private __expired__;
/**
* Gets the current value of the object.
* @returns Current value of the object node or undefined
*/
get value(): ObjectValue | Nullish;
/**
* Applies input value to the object node.
* @param input - Object value to set
* @param option - Setting options
*/
applyValue(input: ObjectValue | Nullish, option: UnionSetValueOption): void;
/** Current active children nodes (combination of property and oneOf children) */
private __children__;
/**
* Gets the child nodes of the object node.
* @returns List of child nodes
*/
get children(): ChildNode[];
/** Array of child nodes for regular properties and oneOf properties */
private readonly __subnodes__;
/**
* Gets all of the child nodes of the object node.
* @returns List of child nodes
*/
get subnodes(): ChildNode[];
/**
* Propagates activation to all child nodes.
* @internal Internal implementation method. Do not call directly.
*/
initialize(): void;
/**
* Initializes the BranchStrategy object.
* @param host - Host ObjectNode object
* @param handleChange - Value change handler
* @param handleRefresh - Refresh handler
* @param handleSetDefaultValue - Default value setting handler
* @param handleUpdateComputedProperties - Computed properties update handler
* @param nodeFactory - Node creation factory
*/
constructor(host: ObjectNode, handleChange: HandleChange<ObjectValue | Nullish>, handleRefresh: Fn<[ObjectValue | Nullish]>, handleSetDefaultValue: Fn<[ObjectValue | Nullish]>, handleUpdateComputedProperties: Fn, nodeFactory: SchemaNodeFactory);
/**
* 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__;
/**
* Reflects value changes and publishes related events.
* @param option - Setting options
* @private
*/
private __handleEmitChange__;
/**
* Parses input value and processes it as an object.
* @param base - Base object to parse
* @param draft - Draft object to parse
* @param nullable - Whether the object is nullable
* @param replace - Whether to replace the existing value
* @returns {ObjectValue} Processed object
* @private
*/
private __parseValue__;
/**
* Processes input value and processes it as an object.
* @param input - Object to parse
* @returns {ObjectValue} Parsed object
* @private
*/
private __processValue__;
/**
* Propagates value changes to child nodes.
* @param replace - Whether to replace existing values
* @param option - Setting options
* @private
*/
private __propagate__;
/** Previously active oneOf index for tracking oneOf branch changes */
private __oneOfIndex__;
/** Active oneOf child node map */
private __oneOfChildNodeMap__;
/** Previously active anyOf index for tracking anyOf branch changes */
private __anyOfIndices__;
/** Active anyOf child node maps */
private __anyOfChildNodeMaps__;
/** Function to validate composition value */
private __validateAllowedKey__;
/** Whether the object node has no oneOf and anyOf schema */
private get __isPristine__();
/**
* Updates child nodes when oneOf index changes, if oneOf schema exists.
* @private
*/
private __prepareCompositionChildren__;
/**
* Updates child nodes when oneOf index changes, if oneOf schema exists.
* @private
*/
private __processOneOfChildren__;
/**
* Updates child nodes when anyOf indices change, if anyOf schema exists.
* @param isolation - Whether the operation is in isolation mode
* @returns Array of active anyOf child node maps, null if no change needed, or undefined if no active anyOf branches
* @private
*/
private __processAnyOfChildren__;
/**
* Updates the active children array based on current oneOf and anyOf selections.
* @param oneOfChildNodeMap - Active oneOf child node map (null if no oneOf or none selected)
* @param anyOfChildNodeMaps - Array of active anyOf child node maps (null if no anyOf or none selected)
* @private
*/
private __processChildren__;
/**
* Processes and validates the object value according to active composition branches.
* Filters out properties that are not allowed by current oneOf/anyOf selections.
* @param isolation - Whether the operation is in isolation mode
* @private
*/
private __processCompositionValue__;
/**
* Creates a validator function that determines whether a property key is allowed
* based on the current oneOf and anyOf selections.
* @returns Function that validates if a property key should be included in the object value
* @private
*/
private __createAllowedKeyValidator__;
/**
* Prepares the process computed properties.
* @private
*/
private __prepareProcessComputedProperties__;
/**
* Excludes values of invisible child elements from the computed value.
* @param source - Source object to check
* @returns Whether the computed properties were processed
* @private
*/
private __processComputedProperties__;
/**
* Publishes a child node change event.
* @private
*/
private __publishChildrenChange__;
}