HEX
Server: LiteSpeed
System: Linux server315.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: globfdxw (6114)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //home/globfdxw/www/wp-content/plugins/give/src/FormBuilder/resources/js/registrars/blocks/index.ts
import {BlockConfiguration} from '@wordpress/blocks';

/**
 * @since 3.0.0
 */
export interface Block {
    name: string;
    settings: BlockConfiguration;
}

/**
 * @since 3.0.0
 */
interface Registrar {
    register(name: string, settings: BlockConfiguration): void;

    getAll(): Block[];

    get(blockName: string): Block | undefined;
}

/**
 * @since 3.0.0
 */
export default class BlockRegistrar implements Registrar {
    /**
     * @since 3.0.0
     */
    private blocks: Block[] = [];

    /**
     * @since 3.0.0
     */
    public get(blockName: string): Block | undefined {
        return this.blocks.find(({name}) => name === blockName);
    }

    /**
     * @since 3.0.0
     */
    public getAll(): Block[] {
        return this.blocks;
    }

    /**
     * @since 3.0.0
     */
    public register(name, settings: BlockConfiguration): void {
        if (this.get(name)) {
            throw new Error(`Block "${name}" is already registered.`);
        }

        this.blocks.push({name, settings});
    }
}