UNPKG

@meonode/ui

Version:

A structured approach to component composition, direct CSS-first prop styling, built-in theming, smart prop handling (including raw property pass-through), and dynamic children.

90 lines 4.72 kB
import type { FinalNodeProps, NodeElement, NodeInstance } from '../types/node.type.js'; import type { ComponentProps, CSSProperties, ElementType } from 'react'; /** * Retrieves or initializes a global state value using a Symbol key. * This ensures singleton behavior across multiple bundles or module reloads, * and protects against property name mangling during obfuscation. * @param key The Symbol key to use for the global state. * @param factory A factory function to create the initial value if it doesn't exist. * @returns The global state value. */ export declare function getGlobalState<T>(key: symbol, factory: () => T): T; /** * Retrieves a deeply nested value from an object using a dot-separated string path. * * This function traverses an object based on the provided path, which is a * string of keys separated by dots. It returns the value found at the end of * the path or `undefined` if any key in the path is not found or if the object * is nullish at any point during traversal. * @param obj The object to traverse, defaults to an empty object if not provided. * @param path The dot-separated path string (e.g., 'background.primary'). * @returns The value at the specified path, or undefined if not found. */ export declare const getValueByPath: (obj: any, path: string) => any; /** * Returns a string describing the type of a given React component or element. * * Checks for common React types (class, forwardRef, memo, etc.) and returns a string * such as 'class', 'forwardRef', 'memo', 'object-with-render', 'function', or other * React-specific types. Falls back to `typeof` or 'unknown' if not recognized. * @param component The React component, element type, or element-like object to check. * @returns A string describing the component type. * @example * getComponentType(class extends React.Component {}) // 'class' * getComponentType(React.forwardRef(() => <div/>)) // 'forwardRef' * getComponentType(React.memo(() => <div/>)) // 'memo' * getComponentType(() => <div/>) // 'function' */ export declare const getComponentType: (component?: NodeElement | NodeInstance) => "class" | "forwardRef" | "memo" | "object" | "function" | "fragment" | "portal" | "profiler" | "strict-mode" | "suspense" | "suspense-list" | "context-consumer" | "context-provider" | "lazy" | "element" | "unknown" | string; /** * Generates a string name for an ElementType or ReactElement. * * This function attempts to extract a meaningful name from a React ElementType * (string, function, class, HOC) or a ReactElement instance. * It prioritizes `displayName` and `name` properties and unwraps HOCs like * `React.memo` and `React.forwardRef` to get the underlying component name. * * If a name cannot be determined, it returns a fallback like 'UnknownElementType' or 'AnonymousComponent'. * @param node The ElementType or ReactElement (e.g., 'div', MyComponent, <MyComponent />). * @returns A string representation of the element type's name. */ export declare function getElementTypeName(node: unknown): string; /** * Filters an object to only include valid CSS properties * @param props The object containing potential CSS properties * @returns An object containing only valid CSS properties * @example * ```ts * getCSSProps({ * backgroundColor: 'red', * invalid: true * }) // { backgroundColor: 'red' } * ``` */ export declare function getCSSProps<T extends Record<string, any>>(props: T): Partial<CSSProperties>; /** * Filters component props to include only valid DOM properties and attributes. * * This function iterates through the provided props and retains only those that * are not CSS properties (as determined by `cssPropertySet`). This is useful for * separating style-related props from standard DOM attributes when rendering * elements. * @ty E - The type of the React element. * @typeParam T - The type of the component props. * @param props The component props to filter. * @returns An object containing only valid DOM props. */ export declare function getDOMProps<E extends ElementType, T extends ComponentProps<E>>(props: T): Partial<FinalNodeProps>; /** * Checks if a given tag is in the set of tags that should not receive style props. * @param tag The tag name to check (e.g., 'script', 'style'). * @returns `true` if the tag is in the no-style set, otherwise `false`. */ export declare function hasNoStyleTag(tag?: NodeElement): boolean; /** * Removes keys from an object whose values are `undefined`. * @param obj The source object. * @returns A new object without keys that have `undefined` values. */ export declare function omitUndefined<T extends object>(obj: T): Partial<T>; //# sourceMappingURL=common.helper.d.ts.map