import { type Nullable } from "@onerjs/core/types.js"; import { ConnectionPointType } from "../connection/connectionPointType.js"; import { type InitializationData, type SmartFilter } from "../smartFilter.js"; import { type ICommandOwner } from "../command/command.js"; import { ConnectionPoint, type RuntimeData } from "../connection/connectionPoint.js"; import { ConnectionPointWithDefault } from "../connection/connectionPointWithDefault.js"; /** * Defines a callback function that is triggered when visiting a block, * It also carries over extra data preventing the need to use global variables or closures. */ export type BlockVisitor = (block: BaseBlock, extraData: T) => void; /** * This class represents the base class for all smart filter blocks. * * It defines the basic structure of a smart filter block and provides the base implementation for * managing the connection points. * * It enforces common behavior for all smart filter blocks. */ export declare abstract class BaseBlock implements ICommandOwner { readonly disableOptimization: boolean; protected static _AlreadyVisitedBlocks: Set; /** * The class name of the block. */ static ClassName: string; /** * The namespace of the block, which is used to reduce name collisions between blocks and also to group blocks in the editor UI. * By convention, sub namespaces are separated by a period (e.g. "Babylon.Demo.Effects"). */ static Namespace: Nullable; /** * The smart filter the block belongs to. */ readonly smartFilter: SmartFilter; /** * Global unique id of the block (This is unique for the current session). */ uniqueId: number; /** * The name of the block. This is used to identify the block in the smart filter or in debug. */ readonly name: string; /** * The type of the block - used when serializing / deserializing the block, and in the editor. * For programmatically created blocks, this should be the class name of the block. * For custom blocks, this is specified in the block definition. */ get blockType(): string; /** * The namespace of the block, which is used to reduce name collisions between blocks and also to group blocks in the editor UI. * By convention, sub namespaces are separated by a period (e.g. "Babylon.Demo.Effects"). */ get namespace(): Nullable; /** * User provided comments about the block. It can be used to document the block. */ comments: Nullable; private readonly _inputs; private readonly _outputs; /** * Instantiates a new block. * @param smartFilter - Defines the smart filter the block belongs to * @param name - Defines the name of the block * @param disableOptimization - Defines if the block is optimizable or not */ constructor(smartFilter: SmartFilter, name: string, disableOptimization?: boolean); /** * Returns the inputs connection points of the current block. */ get inputs(): ReadonlyArray; /** * Returns the outputs connection points of the current block. */ get outputs(): ReadonlyArray; /** * Returns if the block is an input block. */ get isInput(): boolean; /** * Returns if the block is an output block. */ get isOutput(): boolean; /** * @returns the class name of the block */ getClassName(): string; /** * Checks if the block is an "ancestor" of another giving block. * @param block - Defines the block to check against * @returns True if the block is an ancestor of the given block, otherwise false */ isAnAncestorOf(block: BaseBlock): boolean; protected _visitInputs(extraData: T, callback: BlockVisitor, alreadyVisited: Set): void; /** * Visits the block and its inputs recursively. * When starting from the smart filter output block, this will visit all the blocks in the smart filter. * Note that it's a depth first visit: the callback is called on the block AFTER visiting its inputs. * @param extraData - The extra data to pass to the callback * @param callback - The callback to call on each block * @param alreadyVisitedBlocks - Defines the set of blocks already visited (if not provided, a new set will be created) */ visit(extraData: T, callback: BlockVisitor, alreadyVisitedBlocks?: Set): void; /** * Finds the input connection point with the given name. * @param name - Name of the input to find * @returns The connection point with the given name or null if not found */ findInput(name: string): Nullable>; /** * Disconnects the block from the graph. * @param _disconnectedConnections - Stores the connections that have been broken in the process. You can reconnect them later if needed. */ disconnectFromGraph(_disconnectedConnections?: [ConnectionPoint, ConnectionPoint][]): void; /** * Prepares the block for runtime. * This is called by the smart filter just before creating the smart filter runtime, and by the optimizer. */ prepareForRuntime(): void; /** * Propagates the runtime data - telling all outputs to propagate their runtime data forward through the graph */ propagateRuntimeData(): void; /** * Generates the commands needed to execute the block at runtime and gathers promises for initialization work * @param initializationData - The initialization data to use * @param _finalOutput - Defines if the block is the final output of the smart filter */ generateCommandsAndGatherInitPromises(initializationData: InitializationData, _finalOutput: boolean): void; /** * Disconnects all the inputs and outputs from the Block. */ disconnect(): void; /** * Registers a new input connection point in the block which must have a connection before the graph can be used. * @param name - Defines the name of the input connection point * @param type - Defines the type of the input connection point * @param defaultValue - Defines the optional default value of the input connection point to use if not connection is made * @returns The new ConnectionPoint * @internal */ _registerInput(name: string, type: U, defaultValue?: Nullable>): ConnectionPoint; /** * Registers a new input connection point in the block which doesn't require a connection because it has a default value. * @param name - Defines the name of the input connection point * @param type - Defines the type of the input connection point * @param defaultValue - Defines the default value to use if nothing is connected to this connection point * @returns The new ConnectionPointWithDefault * @internal */ _registerOptionalInput(name: string, type: U, defaultValue: RuntimeData): ConnectionPointWithDefault; /** * Registers a new output connection point in the block. * @param name - Defines the name of the output connection point * @param type - Defines the type of the output connection point * @returns The new output connection point * @internal */ _registerOutput(name: string, type: U): ConnectionPoint; /** * Registers a new output connection point in the block that always has runtimeData because it has a default value and doesn't allow it to be overwritten with null. * @param name - Defines the name of the output connection point * @param type - Defines the type of the output connection point * @param initialValue - Defines the initial value of the output connection point * @returns The new output connection point with a default value * @internal */ _registerOutputWithDefault(name: string, type: U, initialValue: RuntimeData): ConnectionPointWithDefault; /** * Gets the required RuntimeData for the given input, throwing with a clear message if it is null * @param input - The input to get the runtime data for * @returns The runtimeData or throws if it was undefined */ protected _confirmRuntimeDataSupplied(input: ConnectionPoint): RuntimeData; } //# sourceMappingURL=baseBlock.d.ts.map