import { ContextManager } from './context'; import { Entity } from './entity'; import { Observable } from './observable'; import type { Behavior, BehaviorConstructor } from './behavior'; /** * Type representing the constructor properties of a given component type. * * This type extracts the constructor properties of a component if the component extends from `Component`. Otherwise, it results in `never`. * @typeParam ComponentType - The component type to extract the constructor properties from. */ export type ConstructorPropsOfComponent = ComponentType extends Component ? R : never; /** * Type representing the constructor function for a component. * * It defines a constructor type for a component given its constructor properties and component type. * @typeParam ConstructorPropsType - The constructor properties type. * @typeParam ComponentType - The type of the component. */ export type ComponentConstructor = new (props: ConstructorPropsType, contextManager: ContextManager) => ComponentType; /** * Type representing a constructor for a specific component. * * It defines a constructor type that takes a context manager and the constructor properties of the component. * @typeParam ComponentType - The component type for which the constructor is defined. */ export type ConstructorForComponent = new (contextManager: ContextManager, props: ComponentType extends Component ? PropsType : never) => ComponentType; /** * Type representing a child of a component. * * It defines a tuple representing a child component, which includes its constructor, properties, and an optional observable reference. * @typeParam ComponentType - The type of the component which the child belongs to. */ export type ComponentChild = [ConstructorForComponent, ComponentType extends Component ? U : never] | [ConstructorForComponent, ComponentType extends Component ? U : never, Observable]; /** * Type representing an array of component children. * * This type is used to define an array of children for a component, where each child is represented by the `ComponentChild` type. */ export type ComponentChildren = ComponentChild[]; /** * Interface representing the constructor properties of a component. * * This interface defines a standard structure for properties that can be passed to a component's constructor, including an optional `children` property. */ export interface ConstructorProps { [id: string]: any; children?: ComponentChildren; } /** * Base class for all components. * * Components define the different types of nodes you can have in your project. * Each component provides a set of functionalities and properties that you can add as nodes in your project’s Hierarchy, as many times as you like. * While there are many components included with Mattercraft (such as `Box` and `Group`), you can also create your own by extending the Component class. * * @link [custom-components](https://docs.zap.works/mattercraft/scripting/custom-components/) */ export declare class Component extends Entity { protected constructorProps?: ConstructorPropsType | undefined; /** * The raw element(s) that this component exposes */ element?: ElementType; /** * The children of this component. */ readonly children: Component[]; /** * The behaviors attached to this component. */ readonly behaviors: Behavior[]; /** * The parent of this component. */ parent?: Component; /** * If true, this component can't be selected at design time in the 3D preview. */ locked?: boolean; /** * Creates an instance of Component. * @param contextManager The current ContextManager * @param constructorProps - The constructor properties. */ constructor(contextManager: ContextManager, constructorProps?: ConstructorPropsType | undefined); /** * Constructs the children of this component. */ constructChildren(children: ComponentChildren, contextManager?: ContextManager): void; /** * Adds the supplied component instance as a child of this component, removing it from any existing parent. * * @param c The component instance to add */ appendChild(c: Component): void; /** * Removes the supplied component instance from the list of children. * @param c The component to remove */ removeChild(c: Component): void; /** * Removes this component from its parent component. */ remove(): void; /** * Adds a behavior to the component. * @param {Behavior} b - The behavior to add. */ addBehavior(b: Behavior): void; /** * Removes a behavior from the component. * @param {Behavior} b - The behavior to remove. */ removeBehavior(b: Behavior): void; /** * Gets a behavior of a specific type from the component. * @param {T} type - The type of behavior to get. * @returns {InstanceType | undefined} The behavior of the specified type, or undefined if no such behavior exists. * @template T The behavior type. */ getBehavior(type: T): InstanceType | undefined; /** * Gets all behaviors of a specific type from the component. * @param {T} type - The type of behaviors to get. * @returns {InstanceType[]} An array of behaviors of the specified type. * @template T The behavior type. */ getBehaviors(type: T): InstanceType[]; /** * An array of the elements that this component instance exposes. In the case that this component * does not expose any elements of its own, this will be an array of the elements * exposed by this component's children. */ get elementsResolved(): any[]; /** * Returns true if this component, or any of its parents, are marked as locked. */ get lockedResolved(): boolean; /** * An array of string 'tags' assocated with this component. * * The `getComponentsByTag(mgr, tag)` function can be used to get an array of components * with the supplied tag. * * By default, tags are scoped to the ZComponent instance that a component is constructed by. * Tags that begin with `global:` are scoped to the experience as a whole. * * @zprop * @zgroup Other * @group Other * @zgrouppriority 0 */ readonly tags: Observable; private _updateEnabledResolved; private _updateTags; /** * Dispose of this component and all of its children. */ dispose(): never; }