@dndbuilder.com/react
Version:
Drag and drop builder for React
127 lines (126 loc) • 4.86 kB
TypeScript
import { Block, BlockConfig } from '../types/block';
import { AnyObject, OptionalKeys } from '../types';
import { ClassValue } from 'clsx';
export * from './block';
export * from './guard';
export * from './popover';
export * from './style';
export * from './theme';
/**
* Creates a unique ID generator with a specified length
* @returns A function that generates unique IDs
*/
export declare const createId: () => string;
/**
* Creates a root block for the page builder
* @returns A root block object with default properties
*/
export declare const createRootBlock: () => {
id: string;
type: string;
parentId: string;
children: never[];
settings: {};
};
/**
* Creates a content object from an array of blocks
* @param blocks - Array of blocks to include in the content
* @returns A content object with blocks organized by ID and parent-child relationships
*/
export declare const createContent: (blocks: Block[]) => Record<string, Block>;
/**
* Checks if the content has no blocks (empty)
* @param content - The content object to check
* @returns True if the content has no blocks, false otherwise
*/
export declare const isEmptyContent: (content: Record<string, Block>) => boolean;
/**
* Creates a block with default values for optional properties
* @param config - The block configuration
* @returns A block object with all required properties
*/
export declare const createBlock: <T extends object = AnyObject>(config: OptionalKeys<Block<T>, "id" | "children">) => {
settings: T;
type: string;
parentId: string;
advancedSettings?: import('../types').BlockAdvancedSettings | undefined;
id: string;
children: (string | Block)[];
};
/**
* Creates a block configuration with default values for optional properties
* @param config - The block configuration options
* @returns A complete block configuration with all required properties
*/
export declare const createBlockConfig: <T extends object>(config: OptionalKeys<BlockConfig<T>, "label" | "settings" | "controls">) => {
icon?: import('react').ComponentType | undefined;
type: string;
style?: ((params: {
blockId: string;
settings: T;
themeSettings: import('../types').Theme["settings"];
breakpoints: import('../types').BreakpointConfig[];
}) => import('free-style').Styles) | undefined;
advancedSettings?: import('../types').BlockAdvancedSettings | undefined;
previewImage?: string | undefined;
component: import('react').ComponentType<import('../types').BlockProps<T>>;
previewComponent?: import('react').ComponentType<import('../types').BlockProps<T>> | undefined;
group?: string | undefined;
disableAdvancedSettings?: boolean | undefined;
isVisible?: ((params?: AnyObject) => boolean) | undefined;
toolbar?: import('react').ComponentType<import('../types').BlockToolbarProps> | undefined;
settings: {};
label: string;
controls: import('../types').BlockControl[];
};
/**
* Creates a style utility for registering and retrieving styles
* @returns An object with register and get methods for managing styles
*/
export declare const createStyle: () => {
register: (styles: import('free-style').Styles) => string;
get: () => string;
};
/**
* Combines multiple class values and merges Tailwind classes
* @param inputs - Class values to combine
* @returns A string of combined and merged class names
*/
export declare function classNames(...inputs: ClassValue[]): string;
/**
* Sorts an array of items based on a provided order of IDs
* @param ids - Array of IDs defining the desired order
* @param data - Array of items to be sorted
* @returns A new sorted array of items
*/
export declare function sortRepeatableItems(ids: string[], data: any[]): any[];
/**
* Type-safe version of Object.keys that preserves the key types
* @param obj - The object to get keys from
* @returns An array of the object's keys with proper typing
*/
export declare function objectKeys<T extends object>(obj: T): Array<keyof T>;
/**
* Converts bytes to a human-readable file size string
* @param bytes - The size in bytes
* @returns A formatted string representing the size (e.g., "1.5 MB")
*/
export declare function bytesToSize(bytes: number): string;
/**
* Converts a file to a base64 string
* @param file The file to convert
* @returns A promise that resolves to the base64 string
*/
export declare const fileToBase64: (file: File) => Promise<string>;
/**
* Converts an image URL to a base64 string
* @param url The URL of the image
* @returns A promise that resolves to the base64 string
*/
export declare const urlToBase64: (url: string) => Promise<string>;
/**
* Generates a unique ID for media items
* @returns A unique ID string
*/
export declare const generateUniqueId: () => string;
//# sourceMappingURL=index.d.ts.map