@meonode/ui 0.2.21 → 0.3.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/CHANGELOG.md +61 -1
- package/README.md +40 -26
- package/dist/components/styled-renderer.client.d.ts +838 -3
- package/dist/components/styled-renderer.client.d.ts.map +1 -1
- package/dist/components/styled-renderer.client.js +9 -1
- package/dist/components/theme-provider.client.d.ts +25 -0
- package/dist/components/theme-provider.client.d.ts.map +1 -0
- package/dist/components/theme-provider.client.js +10 -0
- package/dist/core.node.d.ts +24 -90
- package/dist/core.node.d.ts.map +1 -1
- package/dist/core.node.js +53 -112
- package/dist/helper/node.helper.d.ts +1 -11
- package/dist/helper/node.helper.d.ts.map +1 -1
- package/dist/helper/node.helper.js +2 -22
- package/dist/helper/theme.helper.d.ts +2 -66
- package/dist/helper/theme.helper.d.ts.map +1 -1
- package/dist/helper/theme.helper.js +2 -7
- package/dist/hoc/component.hoc.d.ts +5 -8
- package/dist/hoc/component.hoc.d.ts.map +1 -1
- package/dist/hoc/component.hoc.js +7 -8
- package/dist/hoc/portal.hoc.d.ts +44 -44
- package/dist/hoc/portal.hoc.d.ts.map +1 -1
- package/dist/hoc/portal.hoc.js +53 -53
- package/dist/hook/index.d.ts +1 -0
- package/dist/hook/index.d.ts.map +1 -1
- package/dist/hook/index.js +1 -1
- package/dist/hook/useTheme.d.ts +8 -0
- package/dist/hook/useTheme.d.ts.map +1 -0
- package/dist/hook/useTheme.js +8 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +1 -1
- package/dist/node.type.d.ts +30 -28
- package/dist/node.type.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled-renderer.client.d.ts","sourceRoot":"","sources":["../../src/components/styled-renderer.client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"styled-renderer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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wDASjC"}
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
"use client";var _excluded=["element","
|
|
1
|
+
"use client";var _excluded=["element","children"];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)}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!=_typeof(a)||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],-1===b.indexOf(c)&&{}.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c={};for(var d in a)if({}.hasOwnProperty.call(a,d)){if(-1!==b.indexOf(d))continue;c[d]=a[d]}return c}import{useContext}from"react";import{jsx}from"@emotion/react";import{resolveObjWithTheme}from"../helper/theme.helper.js";import{ThemeContext}from"./theme-provider.client.js";import{resolveDefaultStyle}from"../helper/node.helper.js";/**
|
|
2
|
+
* A client-side component that renders a styled element using Emotion.
|
|
3
|
+
* It resolves theme values and applies default styles.
|
|
4
|
+
* @template E The type of the HTML element to render.
|
|
5
|
+
* @template TProps The type of the props for the component.
|
|
6
|
+
* @param element The HTML element to render (e.g., 'div', 'span').
|
|
7
|
+
* @param children Optional children to be rendered inside the element.
|
|
8
|
+
* @returns {JSX.Element} The rendered JSX element.
|
|
9
|
+
*/export default function StyledRenderer(a){var b=a.element,c=a.children,d=_objectWithoutProperties(a,_excluded),e=useContext(ThemeContext),f=null===e||void 0===e?void 0:e.theme,g=d;f&&(g=resolveObjWithTheme(d,f.system));var h=resolveDefaultStyle(g.css);return jsx(b,_objectSpread(_objectSpread({},g),{},{css:h}),c)}StyledRenderer.displayName="Styled";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Children, Theme } from '../node.type.js';
|
|
2
|
+
export interface ThemeContextValue {
|
|
3
|
+
theme: Theme;
|
|
4
|
+
setTheme: (theme: Theme) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare const ThemeContext: import("react").Context<ThemeContextValue | null>;
|
|
7
|
+
/**
|
|
8
|
+
* The internal implementation of the ThemeProvider component.
|
|
9
|
+
* @param {object} props The props for the component.
|
|
10
|
+
* @param {Children} [props.children] The children to render.
|
|
11
|
+
* @param {Theme} props.theme The theme to provide.
|
|
12
|
+
* @returns {React.ReactNode} The rendered component.
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
export declare function _ThemeProvider({ children, theme }: {
|
|
16
|
+
children?: Children;
|
|
17
|
+
theme: Theme;
|
|
18
|
+
}): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
19
|
+
/**
|
|
20
|
+
* A component that provides a theme to its children.
|
|
21
|
+
*/
|
|
22
|
+
export declare const ThemeProvider: (<AdditionalProps extends Record<string, any> = Record<string, any>>(props: import("../node.type.js").MergedProps<typeof _ThemeProvider, AdditionalProps>) => import("../node.type.js").NodeInstance<typeof _ThemeProvider>) & {
|
|
23
|
+
element: typeof _ThemeProvider;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=theme-provider.client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-provider.client.d.ts","sourceRoot":"","sources":["../../src/components/theme-provider.client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAGxD,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,KAAK,CAAA;IACZ,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CACjC;AAED,eAAO,MAAM,YAAY,mDAAgD,CAAA;AAEzE;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;IAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,8FAgBxF;AAED;;GAEG;AACH,eAAO,MAAM,aAAa;;CAA6B,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";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}import{createContext,useState}from"react";import{createNode,Node}from"../main.js";export var ThemeContext=createContext(null);/**
|
|
2
|
+
* The internal implementation of the ThemeProvider component.
|
|
3
|
+
* @param {object} props The props for the component.
|
|
4
|
+
* @param {Children} [props.children] The children to render.
|
|
5
|
+
* @param {Theme} props.theme The theme to provide.
|
|
6
|
+
* @returns {React.ReactNode} The rendered component.
|
|
7
|
+
* @private
|
|
8
|
+
*/export function _ThemeProvider(a){var b=a.children,c=a.theme,d=useState(c),e=_slicedToArray(d,2),f=e[0],g=e[1];if(!c)throw new Error("`theme` prop must be defined");return Node(ThemeContext.Provider,{value:{theme:f,setTheme:function setTheme(a){document.cookie="theme=".concat(a.mode),g(a)}},children:b}).render()}/**
|
|
9
|
+
* A component that provides a theme to its children.
|
|
10
|
+
*/export var ThemeProvider=createNode(_ThemeProvider);
|
package/dist/core.node.d.ts
CHANGED
|
@@ -1,45 +1,30 @@
|
|
|
1
1
|
import { type ReactElement } from 'react';
|
|
2
|
-
import type { Children, FinalNodeProps, HasRequiredProps, MergedProps, NodeElementType, NodeInstance, NodePortal, NodeProps, PropsOf
|
|
2
|
+
import type { Children, FinalNodeProps, HasRequiredProps, MergedProps, NodeElementType, NodeInstance, NodePortal, NodeProps, PropsOf } from './node.type.js';
|
|
3
3
|
/**
|
|
4
|
-
* Represents a node in a React component tree
|
|
4
|
+
* Represents a node in a React component tree.
|
|
5
5
|
* This class wraps React elements and handles:
|
|
6
6
|
* - Props processing and normalization
|
|
7
|
-
* - Theme inheritance and resolution
|
|
8
7
|
* - Child node processing and management
|
|
9
|
-
* - Style processing
|
|
8
|
+
* - Style processing
|
|
10
9
|
* @template E The type of React element or component this node represents
|
|
11
10
|
*/
|
|
12
11
|
export declare class BaseNode<E extends NodeElementType> implements NodeInstance<E> {
|
|
13
12
|
/** The underlying React element or component type that this node represents */
|
|
14
13
|
element: E;
|
|
15
14
|
/** Original props passed during construction, preserved for cloning/recreation */
|
|
16
|
-
rawProps:
|
|
15
|
+
rawProps: Partial<NodeProps<E>>;
|
|
17
16
|
/** Flag to identify BaseNode instances */
|
|
18
17
|
readonly isBaseNode: boolean;
|
|
19
|
-
/** Processed props after
|
|
18
|
+
/** Processed props after style processing, and child normalization */
|
|
20
19
|
private _props?;
|
|
21
20
|
/** DOM element used for portal rendering */
|
|
22
21
|
private _portalDOMElement;
|
|
23
22
|
/** React root instance for portal rendering */
|
|
24
23
|
private _portalReactRoot;
|
|
25
|
-
/** Hash of the current children and theme to detect changes */
|
|
26
|
-
private _childrenHash?;
|
|
27
24
|
/** Cache for normalized children */
|
|
28
25
|
private _normalizedChildren?;
|
|
29
26
|
/** Indicates whether the code is running on the server (true) or client (false) */
|
|
30
27
|
private static _isServer;
|
|
31
|
-
/**
|
|
32
|
-
* WeakMap cache for processed children, keyed by object/array identity for GC friendliness.
|
|
33
|
-
* Each entry stores the hash, processed children, and a server-side flag.
|
|
34
|
-
*/
|
|
35
|
-
private static _processedChildrenWeakCache;
|
|
36
|
-
/**
|
|
37
|
-
* Map cache for processed children, keyed by a stable string signature.
|
|
38
|
-
* Used for non-object cases or as a fallback. Each entry stores the processed children and a server-side flag.
|
|
39
|
-
*/
|
|
40
|
-
private static _processedChildrenMapCache;
|
|
41
|
-
/** Maximum number of entries in the Map cache to prevent unbounded growth */
|
|
42
|
-
private static readonly _MAX_PROCESSED_CHILDREN_CACHE = 1000;
|
|
43
28
|
/**
|
|
44
29
|
* Constructs a new BaseNode instance.
|
|
45
30
|
*
|
|
@@ -49,98 +34,51 @@ export declare class BaseNode<E extends NodeElementType> implements NodeInstance
|
|
|
49
34
|
* @param element The React element or component type this node will represent.
|
|
50
35
|
* @param rawProps The initial, unprocessed props for the element.
|
|
51
36
|
*/
|
|
52
|
-
constructor(element: E, rawProps?:
|
|
37
|
+
constructor(element: E, rawProps?: Partial<NodeProps<E>>);
|
|
53
38
|
/**
|
|
54
39
|
* Lazily processes and retrieves the final, normalized props for the node.
|
|
55
40
|
*
|
|
56
41
|
* The first time this getter is accessed, it triggers `_processProps` to resolve
|
|
57
|
-
*
|
|
42
|
+
* styles, and children. Subsequent accesses return the cached result
|
|
58
43
|
* until the node is cloned or recreated.
|
|
59
44
|
* @returns The fully processed and normalized `FinalNodeProps`.
|
|
60
45
|
*/
|
|
61
46
|
get props(): FinalNodeProps;
|
|
62
47
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* 4. **Default Style Merging**: Combines default styles with resolved style props.
|
|
70
|
-
* 5. **Child Processing**: Normalizes the `children` prop, propagating the theme.
|
|
71
|
-
* @returns The processed `FinalNodeProps` object.
|
|
48
|
+
* Processes raw props into a final, normalized form.
|
|
49
|
+
* This includes:
|
|
50
|
+
* - Extracting and separating style-related props
|
|
51
|
+
* - Merging CSS-in-JS styles with other style props
|
|
52
|
+
* - Processing and normalizing children
|
|
53
|
+
* - Combining all parts into a single props object
|
|
72
54
|
* @private
|
|
55
|
+
* @returns The processed `FinalNodeProps` ready for rendering.
|
|
73
56
|
*/
|
|
74
57
|
private _processProps;
|
|
75
58
|
/**
|
|
76
|
-
*
|
|
77
|
-
* independent `BaseNode` instances (prevents sharing cycles and mutation bugs).
|
|
78
|
-
*
|
|
79
|
-
* - If the input is an array, each child is cloned recursively.
|
|
80
|
-
* - If the input is a `BaseNode`, a new instance is created with the same element and copied rawProps.
|
|
81
|
-
* - For other objects/primitives, the value is returned as-is (they are immutable or safe to reuse).
|
|
82
|
-
*
|
|
83
|
-
* This ensures that cached children are never shared between different parents in the React tree.
|
|
84
|
-
* @param processed The processed child or array of children to clone.
|
|
85
|
-
* @returns A deep clone of the processed children, safe for use in multiple parents.
|
|
86
|
-
* @private
|
|
87
|
-
*/
|
|
88
|
-
private static _cloneProcessedChildren;
|
|
89
|
-
/**
|
|
90
|
-
* Retrieves cached processed children for a given set of `children` and an optional `theme`.
|
|
91
|
-
*
|
|
92
|
-
* - Skips caching entirely when executed on the server (returns `null`).
|
|
93
|
-
* - Uses a **WeakMap** for identity-based caching when `children` is an object or array,
|
|
94
|
-
* ensuring garbage collection safety.
|
|
95
|
-
* - Falls back to a **Map** keyed by a stable hash of `children` and `theme`
|
|
96
|
-
* for value-based caching.
|
|
97
|
-
* - Only returns cached entries that are **not server-side**.
|
|
98
|
-
* @param children The child node(s) to resolve cached results for.
|
|
99
|
-
* @param theme The theme context that may influence child processing.
|
|
100
|
-
* @returns A cloned version of the cached processed children if available, otherwise `null`.
|
|
101
|
-
* @private
|
|
102
|
-
*/
|
|
103
|
-
private _getCachedChildren;
|
|
104
|
-
/**
|
|
105
|
-
* Caches processed children for a given set of children and theme.
|
|
106
|
-
* This method stores the processed NodeElement(s) in a Map keyed by a stable hash.
|
|
107
|
-
* The cache is bounded to avoid unbounded memory growth.
|
|
108
|
-
* No caching is performed on the server to avoid RSC issues.
|
|
109
|
-
* @param children The original children to cache.
|
|
110
|
-
* @param theme The theme associated with the children.
|
|
111
|
-
* @param processed The processed NodeElement(s) to cache.
|
|
112
|
-
* @private
|
|
113
|
-
*/
|
|
114
|
-
private _setCachedChildren;
|
|
115
|
-
/**
|
|
116
|
-
* Recursively processes raw children, converting them into `BaseNode` instances as needed
|
|
117
|
-
* and propagating the provided theme.
|
|
59
|
+
* Recursively processes raw children, converting them into `BaseNode` instances as needed.
|
|
118
60
|
*
|
|
119
|
-
* This method ensures consistent
|
|
120
|
-
* using caching strategies: a Map for client-side and no caching for server-side.
|
|
61
|
+
* This method ensures consistent handling for all children.
|
|
121
62
|
*
|
|
122
63
|
* - If `children` is an array, each child is processed individually.
|
|
123
64
|
* - If `children` is a single node, it is processed directly.
|
|
124
|
-
* - The processed result is cached on the client to avoid redundant work.
|
|
125
65
|
* @param children The raw child or array of children to process.
|
|
126
|
-
* @param theme The theme to propagate to the children.
|
|
127
66
|
* @returns The processed children, ready for normalization and rendering.
|
|
128
67
|
* @private
|
|
129
68
|
*/
|
|
130
69
|
private _processChildren;
|
|
131
70
|
/**
|
|
132
|
-
* Renders a processed `NodeElement` into a `ReactNode`, applying a
|
|
71
|
+
* Renders a processed `NodeElement` into a `ReactNode`, applying a key if necessary.
|
|
133
72
|
*
|
|
134
73
|
* This static method centralizes the logic for converting various types of processed elements
|
|
135
74
|
* into renderable React nodes. It handles:
|
|
136
|
-
* - `BaseNode` instances: Re-wraps them to apply a new key
|
|
75
|
+
* - `BaseNode` instances: Re-wraps them to apply a new key.
|
|
137
76
|
* - React class components: Wraps them in a new `BaseNode`.
|
|
138
77
|
* - `NodeInstance` objects: Invokes their `render()` method.
|
|
139
78
|
* - React component instances: Invokes their `render()` method.
|
|
140
79
|
* - Functional components: Creates a React element from them.
|
|
141
80
|
* - Other valid `ReactNode` types (strings, numbers, etc.): Returns them as-is.
|
|
142
81
|
* @param processedElement The node element to render.
|
|
143
|
-
* @param passedTheme The theme to propagate.
|
|
144
82
|
* @param passedKey The React key to assign.
|
|
145
83
|
* @returns A renderable `ReactNode`.
|
|
146
84
|
* @private
|
|
@@ -159,15 +97,12 @@ export declare class BaseNode<E extends NodeElementType> implements NodeInstance
|
|
|
159
97
|
*/
|
|
160
98
|
private static _isFunctionChild;
|
|
161
99
|
/**
|
|
162
|
-
* Renders the output of a function-as-a-child
|
|
100
|
+
* Renders the output of a function-as-a-child.
|
|
163
101
|
*
|
|
164
102
|
* This method is designed to handle "render prop" style children (`() => ReactNode`).
|
|
165
|
-
* It invokes the function
|
|
166
|
-
* correctly passed down to any `BaseNode` instances returned by the function.
|
|
103
|
+
* It invokes the function and processes its result.
|
|
167
104
|
* @param props The properties for the function renderer.
|
|
168
105
|
* @param props.render The function to execute to get the child content.
|
|
169
|
-
* @param props.passedTheme The theme to propagate to the rendered child.
|
|
170
|
-
* // * @param props.processRawNode A reference to the `_processRawNode` method for recursive processing.
|
|
171
106
|
* @returns The rendered `ReactNode`.
|
|
172
107
|
* @private
|
|
173
108
|
*/
|
|
@@ -192,16 +127,15 @@ export declare class BaseNode<E extends NodeElementType> implements NodeInstance
|
|
|
192
127
|
* Processes a single raw node, recursively converting it into a `BaseNode` or other renderable type.
|
|
193
128
|
*
|
|
194
129
|
* This is a central method for normalizing children. It handles various types of input:
|
|
195
|
-
* - **`BaseNode` instances**: Re-creates them to ensure the correct
|
|
130
|
+
* - **`BaseNode` instances**: Re-creates them to ensure the correct key is applied.
|
|
196
131
|
* - **Primitives**: Returns strings, numbers, booleans, null, and undefined as-is.
|
|
197
132
|
* - **Functions (Render Props)**: Wraps them in a `BaseNode` that uses `_functionRenderer` to delay execution.
|
|
198
|
-
* - **Valid React Elements**: Converts them into `BaseNode` instances, extracting props
|
|
199
|
-
* - **React Component Types**: Wraps them in a `BaseNode
|
|
133
|
+
* - **Valid React Elements**: Converts them into `BaseNode` instances, extracting props.
|
|
134
|
+
* - **React Component Types**: Wraps them in a `BaseNode`.
|
|
200
135
|
* - **React Component Instances**: Renders them and processes the output recursively.
|
|
201
136
|
*
|
|
202
137
|
* It also generates a stable key for elements within an array if one is not provided.
|
|
203
138
|
* @param node The raw child node to process.
|
|
204
|
-
* @param passedTheme The theme inherited from the parent.
|
|
205
139
|
* @param nodeIndex The index of the child if it is in an array, used for key generation.
|
|
206
140
|
* @returns A processed `NodeElement` (typically a `BaseNode` instance or a primitive).
|
|
207
141
|
* @private
|
|
@@ -214,7 +148,7 @@ export declare class BaseNode<E extends NodeElementType> implements NodeInstance
|
|
|
214
148
|
* This method is called during the `render` phase. It takes a child that has already
|
|
215
149
|
* been processed by `_processChildren` and prepares it for `React.createElement`.
|
|
216
150
|
*
|
|
217
|
-
* - For `BaseNode` instances, it calls their `render()` method
|
|
151
|
+
* - For `BaseNode` instances, it calls their `render()` method.
|
|
218
152
|
* - It validates that other children are valid React element types.
|
|
219
153
|
* - Primitives and other valid nodes are returned as-is.
|
|
220
154
|
* @param child The processed child node to normalize.
|
package/dist/core.node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.node.d.ts","sourceRoot":"","sources":["../src/core.node.ts"],"names":[],"mappings":"AACA,OAAc,EAQZ,KAAK,YAAY,EAElB,MAAM,OAAO,CAAA;AACd,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAEd,gBAAgB,EAChB,WAAW,EAEX,eAAe,EAEf,YAAY,EACZ,UAAU,EACV,SAAS,EACT,OAAO,
|
|
1
|
+
{"version":3,"file":"core.node.d.ts","sourceRoot":"","sources":["../src/core.node.ts"],"names":[],"mappings":"AACA,OAAc,EAQZ,KAAK,YAAY,EAElB,MAAM,OAAO,CAAA;AACd,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAEd,gBAAgB,EAChB,WAAW,EAEX,eAAe,EAEf,YAAY,EACZ,UAAU,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;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB,CAAC,sBAAsB,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,SAAS,eAAe,EACnH,OAAO,EAAE,CAAC,EACV,YAAY,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,sBAAsB,GAAG,UAAU,CAAC,GAAG,sBAAsB,GACpG,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GACxC,CAAC,CAAC,eAAe,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjE,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,eAAe,CAAC,EAAE,UAAU,CAAC,KACrD,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,GACtC,CAAC,CAAC,eAAe,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjE,QAAQ,CAAC,EAAE,QAAQ,EACnB,KAAK,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,eAAe,CAAC,EAAE,UAAU,CAAC,KACtD,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAQzC"}
|
package/dist/core.node.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
"use strict";var _excluded=["ref","key","children","
|
|
2
|
-
* Represents a node in a React component tree
|
|
1
|
+
"use strict";var _excluded=["ref","key","children","css","props"],_excluded2=["style"],_excluded3=["style"],_excluded4=["children","key","nativeProps"];function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],-1===b.indexOf(c)&&{}.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c={};for(var d in a)if({}.hasOwnProperty.call(a,d)){if(-1!==b.indexOf(d))continue;c[d]=a[d]}return c}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)}function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!=_typeof(a)||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}import React,{createElement,Fragment,isValidElement}from"react";import{isNodeInstance}from"./helper/node.helper.js";import{isForwardRef,isFragment,isMemo,isReactClassComponent,isValidElementType}from"./helper/react-is.helper.js";import{createRoot}from"react-dom/client";import{getComponentType,getCSSProps,getDOMProps,getElementTypeName,hasNoStyleTag,omitUndefined}from"./helper/common.helper.js";import StyledRenderer from"./components/styled-renderer.client.js";/**
|
|
2
|
+
* Represents a node in a React component tree.
|
|
3
3
|
* This class wraps React elements and handles:
|
|
4
4
|
* - Props processing and normalization
|
|
5
|
-
* - Theme inheritance and resolution
|
|
6
5
|
* - Child node processing and management
|
|
7
|
-
* - Style processing
|
|
6
|
+
* - Style processing
|
|
8
7
|
* @template E The type of React element or component this node represents
|
|
9
8
|
*/export class BaseNode{/**
|
|
10
9
|
* Constructs a new BaseNode instance.
|
|
@@ -14,124 +13,74 @@
|
|
|
14
13
|
* accessed via the `props` getter, allowing for lazy evaluation.
|
|
15
14
|
* @param element The React element or component type this node will represent.
|
|
16
15
|
* @param rawProps The initial, unprocessed props for the element.
|
|
17
|
-
*/constructor(a){var b=
|
|
16
|
+
*/constructor(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{};/** The underlying React element or component type that this node represents *//** Original props passed during construction, preserved for cloning/recreation *//** Flag to identify BaseNode instances *//** DOM element used for portal rendering *//** React root instance for portal rendering *//**
|
|
18
17
|
* Normalizes a processed child node into a final, renderable `ReactNode`.
|
|
19
18
|
*
|
|
20
19
|
* This method is called during the `render` phase. It takes a child that has already
|
|
21
20
|
* been processed by `_processChildren` and prepares it for `React.createElement`.
|
|
22
21
|
*
|
|
23
|
-
* - For `BaseNode` instances, it calls their `render()` method
|
|
22
|
+
* - For `BaseNode` instances, it calls their `render()` method.
|
|
24
23
|
* - It validates that other children are valid React element types.
|
|
25
24
|
* - Primitives and other valid nodes are returned as-is.
|
|
26
25
|
* @param child The processed child node to normalize.
|
|
27
26
|
* @returns A renderable `ReactNode`.
|
|
28
27
|
* @throws {Error} If the child is not a valid React element type.
|
|
29
28
|
* @private
|
|
30
|
-
*/_defineProperty(this,"rawProps",{}),_defineProperty(this,"isBaseNode",!0),_defineProperty(this,"_portalDOMElement",null),_defineProperty(this,"_portalReactRoot",null),_defineProperty(this,"_normalizeChild",function(a){
|
|
29
|
+
*/_defineProperty(this,"rawProps",{}),_defineProperty(this,"isBaseNode",!0),_defineProperty(this,"_portalDOMElement",null),_defineProperty(this,"_portalReactRoot",null),_defineProperty(this,"_normalizeChild",function(a){// Handle null/undefined quickly
|
|
31
30
|
if(null===a||a===void 0)return a;// Primitives should be returned as-is (text nodes, numbers, booleans)
|
|
32
|
-
var
|
|
33
|
-
if(a instanceof BaseNode||isNodeInstance(a))
|
|
31
|
+
var b=_typeof(a);if("string"===b||"number"===b||"boolean"===b)return a;// For BaseNode instances, apply current theme if child has no theme
|
|
32
|
+
if(a instanceof BaseNode||isNodeInstance(a))return a.render();// Handle React.Component instances
|
|
34
33
|
if("function"==typeof a.render)// React.Component instance
|
|
35
34
|
return a.render();// Validate element type before returning
|
|
36
|
-
if(!isValidElementType(a)){var
|
|
37
|
-
return a}),this.element=a,this.rawProps=
|
|
35
|
+
if(!isValidElementType(a)){var c=getComponentType(a);throw new Error("Invalid element type: ".concat(c," provided!"))}// Return valid React elements as-is
|
|
36
|
+
return a}),this.element=a,this.rawProps=b}/**
|
|
38
37
|
* Lazily processes and retrieves the final, normalized props for the node.
|
|
39
38
|
*
|
|
40
39
|
* The first time this getter is accessed, it triggers `_processProps` to resolve
|
|
41
|
-
*
|
|
40
|
+
* styles, and children. Subsequent accesses return the cached result
|
|
42
41
|
* until the node is cloned or recreated.
|
|
43
42
|
* @returns The fully processed and normalized `FinalNodeProps`.
|
|
44
43
|
*/get props(){return this._props||(this._props=this._processProps()),this._props}/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* 4. **Default Style Merging**: Combines default styles with resolved style props.
|
|
52
|
-
* 5. **Child Processing**: Normalizes the `children` prop, propagating the theme.
|
|
53
|
-
* @returns The processed `FinalNodeProps` object.
|
|
44
|
+
* Processes raw props into a final, normalized form.
|
|
45
|
+
* This includes:
|
|
46
|
+
* - Extracting and separating style-related props
|
|
47
|
+
* - Merging CSS-in-JS styles with other style props
|
|
48
|
+
* - Processing and normalizing children
|
|
49
|
+
* - Combining all parts into a single props object
|
|
54
50
|
* @private
|
|
51
|
+
* @returns The processed `FinalNodeProps` ready for rendering.
|
|
55
52
|
*/_processProps(){// Destructure raw props into relevant parts
|
|
56
|
-
var a=this.rawProps,b=a.ref,c=a.key,d=a.children,e=a.
|
|
53
|
+
var a=this.rawProps,b=a.ref,c=a.key,d=a.children,e=a.css,f=a.props,g=void 0===f?{}:f,h=_objectWithoutProperties(a,_excluded),i=g,j=i.style,k=_objectWithoutProperties(i,_excluded2),l=getCSSProps(h),m=getDOMProps(h),n=this._processChildren(d);// Process children
|
|
57
54
|
// Combine processed props into final normalized form
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* Deeply clones processed children before returning them from cache so that each parent receives
|
|
61
|
-
* independent `BaseNode` instances (prevents sharing cycles and mutation bugs).
|
|
62
|
-
*
|
|
63
|
-
* - If the input is an array, each child is cloned recursively.
|
|
64
|
-
* - If the input is a `BaseNode`, a new instance is created with the same element and copied rawProps.
|
|
65
|
-
* - For other objects/primitives, the value is returned as-is (they are immutable or safe to reuse).
|
|
66
|
-
*
|
|
67
|
-
* This ensures that cached children are never shared between different parents in the React tree.
|
|
68
|
-
* @param processed The processed child or array of children to clone.
|
|
69
|
-
* @returns A deep clone of the processed children, safe for use in multiple parents.
|
|
70
|
-
* @private
|
|
71
|
-
*/static _cloneProcessedChildren(a){var b=function cloneOne(a){return a instanceof BaseNode||isNodeInstance(a)?new BaseNode(a.element,_objectSpread({},a.rawProps)):a;// NodeInstance returns its own instances when render() is called - we avoid calling render here.
|
|
72
|
-
// For other objects/primitives, return as-is (they are immutable or safe to reuse).
|
|
73
|
-
};return Array.isArray(a)?a.map(function(a){return b(a)}):b(a)}/**
|
|
74
|
-
* Retrieves cached processed children for a given set of `children` and an optional `theme`.
|
|
75
|
-
*
|
|
76
|
-
* - Skips caching entirely when executed on the server (returns `null`).
|
|
77
|
-
* - Uses a **WeakMap** for identity-based caching when `children` is an object or array,
|
|
78
|
-
* ensuring garbage collection safety.
|
|
79
|
-
* - Falls back to a **Map** keyed by a stable hash of `children` and `theme`
|
|
80
|
-
* for value-based caching.
|
|
81
|
-
* - Only returns cached entries that are **not server-side**.
|
|
82
|
-
* @param children The child node(s) to resolve cached results for.
|
|
83
|
-
* @param theme The theme context that may influence child processing.
|
|
84
|
-
* @returns A cloned version of the cached processed children if available, otherwise `null`.
|
|
85
|
-
* @private
|
|
86
|
-
*/_getCachedChildren(a,b){if(BaseNode._isServer)return null;// No server caching
|
|
87
|
-
// Compute hash once
|
|
88
|
-
var c=createStableHash(a,b);// If children is an object (array or object), try identity-keyed WeakMap first
|
|
89
|
-
if(a&&"object"===_typeof(a)){var d=BaseNode._processedChildrenWeakCache.get(a);if(d&&d.hash===c&&!d.isServerSide)return BaseNode._cloneProcessedChildren(d.children)}// Fallback to string-hash Map cache
|
|
90
|
-
var e=BaseNode._processedChildrenMapCache.get(c);return e&&!e.isServerSide?BaseNode._cloneProcessedChildren(e.children):null}/**
|
|
91
|
-
* Caches processed children for a given set of children and theme.
|
|
92
|
-
* This method stores the processed NodeElement(s) in a Map keyed by a stable hash.
|
|
93
|
-
* The cache is bounded to avoid unbounded memory growth.
|
|
94
|
-
* No caching is performed on the server to avoid RSC issues.
|
|
95
|
-
* @param children The original children to cache.
|
|
96
|
-
* @param theme The theme associated with the children.
|
|
97
|
-
* @param processed The processed NodeElement(s) to cache.
|
|
98
|
-
* @private
|
|
99
|
-
*/_setCachedChildren(a,b,c){if(!BaseNode._isServer){var d=createStableHash(a,b);if(a&&"object"===_typeof(a))return void BaseNode._processedChildrenWeakCache.set(a,{hash:d,children:c,isServerSide:!1});// Manage bounded Map cache (FIFO eviction)
|
|
100
|
-
if(BaseNode._processedChildrenMapCache.has(d))return void BaseNode._processedChildrenMapCache.set(d,{children:c,isServerSide:!1});if(BaseNode._processedChildrenMapCache.size>=BaseNode._MAX_PROCESSED_CHILDREN_CACHE){var e=BaseNode._processedChildrenMapCache.keys().next().value;void 0!==e&&BaseNode._processedChildrenMapCache["delete"](e)}BaseNode._processedChildrenMapCache.set(d,{children:c,isServerSide:!1})}}/**
|
|
101
|
-
* Recursively processes raw children, converting them into `BaseNode` instances as needed
|
|
102
|
-
* and propagating the provided theme.
|
|
55
|
+
return omitUndefined(_objectSpread(_objectSpread({ref:b,key:c,css:_objectSpread(_objectSpread({},l),e),style:j},m),{},{nativeProps:k,children:n}))}/**
|
|
56
|
+
* Recursively processes raw children, converting them into `BaseNode` instances as needed.
|
|
103
57
|
*
|
|
104
|
-
* This method ensures consistent
|
|
105
|
-
* using caching strategies: a Map for client-side and no caching for server-side.
|
|
58
|
+
* This method ensures consistent handling for all children.
|
|
106
59
|
*
|
|
107
60
|
* - If `children` is an array, each child is processed individually.
|
|
108
61
|
* - If `children` is a single node, it is processed directly.
|
|
109
|
-
* - The processed result is cached on the client to avoid redundant work.
|
|
110
62
|
* @param children The raw child or array of children to process.
|
|
111
|
-
* @param theme The theme to propagate to the children.
|
|
112
63
|
* @returns The processed children, ready for normalization and rendering.
|
|
113
64
|
* @private
|
|
114
|
-
*/_processChildren(a
|
|
115
|
-
|
|
116
|
-
* Renders a processed `NodeElement` into a `ReactNode`, applying a theme and key if necessary.
|
|
65
|
+
*/_processChildren(a){if(a){var b;return b="function"==typeof a?a:Array.isArray(a)?a.map(function(a,b){return BaseNode._processRawNode(a,b)}):BaseNode._processRawNode(a),b}}/**
|
|
66
|
+
* Renders a processed `NodeElement` into a `ReactNode`, applying a key if necessary.
|
|
117
67
|
*
|
|
118
68
|
* This static method centralizes the logic for converting various types of processed elements
|
|
119
69
|
* into renderable React nodes. It handles:
|
|
120
|
-
* - `BaseNode` instances: Re-wraps them to apply a new key
|
|
70
|
+
* - `BaseNode` instances: Re-wraps them to apply a new key.
|
|
121
71
|
* - React class components: Wraps them in a new `BaseNode`.
|
|
122
72
|
* - `NodeInstance` objects: Invokes their `render()` method.
|
|
123
73
|
* - React component instances: Invokes their `render()` method.
|
|
124
74
|
* - Functional components: Creates a React element from them.
|
|
125
75
|
* - Other valid `ReactNode` types (strings, numbers, etc.): Returns them as-is.
|
|
126
76
|
* @param processedElement The node element to render.
|
|
127
|
-
* @param passedTheme The theme to propagate.
|
|
128
77
|
* @param passedKey The React key to assign.
|
|
129
78
|
* @returns A renderable `ReactNode`.
|
|
130
79
|
* @private
|
|
131
80
|
* @static
|
|
132
|
-
*/static _renderProcessedNode(a,b
|
|
133
|
-
if(void 0!==
|
|
134
|
-
return isReactClassComponent(a)?new BaseNode(a,
|
|
81
|
+
*/static _renderProcessedNode(a,b){var c={};// 1. BaseNode instance: re-wrap to apply key/theme if needed
|
|
82
|
+
if(void 0!==b&&(c.key=b),a instanceof BaseNode||isNodeInstance(a)){var d,e=null===(d=a.rawProps)||void 0===d?void 0:d.key;return e===b?a.render():new BaseNode(a.element,_objectSpread(_objectSpread({},a.rawProps),c)).render()}// 2. React class component type: wrap in BaseNode
|
|
83
|
+
return isReactClassComponent(a)?new BaseNode(a,c).render():isNodeInstance(a)?a.render():a instanceof React.Component?a.render():"function"==typeof a?createElement(a,{key:b}):a;// 3. NodeInstance object: call its render
|
|
135
84
|
// 4. React.Component instance: call its render
|
|
136
85
|
// 5. Functional component: create element with key
|
|
137
86
|
// 6. Other valid ReactNode types
|
|
@@ -149,26 +98,22 @@ if("function"!=typeof a)return!1;// Exclude React component types
|
|
|
149
98
|
if(isReactClassComponent(a))return!1;if(isMemo(a))return!1;if(isForwardRef(a))return!1;try{// Try to check if it's a React component instance using prototype
|
|
150
99
|
return!(a.prototype&&"function"==typeof a.prototype.render)}catch(a){// If accessing prototype fails (due to cross-realm), assume it's a function child
|
|
151
100
|
return!0}}/**
|
|
152
|
-
* Renders the output of a function-as-a-child
|
|
101
|
+
* Renders the output of a function-as-a-child.
|
|
153
102
|
*
|
|
154
103
|
* This method is designed to handle "render prop" style children (`() => ReactNode`).
|
|
155
|
-
* It invokes the function
|
|
156
|
-
* correctly passed down to any `BaseNode` instances returned by the function.
|
|
104
|
+
* It invokes the function and processes its result.
|
|
157
105
|
* @param props The properties for the function renderer.
|
|
158
106
|
* @param props.render The function to execute to get the child content.
|
|
159
|
-
* @param props.passedTheme The theme to propagate to the rendered child.
|
|
160
|
-
* // * @param props.processRawNode A reference to the `_processRawNode` method for recursive processing.
|
|
161
107
|
* @returns The rendered `ReactNode`.
|
|
162
108
|
* @private
|
|
163
|
-
*/static _functionRenderer(a){var b,c=a.render
|
|
109
|
+
*/static _functionRenderer(a){var b,c=a.render;// Invoke the render function to get the child node.
|
|
164
110
|
try{b=c()}catch(a){b=null}// Handle null/undefined
|
|
165
111
|
if(null===b||b===void 0)return b;// Handle arrays of elements (common in render props)
|
|
166
|
-
if(Array.isArray(b))return b.map(function(a,b){var c=BaseNode._processRawNode(a,
|
|
167
|
-
if(b instanceof React.Component){var
|
|
168
|
-
if(b instanceof BaseNode||isNodeInstance(b))
|
|
169
|
-
return void 0===(null===(g=h.rawProps)||void 0===g?void 0:g.nodetheme)&&void 0!==d?new BaseNode(h.element,_objectSpread(_objectSpread({},h.rawProps),{},{nodetheme:d})).render():h.render()}// Handle primitives and valid React nodes (string, number, boolean)
|
|
112
|
+
if(Array.isArray(b))return b.map(function(a,b){var c=BaseNode._processRawNode(a,b);return BaseNode._renderProcessedNode(c,"".concat(getElementTypeName(a),"-").concat(b))});// Handle React.Component instance
|
|
113
|
+
if(b instanceof React.Component){var d=b.render(),e=BaseNode._processRawNode(d);return BaseNode._renderProcessedNode(e)}// Handle BaseNode instance or NodeInstance
|
|
114
|
+
if(b instanceof BaseNode||isNodeInstance(b))return b.render();// Handle primitives and valid React nodes (string, number, boolean)
|
|
170
115
|
if("string"==typeof b||"number"==typeof b||"boolean"==typeof b)return b;// Process any other result types
|
|
171
|
-
var
|
|
116
|
+
var f=BaseNode._processRawNode(b);return f?BaseNode._renderProcessedNode(f):b}/**
|
|
172
117
|
* Generates a stable key for a node, especially for elements within an array.
|
|
173
118
|
*
|
|
174
119
|
* If an `existingKey` is provided, it is returned. Otherwise, a key is generated
|
|
@@ -186,41 +131,37 @@ var i=BaseNode._processRawNode(b,d);return i?BaseNode._renderProcessedNode(i,d):
|
|
|
186
131
|
* Processes a single raw node, recursively converting it into a `BaseNode` or other renderable type.
|
|
187
132
|
*
|
|
188
133
|
* This is a central method for normalizing children. It handles various types of input:
|
|
189
|
-
* - **`BaseNode` instances**: Re-creates them to ensure the correct
|
|
134
|
+
* - **`BaseNode` instances**: Re-creates them to ensure the correct key is applied.
|
|
190
135
|
* - **Primitives**: Returns strings, numbers, booleans, null, and undefined as-is.
|
|
191
136
|
* - **Functions (Render Props)**: Wraps them in a `BaseNode` that uses `_functionRenderer` to delay execution.
|
|
192
|
-
* - **Valid React Elements**: Converts them into `BaseNode` instances, extracting props
|
|
193
|
-
* - **React Component Types**: Wraps them in a `BaseNode
|
|
137
|
+
* - **Valid React Elements**: Converts them into `BaseNode` instances, extracting props.
|
|
138
|
+
* - **React Component Types**: Wraps them in a `BaseNode`.
|
|
194
139
|
* - **React Component Instances**: Renders them and processes the output recursively.
|
|
195
140
|
*
|
|
196
141
|
* It also generates a stable key for elements within an array if one is not provided.
|
|
197
142
|
* @param node The raw child node to process.
|
|
198
|
-
* @param passedTheme The theme inherited from the parent.
|
|
199
143
|
* @param nodeIndex The index of the child if it is in an array, used for key generation.
|
|
200
144
|
* @returns A processed `NodeElement` (typically a `BaseNode` instance or a primitive).
|
|
201
145
|
* @private
|
|
202
146
|
* @static
|
|
203
|
-
*/static _processRawNode(a,b
|
|
204
|
-
){var
|
|
147
|
+
*/static _processRawNode(a,b// Index for generating stable keys for array children
|
|
148
|
+
){var c=getComponentType(a);// Determine the type of the raw node
|
|
205
149
|
// Case 1: Child is already a BaseNode instance
|
|
206
|
-
if(a instanceof BaseNode||isNodeInstance(a)){var
|
|
207
|
-
// Prefer child's own theme
|
|
150
|
+
if(a instanceof BaseNode||isNodeInstance(a)){var d=a.rawProps||{};// Get initial raw props of the child
|
|
208
151
|
// Check if we can reuse the existing node
|
|
209
|
-
if(
|
|
210
|
-
return new BaseNode(a.element,_objectSpread(_objectSpread({},
|
|
211
|
-
key:g}));// Create a new BaseNode with merged props and theme
|
|
152
|
+
if(d.key!==void 0)return a;var e=BaseNode._generateKey({nodeIndex:b,element:a.element,existingKey:d.key,children:d.children});// Generate key if needed
|
|
153
|
+
return new BaseNode(a.element,_objectSpread(_objectSpread({},d),{},{key:e}));// Create a new BaseNode with merged props and theme
|
|
212
154
|
}// Case 2: Child is a primitive (string, number, boolean, null, undefined)
|
|
213
|
-
if("string"===
|
|
155
|
+
if("string"===c||"number"===c||"boolean"===c||null===a||void 0===a)return a;// Case 3: Child is a function that needs to be called during render (FunctionRenderer).
|
|
214
156
|
if(BaseNode._isFunctionChild(a)){// The key is for the BaseNode that wraps the _functionRenderer component.
|
|
215
157
|
// Functions themselves don't have a .key prop that we can access here.
|
|
216
|
-
var
|
|
217
|
-
return new BaseNode(BaseNode._functionRenderer,{render:a,
|
|
218
|
-
if(isValidElement(a)){var
|
|
219
|
-
if(isReactClassComponent(a)||"object"===
|
|
220
|
-
return new BaseNode(a,{
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return BaseNode._processRawNode(q,b,c)}// Case 7: Fallback for other ReactNode types (e.g., Fragments, Portals if not caught by isValidElement)
|
|
158
|
+
var f=BaseNode._generateKey({nodeIndex:b,element:BaseNode._functionRenderer});// Generate key for function renderer
|
|
159
|
+
return new BaseNode(BaseNode._functionRenderer,{render:a,key:f})}// Case 4: Child is a React Element (JSX element like <div> or <MyComponent>)
|
|
160
|
+
if(isValidElement(a)){var g=a.props,h=g.style,i=_objectWithoutProperties(g,_excluded3),j=_objectSpread(_objectSpread({},i),h||{}),k=BaseNode._generateKey({nodeIndex:b,element:a.type,existingKey:a.key,children:j.children});return new BaseNode(a.type,_objectSpread(_objectSpread({},j),{},{key:k}))}// Case 5: Child is an ElementType (string tag, class component, Memo/ForwardRef)
|
|
161
|
+
if(isReactClassComponent(a)||"object"===c&&(isMemo(a)||isForwardRef(a))){var l,m=BaseNode._generateKey({nodeIndex:b,element:a,children:"object"===_typeof(a)&&"props"in a?null===(l=a.props)||void 0===l?void 0:l.children:void 0});// ElementTypes don't have an intrinsic key from the node itself.
|
|
162
|
+
return new BaseNode(a,{key:m})}// Case 6: Handle instances of React.Component
|
|
163
|
+
if(a instanceof React.Component){var n=a.render();// Recursively process the rendered element with a parent theme and index if available
|
|
164
|
+
return BaseNode._processRawNode(n,b)}// Case 7: Fallback for other ReactNode types (e.g., Fragments, Portals if not caught by isValidElement)
|
|
224
165
|
// These are returned as-is. If they are elements within an array, React expects them to have keys.
|
|
225
166
|
// This logic primarily adds keys to BaseNode instances we create, other ReactNodes are returned as-is.
|
|
226
167
|
return a}/**
|
|
@@ -238,7 +179,7 @@ return a}/**
|
|
|
238
179
|
* @returns The rendered `ReactElement`.
|
|
239
180
|
* @throws {Error} If the node's `element` is not a valid React element type.
|
|
240
181
|
*/render(){var a=this;if(!isValidElementType(this.element)){var b=getComponentType(this.element);throw new Error("Invalid element type: ".concat(b," provided!"))}// Extract children and key
|
|
241
|
-
var c=this.props,d=c.children,e=c.key,f=c.nativeProps,g=_objectWithoutProperties(c,
|
|
182
|
+
var c=this.props,d=c.children,e=c.key,f=c.nativeProps,g=_objectWithoutProperties(c,_excluded4),h=void 0;if(d!==void 0&&null!==d){if(!this._normalizedChildren)if(!Array.isArray(d))this._normalizedChildren=this._normalizeChild(d);else if(0<d.length){var i=d.map(function(b){return a._normalizeChild(b)});this._normalizedChildren=i.every(function(a){return null===a||void 0===a})?void 0:i}else this._normalizedChildren=void 0;h=this._normalizedChildren}// If the element is a Fragment, use React.createElement directly
|
|
242
183
|
if(this.element===Fragment||isFragment(this.element))return createElement(this.element,{key:e},h);// If the element has a `css` prop and has style tag, render using the `StyledRenderer` component
|
|
243
184
|
// This enables emotion-based style handling for the element
|
|
244
185
|
if(this.element&&!hasNoStyleTag(this.element)&&g.css){// Set displayName for easier debugging in React DevTools
|
|
@@ -293,7 +234,7 @@ return this._portalReactRoot}}}/**
|
|
|
293
234
|
* @param props The props for the node (optional).
|
|
294
235
|
* @param additionalProps Additional props to merge into the node (optional).
|
|
295
236
|
* @returns A new `BaseNode` instance as a `NodeInstance<E>`.
|
|
296
|
-
*/_defineProperty(BaseNode,"_isServer","undefined"==typeof window),_defineProperty(BaseNode,"
|
|
237
|
+
*/_defineProperty(BaseNode,"_isServer","undefined"==typeof window),_defineProperty(BaseNode,"_generateKey",function(a){var b=a.nodeIndex,c=a.element,d=a.existingKey,e=a.children;if(d)return d;var f,g=getElementTypeName(c);return f=Array.isArray(e)&&0<e.length?void 0===b?"".concat(g,"-").concat(e.length):"".concat(g,"-").concat(b,"-").concat(e.length):void 0===b?g:"".concat(g,"-").concat(b),f});export function Node(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:{},d=_objectSpread(_objectSpread({},b),c);return new BaseNode(a,d)}/**
|
|
297
238
|
* Creates a curried node factory for a given React element or component type.
|
|
298
239
|
*
|
|
299
240
|
* Returns a function that, when called with props, produces a `NodeInstance<E>`.
|