<aside> đź’ˇ Context: Block is associated with PluginExtensionInstance under the reearth.plugins namespace.

</aside>

Structure:

Block<P = any> = {
  id: string;
  pluginId?: string;
  extensionId?: string;
  property?: P;
  propertyId?: string;
};

Methods:

id:

Description: This is a unique string that distinctly identifies each block within a plugin extension. Each block represents a specific component or functional element that can be part of a larger plugin system, potentially interacting with or enhancing the functionality of the reearth.

The id of a block is essential for programmatically referencing and managing the block, particularly when manipulating its properties, updating its content, or interacting with it within the broader context of the plugin's operation. This identifier ensures that each block can be uniquely accessed and controlled, making it possible to dynamically adjust the block's behavior or appearance as needed.

Type:

id: string;

//The id is a string that uniquely identifies a Block within the context of a plugin extension. 
//This unique identification is crucial for tasks such as retrieving the block, modifying its properties, or applying specific operations to it within the plugin's architecture. 
//The id provides a way to reference the block consistently across the platform, facilitating robust and error-free interactions within complex plugin systems.

pluginId:

Description: This s an optional string that identifies the plugin to which the block belongs. This identifier links a specific block to a plugin that provides it, ensuring that the block can utilize functionalities or resources offered by that plugin. The pluginId is crucial for maintaining the association between blocks and their respective plugins, facilitating the correct integration and functioning of blocks within the larger plugin ecosystem on reearth.

The presence of a pluginId in a block allows for more organized management of blocks, as blocks are often components of plugins that add specific capabilities or enhancements to the reearth environment. By referencing the pluginId, developers can ensure that each block is correctly attributed to its source plugin, which is essential for operations like updating, configuring, or extending the functionalities of blocks within projects.

Type:

pluginId?: string;

//The pluginId is an optional string that acts as the unique identifier for the plugin that provides or governs the block. 
//If specified, it clearly establishes the relationship between the block and its parent plugin, allowing for seamless interaction and management within the plugin’s architecture. 
//If this property is not set, it may imply that the block does not depend on any external plugin for its functionalities or that it is part of the core functionalities provided directly by the Reearth platform. 
//This flexibility allows blocks to be either independent or tightly integrated with specific plugins, depending on the design and requirements of the application.

extensionId:

Description: This is an optional string that specifies the identifier of a particular extension within the plugin that the block is associated with. This property links the block to a specific functionality or module provided by the plugin, allowing the block to leverage specialized capabilities that enhance or modify its behavior within reearth.

The extensionId is crucial for identifying which specific extension of a plugin is being utilized by a block. Extensions within a plugin can offer various functionalities, such as different types of visualizations, data processing methods, or interactive components. By specifying an extensionId, developers ensure that the block is correctly integrated with the right set of features and functionalities offered by the plugin, facilitating precise and effective enhancements to the platform's capabilities.

Type:

extensionId?: string;

//The extensionId is an optional string that acts as the unique identifier for a specific extension within a plugin. 
//If provided, this ID confirms that the block is associated with and dependent on that particular extension for its operations. 
//This identification is vital for the proper functioning and integration of the block within the plugin's ecosystem. 
//If this property is not specified, it suggests that the block either operates independently of any specific extensions or relies on the general functionalities provided by the plugin or the platform itself. 
//This setup allows for flexibility in how blocks are configured and used within different projects on the Reearth platform.

property:

Description: This attribute is an optional generic parameter (P) that stores custom properties and settings specific to that block. These properties are crucial for defining the behavior and appearance of the block as it operates within the context of a plugin. The flexibility of the property allows it to adapt to various functionalities provided by the plugin, ranging from visual settings and interactive controls to complex data handling specific to the plugin’s extension.

This property field allows developers to tailor the block’s functions and interactions to enhance user experience or to meet specific operational requirements within the reearth environment. For example, a block associated with a mapping plugin might have properties related to geographic data displays, while a block from a visualization plugin might contain properties that configure the aesthetics of data representation.

Type:

property?: P;

//The property is a generic type that can represent any structure of data, providing great flexibility in customizing the block’s behavior and capabilities within the plugin. 
//This might include configurations like display options, interaction rules, or data processing parameters specific to the plugin's purpose. 
//The specific type P is defined based on what the block needs to function optimally within the plugin’s ecosystem, ensuring that each block can effectively use or enhance the plugin’s capabilities.

propertyId:

Description: This is an optional string that serves as a unique identifier linking the block to a specific set of externally defined properties. This identifier is crucial for connecting the block to a pre-defined configuration or data set stored outside of the block itself, typically managed within the plugin's system or a central property database.

The propertyId facilitates the dynamic application and integration of these properties into the block, enabling the block to inherit attributes, configurations, or behaviors defined by these external properties without embedding them directly into the block's structure. This linkage is particularly important in plugin environments where blocks may need to adapt or modify their functionality based on external configurations or when properties need to be shared among multiple blocks or components within the same plugin.

Type:

propertyId?: string;

//The propertyId is an optional string that acts as the unique identifier for an external set of properties. 
//If specified, it ensures that the block retrieves and uses a specific set of properties defined outside of its immediate structure. 
//This setup enhances the modularity and reusability of blocks within plugins, as it allows for centralized management of properties that can be consistently applied across different blocks or instances within the plugin, enhancing the plugin’s functionality and efficiency.
//If this property is not set, it may imply that the block either uses locally defined properties or defaults, or it does not require external property configurations for its operations. 
//This flexibility allows developers to efficiently manage the customization and functionality of blocks, tailoring them to specific needs while maintaining the ability to scale or modify features as required by the plugin's application within the Reearth platform.

Example Usage:

// Suppose we have an array of PluginExtensionInstance objects, including block extensions
const pluginInstances = [
    {
        id: "pluginInstance1",
        pluginId: "plugin1",
        name: "Data Display",
        extensionId: "ext1",
        extensionType: "block",
        runTimes: undefined
    }
];

// A hypothetical function to update a block's properties based on certain conditions
function updateBlockProperties(blockId) {
    // Find the block by ID from the plugin instances
    const blockInstance = pluginInstances.find(instance => 
        instance.extensionType === "block" && instance.id === blockId);

    // Assume we have access to a function that fetches or updates block properties
    if (blockInstance) {
        // Modify the block's property, like changing configuration settings
        console.log(`Updating properties for block ID: ${blockInstance.id}`);
        // This could involve API calls or local state updates.

        // Just a placeholder for illustration
        console.log("Properties updated for block:", blockInstance.id);
    } else {
        console.log("Block not found with ID:", blockId);
    }
}

// Function call to update properties of a specific block
updateBlockProperties("pluginInstance1");

Example Without Comments

(plugin?.extensionType === "widget"
                  ? widget?.()?.id
                  : plugin?.extensionType === "block"
                  ? block?.()?.id
                  : "") ?? "",
                  
 --------------------------------------------------------
                
     if (blocks) {
      blocks.forEach(block => {
        instances.push({
          id: block.id,
          pluginId: block.pluginId ?? "",
          name: getExtensionInstanceName(block.pluginId ?? ""),
          extensionId: block.extensionId ?? "",
          extensionType: "block",
          get runTimes() {
            return runTimesCacheHandler.get(block.id);
          },
        });
      });
    }