UNPKG

@gmetrixr/rjson

Version:
77 lines (76 loc) 3.61 kB
import { ElementType, IElementDefinition } from "../definitions/elements/ElementDefinition"; import { RecordFactory } from "../R/RecordFactory"; import { RecordNode, ClipboardR } from "../R/RecordNode"; import { RT, RTP } from "../R/RecordTypes"; import { fn } from "../definitions"; export declare class ElementFactory extends RecordFactory<RT.element> { private elementType; constructor(json: RecordNode<RT.element>); /** * ISSUE : We were facing issue when we copy element from root to group, id for that element was duplicated and that was causing an issue. Below id fix for that * this function will add record with new element id to prevent duplicate issue. */ pasteFromClipboardObject(this: ElementFactory, { obj, position }: { obj: ClipboardR; position?: number; }): (RecordNode<RT> | undefined)[]; /** * Regenerate new element_id for all children recursively */ dedupeChildElementIds(this: ElementFactory): void; getElementType(this: ElementFactory): ElementType; set(this: ElementFactory, property: RTP[RT.element], value: unknown): ElementFactory; /** * Returns the default value of a property. If no default is found, returns undefined * This is already defined in RecordFactory and is being overridden in ElementFactory */ getDefault(this: ElementFactory, property: RTP[RT.element]): unknown; /** * Used by the right bar to list down properties */ getJsonPropsAndDefaultProps(this: ElementFactory): string[]; /** * Gets all file ids from an element structure * file ids are stored in properties of type "source" * Properties of type "source" are generally in properties ending with "source" (Eg: "background_source") * sources */ getFileIdsFromElement(this: ElementFactory): number[]; /** * Inject the given sources into the element */ injectSourceIntoElement(this: ElementFactory, sourceMap: { [id: number]: fn.Source; }): void; addElementOfType(this: ElementFactory, elementType: ElementType, position?: number): RecordNode<RT.element>; } export declare class ElementUtils { /** * Get the element definition of a specific element_type * ElementDefinition can be used to get element_type, properties, propertyDefaults, events, actions * * In case its an unknown element_type, returns BasicElement's Definition */ static getElementDefinition: (elementType: ElementType) => IElementDefinition; /** Get a list of all defaults for the given elementType */ static getElementTypeDefaults: (elementType: ElementType) => Record<string, unknown>; /** * Given a property of type Array<Source>, takes file id out of it in an array and returns it */ static getFileIdsFromElementArrayPropertyValue: (value: unknown) => number[]; /** * Given a property value (of type source), takes file id out of it and returns it as an array */ static getFileIdsFromValue: (value: unknown) => number[]; /** * Given a property value and sourceMap, returns a new value with the replaced sources * Can return undefined or a Source or a Source[], depending on the propertyName * The multiple returns type don't matter, because the logic of the calling function doesn't care about return type */ static getNewSourceValueArray: (value: unknown, sourceMap: { [id: number]: fn.Source; }) => fn.Source[]; static getNewSourceValue: (value: unknown, sourceMap: { [id: number]: fn.Source; }) => fn.Source | undefined; }