@meonode/ui 0.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +188 -0
- package/dist/core.node.d.ts +25 -0
- package/dist/core.node.d.ts.map +1 -0
- package/dist/core.node.js +105 -0
- package/dist/html.node.d.ts +596 -0
- package/dist/html.node.d.ts.map +1 -0
- package/dist/html.node.js +408 -0
- package/dist/json/css-properties.json +1311 -0
- package/dist/main.d.ts +5 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +1 -0
- package/dist/node.helper.d.ts +71 -0
- package/dist/node.helper.d.ts.map +1 -0
- package/dist/node.helper.js +76 -0
- package/dist/node.type.d.ts +108 -0
- package/dist/node.type.d.ts.map +1 -0
- package/dist/node.type.js +1 -0
- package/dist/react-is.helper.d.ts +139 -0
- package/dist/react-is.helper.d.ts.map +1 -0
- package/dist/react-is.helper.js +84 -0
- package/docs/basic-usage.md +66 -0
- package/docs/conditional-component-with-hook.md +71 -0
- package/package.json +54 -0
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA"}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./core.node.ts";export*from"./node.helper.ts";export*from"./html.node.ts";export*from"./node.type.ts";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ComponentProps, CSSProperties, ElementType } from 'react';
|
|
2
|
+
import type { NodeElement, OriginalNodeProps } from './node.type.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Returns a string describing the type of a given React component or element.
|
|
5
|
+
*
|
|
6
|
+
* Checks for common React types (class, forwardRef, memo, etc.) and returns a string
|
|
7
|
+
* such as 'class', 'forwardRef', 'memo', 'object-with-render', 'function', or other
|
|
8
|
+
* React-specific types. Falls back to `typeof` or 'unknown' if not recognized.
|
|
9
|
+
* @param component The React component, element type, or element-like object to check.
|
|
10
|
+
* @returns A string describing the component type.
|
|
11
|
+
* @example
|
|
12
|
+
* getComponentType(class extends React.Component {}) // 'class'
|
|
13
|
+
* getComponentType(React.forwardRef(() => <div/>)) // 'forwardRef'
|
|
14
|
+
* getComponentType(React.memo(() => <div/>)) // 'memo'
|
|
15
|
+
* getComponentType(() => <div/>) // 'function'
|
|
16
|
+
*/
|
|
17
|
+
export declare const getComponentType: (component?: NodeElement) => "class" | "forwardRef" | "memo" | "object" | "object-with-render" | "function" | "fragment" | "portal" | "profiler" | "strict-mode" | "suspense" | "suspense-list" | "context-consumer" | "context-provider" | "lazy" | "element" | "unknown" | string;
|
|
18
|
+
/**
|
|
19
|
+
* Generates a string name for an ElementType.
|
|
20
|
+
*
|
|
21
|
+
* This function attempts to extract a meaningful name from a React ElementType,
|
|
22
|
+
* which can be a string (for intrinsic elements like 'div'), a function (for
|
|
23
|
+
* functional components), or an object (for components created with `React.memo`,
|
|
24
|
+
* `React.forwardRef`, etc.). It prioritizes `displayName` and `name` properties
|
|
25
|
+
* for functions and unwraps higher-order components to get the underlying name.
|
|
26
|
+
*
|
|
27
|
+
* If a name cannot be determined, it returns 'UnknownElementType'.
|
|
28
|
+
* @typeParam ElementType - The type of the React element.
|
|
29
|
+
* @param elementType The ElementType (e.g., 'div', MyComponent function/class).
|
|
30
|
+
* @returns A string representation of the element type.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getElementTypeName(elementType: NodeElement): string;
|
|
33
|
+
/**
|
|
34
|
+
* Filters an object to only include valid CSS properties
|
|
35
|
+
* @param props The object containing potential CSS properties
|
|
36
|
+
* @returns An object containing only valid CSS properties
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* getCSSProps({
|
|
40
|
+
* backgroundColor: 'red',
|
|
41
|
+
* invalid: true
|
|
42
|
+
* }) // { backgroundColor: 'red' }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function getCSSProps<T extends Record<string, any>>(props: T): Partial<CSSProperties>;
|
|
46
|
+
/**
|
|
47
|
+
* Filters component props to include only valid DOM properties and attributes.
|
|
48
|
+
*
|
|
49
|
+
* This function iterates through the provided props and retains only those that
|
|
50
|
+
* are not CSS properties (as determined by `cssPropertySet`). This is useful for
|
|
51
|
+
* separating style-related props from standard DOM attributes when rendering
|
|
52
|
+
* elements.
|
|
53
|
+
* @ty E - The type of the React element.
|
|
54
|
+
* @typeParam T - The type of the component props.
|
|
55
|
+
* @param props The component props to filter.
|
|
56
|
+
* @returns An object containing only valid DOM props.
|
|
57
|
+
*/
|
|
58
|
+
export declare function getDOMProps<E extends ElementType, T extends ComponentProps<E>>(props: T): Partial<OriginalNodeProps>;
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves a deeply nested value from an object using a dot-separated string path.
|
|
61
|
+
*
|
|
62
|
+
* This function traverses an object based on the provided path, which is a
|
|
63
|
+
* string of keys separated by dots. It returns the value found at the end of
|
|
64
|
+
* the path or `undefined` if any key in the path is not found or if the object
|
|
65
|
+
* is nullish at any point during traversal.
|
|
66
|
+
* @param obj The object to traverse. Defaults to an empty object if not provided.
|
|
67
|
+
* @param path The dot-separated path string (e.g., 'background.primary').
|
|
68
|
+
* @returns The value at the specified path, or undefined if not found.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getValueByPath(obj: Record<string, any> | undefined, path: string): any;
|
|
71
|
+
//# sourceMappingURL=node.helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.helper.d.ts","sourceRoot":"","sources":["../src/node.helper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAwBvE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,GAC3B,YAAY,WAAW,KAErB,OAAO,GACP,YAAY,GACZ,MAAM,GACN,QAAQ,GACR,oBAAoB,GACpB,UAAU,GACV,UAAU,GACV,QAAQ,GACR,UAAU,GACV,aAAa,GACb,UAAU,GACV,eAAe,GACf,kBAAkB,GAClB,kBAAkB,GAClB,MAAM,GACN,SAAS,GACT,SAAS,GACT,MAgBH,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAiCnE;AAwBD;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAU3F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,cAAc,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAUpH;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YAAK,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CAE/E"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";var _process$versions,_import$meta$resolve,_import$meta$resolve2,_import$meta;function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_unsupportedIterableToArray(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(b,c){if(b){if("string"==typeof b)return _arrayLikeToArray(b,c);var a={}.toString.call(b).slice(8,-1);return"Object"===a&&b.constructor&&(a=b.constructor.name),"Map"===a||"Set"===a?Array.from(b):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?_arrayLikeToArray(b,c):void 0}}function _arrayLikeToArray(b,c){(null==c||c>b.length)&&(c=b.length);for(var d=0,f=Array(c);d<c;d++)f[d]=b[d];return f}function _iterableToArrayLimit(b,c){var d=null==b?null:"undefined"!=typeof Symbol&&b[Symbol.iterator]||b["@@iterator"];if(null!=d){var g,h,j,k,l=[],a=!0,m=!1;try{if(j=(d=d.call(b)).next,0===c){if(Object(d)!==d)return;a=!1}else for(;!(a=(g=j.call(d)).done)&&(l.push(g.value),l.length!==c);a=!0);}catch(a){m=!0,h=a}finally{try{if(!a&&null!=d["return"]&&(k=d["return"](),Object(k)!==k))return}finally{if(m)throw h}}return l}}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}var cssPropertiesJson=await("object"===("undefined"==typeof process?"undefined":_typeof(process))&&null!==(_process$versions=process.versions)&&void 0!==_process$versions&&_process$versions.node?Promise.all([import("fs"),import("module")]).then(function(a){var b=_slicedToArray(a,2),c=b[0],d=b[1];return new Promise(function(b){return function(a,f){return c.readFile(b,function(b,c){return b?f(b):a(c)})}}(d.createRequire(import.meta.url).resolve("./json/css-properties.json")))}).then(JSON.parse):fetch(null!==(_import$meta$resolve=null===(_import$meta$resolve2=(_import$meta=import.meta).resolve)||void 0===_import$meta$resolve2?void 0:_import$meta$resolve2.call(_import$meta,"./json/css-properties.json"))&&void 0!==_import$meta$resolve?_import$meta$resolve:new URL("./json/css-properties.json",import.meta.url)).then(function(a){return a.json()}));import{isContextConsumer,isContextProvider,isElement,isForwardRef,isFragment,isLazy,isMemo,isPortal,isProfiler,isReactClassComponent,isStrictMode,isSuspense,isSuspenseList}from"./react-is.helper.ts";/**
|
|
2
|
+
* The list of CSS property names imported from the JSON file.
|
|
3
|
+
* Used for validation and filtering of CSS-related props.
|
|
4
|
+
*/var cssProperties=cssPropertiesJson.properties;/**
|
|
5
|
+
* Returns a string describing the type of a given React component or element.
|
|
6
|
+
*
|
|
7
|
+
* Checks for common React types (class, forwardRef, memo, etc.) and returns a string
|
|
8
|
+
* such as 'class', 'forwardRef', 'memo', 'object-with-render', 'function', or other
|
|
9
|
+
* React-specific types. Falls back to `typeof` or 'unknown' if not recognized.
|
|
10
|
+
* @param component The React component, element type, or element-like object to check.
|
|
11
|
+
* @returns A string describing the component type.
|
|
12
|
+
* @example
|
|
13
|
+
* getComponentType(class extends React.Component {}) // 'class'
|
|
14
|
+
* getComponentType(React.forwardRef(() => <div/>)) // 'forwardRef'
|
|
15
|
+
* getComponentType(React.memo(() => <div/>)) // 'memo'
|
|
16
|
+
* getComponentType(() => <div/>) // 'function'
|
|
17
|
+
*/export var getComponentType=function getComponentType(a){return isForwardRef(a)?"forwardRef":isMemo(a)?"memo":isFragment(a)?"fragment":isPortal(a)?"portal":isProfiler(a)?"profiler":isStrictMode(a)?"strict-mode":isSuspense(a)?"suspense":isSuspenseList(a)?"suspense-list":isContextConsumer(a)?"context-consumer":isContextProvider(a)?"context-provider":isLazy(a)?"lazy":isElement(a)?"element":isReactClassComponent(a)?"class":_typeof(a)};/**
|
|
18
|
+
* Generates a string name for an ElementType.
|
|
19
|
+
*
|
|
20
|
+
* This function attempts to extract a meaningful name from a React ElementType,
|
|
21
|
+
* which can be a string (for intrinsic elements like 'div'), a function (for
|
|
22
|
+
* functional components), or an object (for components created with `React.memo`,
|
|
23
|
+
* `React.forwardRef`, etc.). It prioritizes `displayName` and `name` properties
|
|
24
|
+
* for functions and unwraps higher-order components to get the underlying name.
|
|
25
|
+
*
|
|
26
|
+
* If a name cannot be determined, it returns 'UnknownElementType'.
|
|
27
|
+
* @typeParam ElementType - The type of the React element.
|
|
28
|
+
* @param elementType The ElementType (e.g., 'div', MyComponent function/class).
|
|
29
|
+
* @returns A string representation of the element type.
|
|
30
|
+
*/export function getElementTypeName(a){var b;switch(!0){case"string"==typeof a:return a;case"function"==typeof a&&"displayName"in a:return a.displayName||a.name||"AnonymousComponent";case"object"===_typeof(a)&&null!==a:{if(a.displayName)return a.displayName;var c=a.type||a.render;switch(!0){case"function"==typeof c:return c.displayName||c.name||"WrappedComponent";case"string"==typeof c:return c;case"function"==typeof a.render&&(null===(b=a.prototype)||void 0===b?void 0:b.isReactComponent):return a.name||"ClassComponent";default:return"ObjectComponent"}}default:return"UnknownElementType"}}/**
|
|
31
|
+
* Converts kebab-case CSS property names to camelCase, preserving CSS custom properties.
|
|
32
|
+
* Converts kebab-case CSS property names to their camelCase equivalents
|
|
33
|
+
* Preserves CSS custom properties that start with --
|
|
34
|
+
* @param prop The CSS property name to convert
|
|
35
|
+
* @returns The camelCase property name
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* toCamelCase('background-color') // 'backgroundColor'
|
|
39
|
+
* toCamelCase('--custom-prop') // '--custom-prop'
|
|
40
|
+
* ```
|
|
41
|
+
*/var toCamelCase=function toCamelCase(a){return a.startsWith("--")?a:a.replace(/-([a-z])/g,function(a,b){return b.toUpperCase()});// Preserve CSS variables
|
|
42
|
+
},cssPropertySet=new Set(cssProperties.map(toCamelCase));/**
|
|
43
|
+
* A set of valid CSS property names in camelCase, used for validation.
|
|
44
|
+
*//**
|
|
45
|
+
* Filters an object to only include valid CSS properties
|
|
46
|
+
* @param props The object containing potential CSS properties
|
|
47
|
+
* @returns An object containing only valid CSS properties
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* getCSSProps({
|
|
51
|
+
* backgroundColor: 'red',
|
|
52
|
+
* invalid: true
|
|
53
|
+
* }) // { backgroundColor: 'red' }
|
|
54
|
+
* ```
|
|
55
|
+
*/export function getCSSProps(a){var b={};for(var c in a)cssPropertySet.has(c)&&(b[c]=a[c]);return b}/**
|
|
56
|
+
* Filters component props to include only valid DOM properties and attributes.
|
|
57
|
+
*
|
|
58
|
+
* This function iterates through the provided props and retains only those that
|
|
59
|
+
* are not CSS properties (as determined by `cssPropertySet`). This is useful for
|
|
60
|
+
* separating style-related props from standard DOM attributes when rendering
|
|
61
|
+
* elements.
|
|
62
|
+
* @ty E - The type of the React element.
|
|
63
|
+
* @typeParam T - The type of the component props.
|
|
64
|
+
* @param props The component props to filter.
|
|
65
|
+
* @returns An object containing only valid DOM props.
|
|
66
|
+
*/export function getDOMProps(a){var b={};for(var c in a)cssPropertySet.has(c)||(b[c]=a[c]);return b}/**
|
|
67
|
+
* Retrieves a deeply nested value from an object using a dot-separated string path.
|
|
68
|
+
*
|
|
69
|
+
* This function traverses an object based on the provided path, which is a
|
|
70
|
+
* string of keys separated by dots. It returns the value found at the end of
|
|
71
|
+
* the path or `undefined` if any key in the path is not found or if the object
|
|
72
|
+
* is nullish at any point during traversal.
|
|
73
|
+
* @param obj The object to traverse. Defaults to an empty object if not provided.
|
|
74
|
+
* @param path The dot-separated path string (e.g., 'background.primary').
|
|
75
|
+
* @returns The value at the specified path, or undefined if not found.
|
|
76
|
+
*/export function getValueByPath(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},b=1<arguments.length?arguments[1]:void 0;return b.split(".").reduce(function(a,b){return null===a||void 0===a?void 0:a[b]},a)}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { Attributes as ReactAttributes, ComponentProps, CSSProperties, ReactNode, JSX, ElementType, ComponentType, JSXElementConstructor } from 'react';
|
|
2
|
+
export type NodeElement = ReactNode | ElementType | ComponentType | BaseNodeInstance<any> | ((props?: any) => ReactNode | Promise<ReactNode> | BaseNodeInstance<any>);
|
|
3
|
+
/**
|
|
4
|
+
* Defines valid child types that can be passed to a node:
|
|
5
|
+
* - ReactNode: Any valid React child (elements, strings, numbers, etc.)
|
|
6
|
+
* - ElementType: React component types (functions/classes)
|
|
7
|
+
* - BaseNodeInstance: Other node instances in the tree
|
|
8
|
+
* - Function: Lazy child evaluation, useful for conditional rendering and hooks
|
|
9
|
+
*/
|
|
10
|
+
export type Children = ReactNode | NodeElement | BaseNodeInstance<any>;
|
|
11
|
+
/**
|
|
12
|
+
* Forward declaration of the BaseNode interface to avoid circular dependencies.
|
|
13
|
+
* Defines the core structure and capabilities of a BaseNode instance.
|
|
14
|
+
* @template T - The type of React element/component that this node represents
|
|
15
|
+
*/
|
|
16
|
+
export interface BaseNodeInstance<T extends NodeElement = NodeElement> {
|
|
17
|
+
/** The underlying React element or component type that this node will render */
|
|
18
|
+
readonly element: T;
|
|
19
|
+
/** Original props passed during node construction, preserved for cloning/recreation */
|
|
20
|
+
readonly initialRawProps?: BaseNodeProps<T>;
|
|
21
|
+
/** Converts this node instance into a renderable React element/tree */
|
|
22
|
+
render(): ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Extracts the props type from a given element type, handling both intrinsic (HTML) elements
|
|
26
|
+
* and custom React components.
|
|
27
|
+
* @template E - The element type to extract props from
|
|
28
|
+
*/
|
|
29
|
+
export type PropsOf<E extends NodeElement> = E extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[E] : E extends JSXElementConstructor<any> ? ComponentProps<E> : BaseNodeInstance<E>;
|
|
30
|
+
/**
|
|
31
|
+
* Theme configuration object that can be passed through the node tree.
|
|
32
|
+
* Supports nested theme properties for complex styling systems:
|
|
33
|
+
* - Simple values (strings, numbers)
|
|
34
|
+
* - Nested theme objects with unlimited depth
|
|
35
|
+
* - Common CSS values and units
|
|
36
|
+
* - Custom theme variables and tokens
|
|
37
|
+
* Used for consistent styling and dynamic theme application.
|
|
38
|
+
*/
|
|
39
|
+
export interface Theme {
|
|
40
|
+
[key: string]: string | number | boolean | null | undefined | any | Theme | Record<string, Theme | string | number | boolean | null | undefined | any>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Internal representation of processed children after BaseNode handles them.
|
|
44
|
+
* All dynamic/function children are converted to concrete nodes or React elements.
|
|
45
|
+
* Ensures consistent handling of children during the render phase.
|
|
46
|
+
*/
|
|
47
|
+
export type ProcessedChild = BaseNodeInstance | ReactNode;
|
|
48
|
+
/**
|
|
49
|
+
* Internal props type used by BaseNode instances after initial processing.
|
|
50
|
+
* Ensures consistent prop shape throughout the node's lifecycle:
|
|
51
|
+
* - Normalizes style properties into a CSSProperties object
|
|
52
|
+
* - Processes children into known concrete types
|
|
53
|
+
* - Handles theme context propagation
|
|
54
|
+
* @template E - The element type these props apply to
|
|
55
|
+
*/
|
|
56
|
+
export type OriginalNodeProps = ReactAttributes & {
|
|
57
|
+
style?: CSSProperties;
|
|
58
|
+
children?: Children | Children[];
|
|
59
|
+
theme?: Theme;
|
|
60
|
+
nodeTheme?: Theme;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Helper type to determine if the props P have a 'style' property
|
|
64
|
+
* that is compatible with CSSProperties.
|
|
65
|
+
* @template P - The props object of a component (e.g., PropsOf<E>)
|
|
66
|
+
*/
|
|
67
|
+
type HasCSSCompatibleStyleProp<P> = P extends {
|
|
68
|
+
style?: infer S;
|
|
69
|
+
} ? S extends CSSProperties | undefined ? true : false : false;
|
|
70
|
+
/**
|
|
71
|
+
* Public API for node creation props, providing a flexible and type-safe interface:
|
|
72
|
+
* - Preserves original component props while allowing direct style properties (conditionally)
|
|
73
|
+
* - Supports both single and array children
|
|
74
|
+
* - Enables theme customization
|
|
75
|
+
* - Maintains React's key prop for reconciliation
|
|
76
|
+
* @template E - The element type these props apply to
|
|
77
|
+
*/
|
|
78
|
+
export type NodeProps<E extends NodeElement> = Omit<PropsOf<E>, 'style' | 'children'> & ReactAttributes & (HasCSSCompatibleStyleProp<PropsOf<E>> extends true ? Partial<CSSProperties> : object) & {
|
|
79
|
+
children?: Children | Children[];
|
|
80
|
+
theme?: Theme;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* BaseNode's internal props type, extending NodeProps:
|
|
84
|
+
* - Makes all properties optional for flexible node creation
|
|
85
|
+
* - Adds nodeTheme for theme context handling
|
|
86
|
+
* - Used for both initial construction and internal state
|
|
87
|
+
* @template E - The element type these props apply to
|
|
88
|
+
*/
|
|
89
|
+
export type BaseNodeProps<E extends NodeElement> = Partial<NodeProps<E>> & {
|
|
90
|
+
nodeTheme?: Theme;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Props interface for the internal FunctionRenderer component.
|
|
94
|
+
* Handles dynamic function children within React's component lifecycle:
|
|
95
|
+
* - Ensures proper timing of function evaluation
|
|
96
|
+
* - Maintains theme context for rendered content
|
|
97
|
+
* - Enables hook usage in function children
|
|
98
|
+
*/
|
|
99
|
+
export interface FunctionRendererProps<E extends NodeElement> {
|
|
100
|
+
/** Function that returns the child content to render */
|
|
101
|
+
render: (props?: any) => BaseNodeInstance<E> | ReactNode;
|
|
102
|
+
/** Theme context to be applied to the rendered content */
|
|
103
|
+
passedTheme?: Theme;
|
|
104
|
+
/** Optional key prop to help React identify unique instances in lists */
|
|
105
|
+
passedKey?: string;
|
|
106
|
+
}
|
|
107
|
+
export {};
|
|
108
|
+
//# sourceMappingURL=node.type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.type.d.ts","sourceRoot":"","sources":["../src/node.type.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";export{};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom React Type Checker (TypeScript Version)
|
|
3
|
+
* Provides utilities for identifying and checking React component/element types.
|
|
4
|
+
* Inspired by react-is package but implemented in TypeScript with type safety.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Symbol identifiers for React internal component types
|
|
8
|
+
* These are used to identify different kinds of React elements and components
|
|
9
|
+
*/
|
|
10
|
+
export declare const REACT_ELEMENT_TYPE: unique symbol;
|
|
11
|
+
export declare const REACT_PORTAL_TYPE: unique symbol;
|
|
12
|
+
export declare const REACT_FRAGMENT_TYPE: unique symbol;
|
|
13
|
+
export declare const REACT_STRICT_MODE_TYPE: unique symbol;
|
|
14
|
+
export declare const REACT_PROFILER_TYPE: unique symbol;
|
|
15
|
+
export declare const REACT_PROVIDER_TYPE: unique symbol;
|
|
16
|
+
export declare const REACT_CONSUMER_TYPE: unique symbol;
|
|
17
|
+
export declare const REACT_CONTEXT_TYPE: unique symbol;
|
|
18
|
+
export declare const REACT_FORWARD_REF_TYPE: unique symbol;
|
|
19
|
+
export declare const REACT_SUSPENSE_TYPE: unique symbol;
|
|
20
|
+
export declare const REACT_SUSPENSE_LIST_TYPE: unique symbol;
|
|
21
|
+
export declare const REACT_MEMO_TYPE: unique symbol;
|
|
22
|
+
export declare const REACT_LAZY_TYPE: unique symbol;
|
|
23
|
+
export declare const REACT_VIEW_TRANSITION_TYPE: unique symbol;
|
|
24
|
+
export declare const REACT_CLIENT_REFERENCE: unique symbol;
|
|
25
|
+
/**
|
|
26
|
+
* Union type of all possible React internal type symbols.
|
|
27
|
+
* Used to strongly type return values from type checking functions.
|
|
28
|
+
*/
|
|
29
|
+
export type ReactTypeSymbols = typeof REACT_ELEMENT_TYPE | typeof REACT_PORTAL_TYPE | typeof REACT_FRAGMENT_TYPE | typeof REACT_STRICT_MODE_TYPE | typeof REACT_PROFILER_TYPE | typeof REACT_PROVIDER_TYPE | typeof REACT_CONSUMER_TYPE | typeof REACT_CONTEXT_TYPE | typeof REACT_FORWARD_REF_TYPE | typeof REACT_SUSPENSE_TYPE | typeof REACT_SUSPENSE_LIST_TYPE | typeof REACT_MEMO_TYPE | typeof REACT_LAZY_TYPE | typeof REACT_VIEW_TRANSITION_TYPE | typeof REACT_CLIENT_REFERENCE;
|
|
30
|
+
/**
|
|
31
|
+
* Interface describing the minimal shape of a React element-like object.
|
|
32
|
+
* Used for type checking without coupling to React's internal element type.
|
|
33
|
+
*/
|
|
34
|
+
export interface ReactElementLike {
|
|
35
|
+
$$typeof?: symbol;
|
|
36
|
+
type?: any;
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Determines the internal React type of an object.
|
|
41
|
+
* Examines the object's $$typeof property and nested type properties
|
|
42
|
+
* to identify what kind of React element or component it represents.
|
|
43
|
+
* @param {unknown} object The object to check
|
|
44
|
+
* @returns {boolean} - The matching React type symbol or undefined if not a React object
|
|
45
|
+
*/
|
|
46
|
+
export declare function typeOf(object: unknown): ReactTypeSymbols | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Checks if an object is a React Context Consumer
|
|
49
|
+
* @param {unknown} object Object to check
|
|
50
|
+
* @returns {boolean} - True if object is a Context.Consumer
|
|
51
|
+
*/
|
|
52
|
+
export declare const isContextConsumer: (object: unknown) => boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Checks if an object is a React Context Provider
|
|
55
|
+
* @param {unknown} object Object to check
|
|
56
|
+
* @returns {boolean} - True if object is a Context.Provider
|
|
57
|
+
*/
|
|
58
|
+
export declare const isContextProvider: (object: unknown) => boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Checks if an object is a valid React element
|
|
61
|
+
* @param {unknown} object Object to check
|
|
62
|
+
* @returns {boolean} - True if object is a React element
|
|
63
|
+
*/
|
|
64
|
+
export declare const isElement: (object: unknown) => boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Checks if an object is a React forwardRef component
|
|
67
|
+
* @param {unknown} object Object to check
|
|
68
|
+
* @returns {boolean} - True if object is a forwardRef component
|
|
69
|
+
*/
|
|
70
|
+
export declare const isForwardRef: (object: unknown) => boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Checks if an object is a React Fragment
|
|
73
|
+
* @param {unknown} object Object to check
|
|
74
|
+
* @returns {boolean} - True if object is a Fragment
|
|
75
|
+
*/
|
|
76
|
+
export declare const isFragment: (object: unknown) => boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Checks if an object is a React lazy component
|
|
79
|
+
* @param {unknown} object Object to check
|
|
80
|
+
* @returns {boolean} - True if object is a lazy component
|
|
81
|
+
*/
|
|
82
|
+
export declare const isLazy: (object: unknown) => boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if an object is a React memo component
|
|
85
|
+
* @param {unknown} object Object to check
|
|
86
|
+
* @returns {boolean} - True if object is a memo component
|
|
87
|
+
*/
|
|
88
|
+
export declare const isMemo: (object: unknown) => boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Checks if an object is a React portal
|
|
91
|
+
* @param {unknown} object Object to check
|
|
92
|
+
* @returns {boolean} - True if object is a portal
|
|
93
|
+
*/
|
|
94
|
+
export declare const isPortal: (object: unknown) => boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Checks if an object is a React Profiler
|
|
97
|
+
* @param {unknown} object Object to check
|
|
98
|
+
* @returns {boolean} - True if object is a Profiler
|
|
99
|
+
*/
|
|
100
|
+
export declare const isProfiler: (object: unknown) => boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Checks if an object is a React StrictMode component
|
|
103
|
+
* @param {unknown} object Object to check
|
|
104
|
+
* @returns {boolean} - True if object is StrictMode
|
|
105
|
+
*/
|
|
106
|
+
export declare const isStrictMode: (object: unknown) => boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Checks if an object is a React Suspense component
|
|
109
|
+
* @param {unknown} object Object to check
|
|
110
|
+
* @returns {boolean} - True if object is Suspense
|
|
111
|
+
*/
|
|
112
|
+
export declare const isSuspense: (object: unknown) => boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Checks if an object is a React SuspenseList component
|
|
115
|
+
* @param {unknown} object Object to check
|
|
116
|
+
* @returns {boolean} - True if `object` is SuspenseList
|
|
117
|
+
*/
|
|
118
|
+
export declare const isSuspenseList: (object: unknown) => boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Checks if a type is a valid React element type that can be rendered.
|
|
121
|
+
* This includes strings (for DOM elements), functions (for components),
|
|
122
|
+
* and various React-specific types like Fragment, Context, etc.
|
|
123
|
+
* @param {any} type The type to validate
|
|
124
|
+
* @returns {boolean} - True if the type can be rendered as a React element
|
|
125
|
+
*/
|
|
126
|
+
export declare const isValidElementType: <T>(type: T) => boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Type guard that checks if a component is a React class component.
|
|
129
|
+
* Examines the component's prototype for the isReactComponent marker property
|
|
130
|
+
* that React adds to all class components.
|
|
131
|
+
* @param {unknown} component Component to check
|
|
132
|
+
* @returns {boolean} - True if component is a React class component
|
|
133
|
+
*/
|
|
134
|
+
export declare const isReactClassComponent: (component: unknown) => component is {
|
|
135
|
+
prototype: {
|
|
136
|
+
isReactComponent: any;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
//# sourceMappingURL=react-is.helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-is.helper.d.ts","sourceRoot":"","sources":["../src/react-is.helper.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}/**
|
|
2
|
+
* Custom React Type Checker (TypeScript Version)
|
|
3
|
+
* Provides utilities for identifying and checking React component/element types.
|
|
4
|
+
* Inspired by react-is package but implemented in TypeScript with type safety.
|
|
5
|
+
*//**
|
|
6
|
+
* Symbol identifiers for React internal component types
|
|
7
|
+
* These are used to identify different kinds of React elements and components
|
|
8
|
+
*/export var REACT_ELEMENT_TYPE=Symbol["for"]("react.transitional.element");export var REACT_PORTAL_TYPE=Symbol["for"]("react.portal");export var REACT_FRAGMENT_TYPE=Symbol["for"]("react.fragment");export var REACT_STRICT_MODE_TYPE=Symbol["for"]("react.strict_mode");export var REACT_PROFILER_TYPE=Symbol["for"]("react.profiler");export var REACT_PROVIDER_TYPE=Symbol["for"]("react.provider");export var REACT_CONSUMER_TYPE=Symbol["for"]("react.consumer");export var REACT_CONTEXT_TYPE=Symbol["for"]("react.context");export var REACT_FORWARD_REF_TYPE=Symbol["for"]("react.forward_ref");export var REACT_SUSPENSE_TYPE=Symbol["for"]("react.suspense");export var REACT_SUSPENSE_LIST_TYPE=Symbol["for"]("react.suspense_list");export var REACT_MEMO_TYPE=Symbol["for"]("react.memo");export var REACT_LAZY_TYPE=Symbol["for"]("react.lazy");export var REACT_VIEW_TRANSITION_TYPE=Symbol["for"]("react.view_transition");export var REACT_CLIENT_REFERENCE=Symbol["for"]("react.client.reference");/**
|
|
9
|
+
* Union type of all possible React internal type symbols.
|
|
10
|
+
* Used to strongly type return values from type checking functions.
|
|
11
|
+
*//**
|
|
12
|
+
* Interface describing the minimal shape of a React element-like object.
|
|
13
|
+
* Used for type checking without coupling to React's internal element type.
|
|
14
|
+
*//**
|
|
15
|
+
* Determines the internal React type of an object.
|
|
16
|
+
* Examines the object's $$typeof property and nested type properties
|
|
17
|
+
* to identify what kind of React element or component it represents.
|
|
18
|
+
* @param {unknown} object The object to check
|
|
19
|
+
* @returns {boolean} - The matching React type symbol or undefined if not a React object
|
|
20
|
+
*/export function typeOf(a){if("object"===_typeof(a)&&null!==a){var b=a.$$typeof;switch(b){case REACT_ELEMENT_TYPE:{var c=a.type;switch(c){case REACT_FRAGMENT_TYPE:case REACT_PROFILER_TYPE:case REACT_STRICT_MODE_TYPE:case REACT_SUSPENSE_TYPE:case REACT_SUSPENSE_LIST_TYPE:case REACT_VIEW_TRANSITION_TYPE:return c;default:{var d=null===c||void 0===c?void 0:c.$$typeof;return d===REACT_CONTEXT_TYPE||d===REACT_FORWARD_REF_TYPE||d===REACT_LAZY_TYPE||d===REACT_MEMO_TYPE||d===REACT_CONSUMER_TYPE?d:b}}}case REACT_PORTAL_TYPE:return b}}}/**
|
|
21
|
+
* Checks if an object is a React Context Consumer
|
|
22
|
+
* @param {unknown} object Object to check
|
|
23
|
+
* @returns {boolean} - True if object is a Context.Consumer
|
|
24
|
+
*/export var isContextConsumer=function isContextConsumer(a){return typeOf(a)===REACT_CONSUMER_TYPE};/**
|
|
25
|
+
* Checks if an object is a React Context Provider
|
|
26
|
+
* @param {unknown} object Object to check
|
|
27
|
+
* @returns {boolean} - True if object is a Context.Provider
|
|
28
|
+
*/export var isContextProvider=function isContextProvider(a){return typeOf(a)===REACT_CONTEXT_TYPE};/**
|
|
29
|
+
* Checks if an object is a valid React element
|
|
30
|
+
* @param {unknown} object Object to check
|
|
31
|
+
* @returns {boolean} - True if object is a React element
|
|
32
|
+
*/export var isElement=function isElement(a){return"object"===_typeof(a)&&null!==a&&a.$$typeof===REACT_ELEMENT_TYPE};/**
|
|
33
|
+
* Checks if an object is a React forwardRef component
|
|
34
|
+
* @param {unknown} object Object to check
|
|
35
|
+
* @returns {boolean} - True if object is a forwardRef component
|
|
36
|
+
*/export var isForwardRef=function isForwardRef(a){return typeOf(a)===REACT_FORWARD_REF_TYPE};/**
|
|
37
|
+
* Checks if an object is a React Fragment
|
|
38
|
+
* @param {unknown} object Object to check
|
|
39
|
+
* @returns {boolean} - True if object is a Fragment
|
|
40
|
+
*/export var isFragment=function isFragment(a){return typeOf(a)===REACT_FRAGMENT_TYPE};/**
|
|
41
|
+
* Checks if an object is a React lazy component
|
|
42
|
+
* @param {unknown} object Object to check
|
|
43
|
+
* @returns {boolean} - True if object is a lazy component
|
|
44
|
+
*/export var isLazy=function isLazy(a){return typeOf(a)===REACT_LAZY_TYPE};/**
|
|
45
|
+
* Checks if an object is a React memo component
|
|
46
|
+
* @param {unknown} object Object to check
|
|
47
|
+
* @returns {boolean} - True if object is a memo component
|
|
48
|
+
*/export var isMemo=function isMemo(a){return typeOf(a)===REACT_MEMO_TYPE};/**
|
|
49
|
+
* Checks if an object is a React portal
|
|
50
|
+
* @param {unknown} object Object to check
|
|
51
|
+
* @returns {boolean} - True if object is a portal
|
|
52
|
+
*/export var isPortal=function isPortal(a){return typeOf(a)===REACT_PORTAL_TYPE};/**
|
|
53
|
+
* Checks if an object is a React Profiler
|
|
54
|
+
* @param {unknown} object Object to check
|
|
55
|
+
* @returns {boolean} - True if object is a Profiler
|
|
56
|
+
*/export var isProfiler=function isProfiler(a){return typeOf(a)===REACT_PROFILER_TYPE};/**
|
|
57
|
+
* Checks if an object is a React StrictMode component
|
|
58
|
+
* @param {unknown} object Object to check
|
|
59
|
+
* @returns {boolean} - True if object is StrictMode
|
|
60
|
+
*/export var isStrictMode=function isStrictMode(a){return typeOf(a)===REACT_STRICT_MODE_TYPE};/**
|
|
61
|
+
* Checks if an object is a React Suspense component
|
|
62
|
+
* @param {unknown} object Object to check
|
|
63
|
+
* @returns {boolean} - True if object is Suspense
|
|
64
|
+
*/export var isSuspense=function isSuspense(a){return typeOf(a)===REACT_SUSPENSE_TYPE};/**
|
|
65
|
+
* Checks if an object is a React SuspenseList component
|
|
66
|
+
* @param {unknown} object Object to check
|
|
67
|
+
* @returns {boolean} - True if `object` is SuspenseList
|
|
68
|
+
*/export var isSuspenseList=function isSuspenseList(a){return typeOf(a)===REACT_SUSPENSE_LIST_TYPE};/**
|
|
69
|
+
* Set of known valid React special element types.
|
|
70
|
+
* Used for quick validation of element types in isValidElementType().
|
|
71
|
+
* Includes Fragment, Profiler, StrictMode, Suspense and SuspenseList.
|
|
72
|
+
*/var knownValidSymbols=new Set([REACT_FRAGMENT_TYPE,REACT_PROFILER_TYPE,REACT_STRICT_MODE_TYPE,REACT_SUSPENSE_TYPE,REACT_SUSPENSE_LIST_TYPE]);/**
|
|
73
|
+
* Checks if a type is a valid React element type that can be rendered.
|
|
74
|
+
* This includes strings (for DOM elements), functions (for components),
|
|
75
|
+
* and various React-specific types like Fragment, Context, etc.
|
|
76
|
+
* @param {any} type The type to validate
|
|
77
|
+
* @returns {boolean} - True if the type can be rendered as a React element
|
|
78
|
+
*/export var isValidElementType=function isValidElementType(a){if("string"==typeof a||"function"==typeof a)return!0;if(knownValidSymbols.has(a))return!0;if("object"===_typeof(a)&&null!==a){var b=a.$$typeof;return b===REACT_LAZY_TYPE||b===REACT_MEMO_TYPE||b===REACT_CONTEXT_TYPE||b===REACT_CONSUMER_TYPE||b===REACT_FORWARD_REF_TYPE||b===REACT_CLIENT_REFERENCE||"function"==typeof a.getModuleId}return!1};/**
|
|
79
|
+
* Type guard that checks if a component is a React class component.
|
|
80
|
+
* Examines the component's prototype for the isReactComponent marker property
|
|
81
|
+
* that React adds to all class components.
|
|
82
|
+
* @param {unknown} component Component to check
|
|
83
|
+
* @returns {boolean} - True if component is a React class component
|
|
84
|
+
*/export var isReactClassComponent=function isReactClassComponent(a){return"function"==typeof a&&!!a.prototype&&!!a.prototype.isReactComponent};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
```ts
|
|
2
|
+
// Component wraps a React Server Component into a Client Component
|
|
3
|
+
// Think of it like a factory that transforms JSX-like node definitions into actual React components
|
|
4
|
+
import { Component } from '@src/lib/node/core.node'
|
|
5
|
+
|
|
6
|
+
// These are layout/HTML helpers that render to real DOM elements (e.g., <div>, <img>, <p>)
|
|
7
|
+
import { Column, Row, Div, Img, P } from '@src/lib/node/html.node'
|
|
8
|
+
|
|
9
|
+
const theme = { background: { primary: 'red', secondary: 'blue' } }
|
|
10
|
+
|
|
11
|
+
// This is the actual exported component
|
|
12
|
+
export default Component(() => {
|
|
13
|
+
return Card({
|
|
14
|
+
title: 'Genshin Impact',
|
|
15
|
+
subtitle: 'Adventure awaits!',
|
|
16
|
+
imageUrl: 'https://upload-os-bbs.mihoyo.com/upload/2021/03/05/75387538/f37ce39baf72ffb84cb5c0040bdcbf10_2126420710320647353.jpg',
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// This function returns a structured layout using html.node helpers only
|
|
21
|
+
const Card = ({ title, subtitle, imageUrl }: { title: string; subtitle: string; imageUrl: string }) =>
|
|
22
|
+
Column({
|
|
23
|
+
theme,
|
|
24
|
+
// Column is just a <div> with `display: flex; flex-direction: column`
|
|
25
|
+
borderRadius: 10,
|
|
26
|
+
overflow: 'hidden',
|
|
27
|
+
border: '1px solid theme.background.primary', // Can use theme references
|
|
28
|
+
width: 300,
|
|
29
|
+
children: [
|
|
30
|
+
// Img translates to a real <img> tag
|
|
31
|
+
Img({
|
|
32
|
+
src: imageUrl,
|
|
33
|
+
width: '100%',
|
|
34
|
+
height: 180,
|
|
35
|
+
style: {
|
|
36
|
+
objectFit: 'cover', // Ensures the image fills the area without distortion
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
// Div is a basic <div> wrapper
|
|
40
|
+
Div({
|
|
41
|
+
padding: 10,
|
|
42
|
+
backgroundColor: 'theme.background.secondary',
|
|
43
|
+
children: Column({
|
|
44
|
+
gap: 5,
|
|
45
|
+
children: [
|
|
46
|
+
// P maps directly to <p>, with styling
|
|
47
|
+
P({
|
|
48
|
+
style: {
|
|
49
|
+
fontSize: 18,
|
|
50
|
+
fontWeight: 600,
|
|
51
|
+
},
|
|
52
|
+
children: title,
|
|
53
|
+
}),
|
|
54
|
+
P({
|
|
55
|
+
style: {
|
|
56
|
+
fontSize: 14,
|
|
57
|
+
color: 'gray',
|
|
58
|
+
},
|
|
59
|
+
children: subtitle,
|
|
60
|
+
}),
|
|
61
|
+
],
|
|
62
|
+
}),
|
|
63
|
+
}),
|
|
64
|
+
],
|
|
65
|
+
})
|
|
66
|
+
```
|