@meonode/ui 0.1.11 → 0.1.13
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/dist/core.node.d.ts +19 -10
- package/dist/core.node.d.ts.map +1 -1
- package/dist/core.node.js +89 -41
- package/dist/node.type.d.ts +3 -3
- package/dist/node.type.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/core.node.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { type ReactNode } from 'react';
|
|
2
|
-
import type { BaseNodeInstance, NodeElement, NodeProps } from './node.type.js';
|
|
2
|
+
import type { BaseNodeInstance, NodeElement, NodeProps, Theme } from './node.type.js';
|
|
3
3
|
/**
|
|
4
4
|
* Factory function to create a BaseNode instance.
|
|
5
5
|
* @param element The React element type.
|
|
@@ -9,17 +9,26 @@ import type { BaseNodeInstance, NodeElement, NodeProps } from './node.type.js';
|
|
|
9
9
|
export declare function Node<E extends NodeElement>(element: E, props?: Partial<NodeProps<E>>): BaseNodeInstance<E>;
|
|
10
10
|
/**
|
|
11
11
|
* Higher-order component wrapper that converts BaseNode components into React components.
|
|
12
|
+
* This wrapper ensures proper theme propagation and component rendering in the React ecosystem.
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
14
|
+
* Key features:
|
|
15
|
+
* - Converts BaseNode instances to React elements via render()
|
|
16
|
+
* - Handles theme inheritance and merging
|
|
17
|
+
* - Preserves component props
|
|
18
|
+
* - Type-safe with generic prop types
|
|
19
|
+
* @template T - The props type for the wrapped component
|
|
20
|
+
* @param component Component function that returns a BaseNode or ReactNode
|
|
21
|
+
* @returns A React function component that handles BaseNode conversion and theme propagation
|
|
19
22
|
* @example
|
|
20
|
-
*
|
|
21
|
-
*
|
|
23
|
+
* // Basic usage
|
|
24
|
+
* const Button = Component((props) => {
|
|
25
|
+
* return Node('button', {
|
|
26
|
+
* ...props,
|
|
27
|
+
* theme: { color: 'blue' }
|
|
28
|
+
* })
|
|
22
29
|
* })
|
|
23
30
|
*/
|
|
24
|
-
export declare function Component<T extends Record<string, any
|
|
31
|
+
export declare function Component<T extends Record<string, any> & {
|
|
32
|
+
theme?: Theme;
|
|
33
|
+
}>(component: (props: T) => BaseNodeInstance<any> | ReactNode): (props?: T) => string | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | BaseNodeInstance<any> | null | undefined;
|
|
25
34
|
//# sourceMappingURL=core.node.d.ts.map
|
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,OAAO,KAAK,EAAE,EAAsG,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AACjJ,OAAO,KAAK,EAAE,gBAAgB,EAAwC,WAAW,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"core.node.d.ts","sourceRoot":"","sources":["../src/core.node.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAsG,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AACjJ,OAAO,KAAK,EAAE,gBAAgB,EAAwC,WAAW,EAAE,SAAS,EAAqB,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAoXjJ;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,WAAW,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,GAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAM,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAU9G;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAAE,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,gBAAgB,CAAC,GAAG,CAAC,GAAG,SAAS,IAE7H,QAAO,CAAW,kXAmB3B"}
|
package/dist/core.node.js
CHANGED
|
@@ -1,30 +1,38 @@
|
|
|
1
|
-
"use strict";var _excluded=["children","nodeTheme"],_excluded2=["children","key"];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
|
|
1
|
+
"use strict";var _excluded=["children","nodeTheme"],_excluded2=["children","key"];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 _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 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 _classCallCheck(b,a){if(!(b instanceof a))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),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,isValidElement}from"react";import{getComponentType,getCSSProps,getDOMProps,getElementTypeName,getValueByPath}from"./node.helper.js";import{isForwardRef,isMemo,isReactClassComponent,isValidElementType}from"./react-is.helper.js";/**
|
|
2
2
|
* Represents a node in a React component tree, providing a structured way to define and manipulate
|
|
3
3
|
* React elements before they are rendered. Handles props processing, theme application, and child node management.
|
|
4
4
|
* @template E The type of the React element this node represents (e.g., 'div', a custom component).
|
|
5
|
-
*/var BaseNode=/*#__PURE__*/function(){/** The React element type for this node. *//** The original, unprocessed props passed to this node during construction.
|
|
5
|
+
*/var BaseNode=/*#__PURE__*/function(){/** The React element type for this node. *//** The original, unprocessed props passed to this node during construction. */// Initial props before processing
|
|
6
|
+
/** The processed props for this node, including styles, DOM attributes, and children. *//**
|
|
6
7
|
* Constructs a new BaseNode instance.
|
|
7
8
|
* @param element The React element type.
|
|
8
9
|
* @param rawProps The raw props for the node.
|
|
9
|
-
*/function BaseNode(a,b){var c=this;_classCallCheck(this,BaseNode),this
|
|
10
|
-
|
|
11
|
-
if(
|
|
10
|
+
*/function BaseNode(a,b){var c=this;_classCallCheck(this,BaseNode),_defineProperty(this,"_normalizeChild",function(a){var b,d;if(!a)return a;var e=(null===(b=c.rawProps)||void 0===b?void 0:b.nodeTheme)||(null===(d=c.rawProps)||void 0===d?void 0:d.theme)||c.props.nodeTheme||c.props.theme;// For BaseNode instances, apply current theme if child has no theme
|
|
11
|
+
if(a instanceof BaseNode){var f;return null!==(f=a.rawProps)&&void 0!==f&&f.nodeTheme||void 0===e?a.render():new BaseNode(a.element,_objectSpread(_objectSpread({},a.rawProps),{},{nodeTheme:e})).render()}// For React.Component instances, wrap in BaseNode with theme if needed
|
|
12
|
+
if(a instanceof React.Component)return a.props.nodeTheme||void 0===e?a.render():new BaseNode(a.render(),_objectSpread(_objectSpread({},a.props),{},{nodeTheme:e})).render();// Validate element type before returning
|
|
13
|
+
if(!isValidElementType(a)){var g=getComponentType(a);throw new Error("Invalid element type: ".concat(g," provided!"))}// Return valid React elements as-is
|
|
14
|
+
return a}),this.element=a,this.rawProps=b;var d=b||{},e=d.children,f=d.nodeTheme,g=_objectWithoutProperties(d,_excluded),h=getCSSProps(g),i=this._resolveStyleWithTheme(h,f);// Extract children and theme
|
|
15
|
+
// 1. Resolve styles and DOM props for this node
|
|
16
|
+
i=0<Object.keys(i).length?i:{};var j=getDOMProps(g),k=void 0;// Extract DOM-related props
|
|
17
|
+
// 2. Process rawNoderen into BaseNode instances or primitives, passing down currentTheme
|
|
18
|
+
if(e!==void 0&&null!==e)if(Array.isArray(e)){k=e.map(function(a,b){return c._processRawNode(a,f,b)}// Process each child, passing index
|
|
12
19
|
)}else// For a single child, no index is passed; existing key logic in _processRawNode will apply
|
|
13
20
|
k=this._processRawNode(e,f);// 3. Construct final this.props
|
|
14
|
-
this.props=_objectSpread(_objectSpread({},j),{},{style:i,nodeTheme:f,children:k
|
|
21
|
+
this.props=_objectSpread(_objectSpread({},j),{},{style:i,nodeTheme:f,children:k// Assign processed children
|
|
22
|
+
})}/**
|
|
15
23
|
* Resolves style properties by replacing theme path placeholders with actual theme values.
|
|
16
24
|
* Handles complex strings like '1px solid theme.background.primary' and iterative resolution.
|
|
17
25
|
* @param initialCssProps The initial CSS properties object.
|
|
18
26
|
* @param theme The theme object to use for resolving paths.
|
|
19
27
|
* @returns A new CSSProperties object with theme values resolved.
|
|
20
|
-
*/return _createClass(BaseNode,[{key:"_resolveStyleWithTheme",value:function _resolveStyleWithTheme(a,b){
|
|
21
|
-
if(!b||0===Object.keys(a).length)return a;var c=_objectSpread({},a);//
|
|
22
|
-
for(var
|
|
23
|
-
|
|
28
|
+
*/return _createClass(BaseNode,[{key:"_resolveStyleWithTheme",value:function _resolveStyleWithTheme(a,b){var c;// If no theme is provided or there are no initial CSS props to process, return the initial props.
|
|
29
|
+
if(!b||0===Object.keys(a).length)return a;var d=_objectSpread(_objectSpread({},null===(c=this.rawProps)||void 0===c?void 0:c.nodeTheme),b),e=_objectSpread({},a);// Merge nodeTheme from rawProps with theme
|
|
30
|
+
for(var f in e)if(Object.prototype.hasOwnProperty.call(e,f)){var g=e[f];if("string"==typeof g&&g.includes("theme.")){var h=g;// Iteratively resolve theme references within the string
|
|
31
|
+
h=h.replace(/theme\.([a-zA-Z0-9_.-]+)/g,function(a,b){var c=getValueByPath(d,b);// Use 'theme' passed to the function
|
|
24
32
|
// Replace if themeValue is found and is a string or number.
|
|
25
33
|
// null is explicitly excluded to avoid 'null' string in output unless intended.
|
|
26
|
-
return void 0!==
|
|
27
|
-
}),
|
|
34
|
+
return void 0!==c&&null!==c&&("string"==typeof c||"number"==typeof c)?c+"":a;// If themeValue is not a string/number, or is undefined/null, keep the original placeholder
|
|
35
|
+
}),e[f]=h}}return e}/**
|
|
28
36
|
* React component that renders the result of a function child, supporting theme propagation.
|
|
29
37
|
*
|
|
30
38
|
* This component is used to render children that are functions (i.e., `() => Children`).
|
|
@@ -37,9 +45,11 @@ return void 0!==d&&null!==d&&("string"==typeof d||"number"==typeof d)?d+"":a;//
|
|
|
37
45
|
*/},{key:"_functionRenderer",value:function _functionRenderer(a){var b=a.render,c=a.passedTheme,d=a.passedKey,e=a.processRawNode,f=b();// Call the user-provided render function to get the child.
|
|
38
46
|
if(f instanceof React.Component){var g=f.render(),h=e(g,c);return h instanceof BaseNode?h.render():h}if(f instanceof BaseNode){var i,j=f;// If the returned BaseNode does not have its own theme, but a theme is provided,
|
|
39
47
|
// re-create the node with the provided theme to ensure correct theme propagation.
|
|
40
|
-
return void 0===(null===(i=j.rawProps)||void 0===i?void 0:i.nodeTheme)&&void 0!==c?new BaseNode(j.element,_objectSpread(_objectSpread({},j.rawProps||{}),{},{nodeTheme:c,theme:c,//
|
|
48
|
+
return void 0===(null===(i=j.rawProps)||void 0===i?void 0:i.nodeTheme)&&void 0!==c?new BaseNode(j.element,_objectSpread(_objectSpread({},j.rawProps||{}),{},{nodeTheme:c,theme:c,// Pass theme for consistency if used in rawProps
|
|
41
49
|
key:d})).render():j.render();// If the node already has a theme or no theme is provided, render as-is.
|
|
42
|
-
}//
|
|
50
|
+
}// Process the result if it's not a React.Component or BaseNode
|
|
51
|
+
var k=e(f,c);if(k instanceof BaseNode){var l,m;if(((null===(l=k.rawProps)||void 0===l?void 0:l.theme)||(null===(m=k.rawProps)||void 0===m?void 0:m.nodeTheme))===void 0&&c!==void 0){var n,o,p;return new BaseNode(k.element,_objectSpread(_objectSpread({},k.rawProps),{},{nodeTheme:(null===(n=k.rawProps)||void 0===n?void 0:n.theme)||(null===(o=k.rawProps)||void 0===o?void 0:o.nodeTheme)||c,key:(null===(p=k.rawProps)||void 0===p?void 0:p.key)||d// Use existing key or passed key
|
|
52
|
+
})).render()}return k.render()}// If the result is not a BaseNode (e.g., JSX, string, etc.), return it directly.
|
|
43
53
|
// Note: Non-BaseNode results will not automatically receive the theme.
|
|
44
54
|
return f}/**
|
|
45
55
|
* Processes a single raw child element, converting it into a ProcessedChild.
|
|
@@ -50,58 +60,96 @@ return f}/**
|
|
|
50
60
|
* @param childIndex Optional index of the child if it's part of an array.
|
|
51
61
|
* @returns The processed child.
|
|
52
62
|
*/},{key:"_processRawNode",value:function _processRawNode(a,b,c// Index for generating stable keys for array children
|
|
53
|
-
){var d=getComponentType(a),e=function generateIndexedKeyIfNeeded(a,b){if(b!==void 0&&null!==b)return b;if(void 0!==c){var d=getElementTypeName(a)
|
|
54
|
-
}
|
|
63
|
+
){var d=getComponentType(a),e=function generateIndexedKeyIfNeeded(a,b){if(b!==void 0&&null!==b)return b;if(void 0!==c){var d=getElementTypeName(a);// Get element type name for key generation
|
|
64
|
+
return"".concat(d,"-").concat(c)}// No explicit key, and not an array child, so BaseNode constructor will handle.
|
|
65
|
+
};// Determine the type of the raw node
|
|
66
|
+
// Helper to generate an indexed key if no explicit key is present and an index is available.
|
|
55
67
|
// Case 1: Child is already a BaseNode instance
|
|
56
|
-
if(a instanceof BaseNode){var f=a,g=f.rawProps||{},h=g.nodeTheme,i=e(f.element,g.key);//
|
|
57
|
-
|
|
68
|
+
if(a instanceof BaseNode){var f=a,g=f.rawProps||{},h=g.nodeTheme,i=e(f.element,g.key);// Get initial raw props of the child
|
|
69
|
+
// Get the child's own theme
|
|
70
|
+
// Prefer child's own theme
|
|
71
|
+
return new BaseNode(f.element,_objectSpread(_objectSpread({},g),{},{nodeTheme:h||b||{},// Use the determined theme for the new node
|
|
72
|
+
key:i}));// Create a new BaseNode with merged props and theme
|
|
73
|
+
}// Case 2: Child is a primitive (string, number, boolean, null, undefined)
|
|
58
74
|
if("string"===d||"number"===d||"boolean"===d||null===a||void 0===a)return a;// Case 3: Child is a function that needs to be called during render (FunctionRenderer).
|
|
59
75
|
if("function"===d&&!isReactClassComponent(a)&&!isMemo(a)&&!isForwardRef(a)){// The key is for the BaseNode that wraps the _functionRenderer component.
|
|
60
76
|
// Functions themselves don't have a .key prop that we can access here.
|
|
61
|
-
var j=e(this._functionRenderer,void 0)
|
|
77
|
+
var j=e(this._functionRenderer,void 0);// Generate key for function renderer
|
|
78
|
+
return new BaseNode(this._functionRenderer,{processRawNode:this._processRawNode.bind(this),render:a,passedTheme:b,key:j// Assign the generated key
|
|
79
|
+
})}// Case 4: Child is a React Element (JSX element like <div> or <MyComponent>)
|
|
62
80
|
if(isValidElement(a)){var k,l=_objectSpread({},a.props);// Extract and merge props from the JSX element, flattening style props
|
|
63
81
|
l=_objectSpread(_objectSpread({},l.style),l),delete l.style;// Remove original style object after merging
|
|
64
|
-
// Handle theme
|
|
82
|
+
// Handle theme: prefer nodeTheme from child's props, fallback to parent theme
|
|
65
83
|
var m=(null===(k=l)||void 0===k?void 0:k.nodeTheme)||b,n=e(a.type,a.key);// For array children without keys, generate stable key from element type and index
|
|
66
84
|
// Create new BaseNode instance with processed props and theme
|
|
67
|
-
return new BaseNode(a.type,_objectSpread(_objectSpread({},l),{},{nodeTheme:m,key:n
|
|
85
|
+
return new BaseNode(a.type,_objectSpread(_objectSpread({},l),{},{nodeTheme:m,key:n// Assign the generated key
|
|
86
|
+
}))}// Case 5: Child is an ElementType (string tag, class component, Memo/ForwardRef)
|
|
68
87
|
if(isReactClassComponent(a)||"object"===d&&(isMemo(a)||isForwardRef(a))){// ElementTypes don't have an intrinsic key from the rawNode itself.
|
|
69
|
-
var o=e(a,void 0);return new BaseNode(a,{nodeTheme:b
|
|
70
|
-
|
|
88
|
+
var o=e(a,void 0);return new BaseNode(a,{nodeTheme:b,// Apply parent theme
|
|
89
|
+
key:o})}// Case 6: Handle instances of React.Component
|
|
90
|
+
if(a instanceof React.Component){var p=a.render();// Recursively process the rendered element with parent theme and index if available
|
|
71
91
|
return this._processRawNode(p,b,c)}// Case 7: Fallback for other ReactNode types (e.g., Fragments, Portals if not caught by isValidElement)
|
|
72
92
|
// These are returned as-is. If they are elements within an array, React expects them to have keys.
|
|
73
|
-
// This logic primarily adds keys to BaseNode instances we create.
|
|
93
|
+
// This logic primarily adds keys to BaseNode instances we create, other ReactNodes are returned as-is.
|
|
74
94
|
return a}/**
|
|
95
|
+
* Normalizes a child node into a renderable ReactNode.
|
|
96
|
+
* Processes different types of child nodes to ensure they can be properly rendered
|
|
97
|
+
* while maintaining theme inheritance.
|
|
98
|
+
*
|
|
99
|
+
* Handles:
|
|
100
|
+
* - BaseNode instances (applies theme if needed)
|
|
101
|
+
* - React.Component instances (applies theme if needed)
|
|
102
|
+
* - Other valid React element types (returned as-is)
|
|
103
|
+
* - null/undefined values (returned as-is)
|
|
104
|
+
* @param child The child node to normalize into a renderable form
|
|
105
|
+
* @returns The normalized ReactNode that can be rendered by React
|
|
106
|
+
* @throws Error if child is an invalid element type
|
|
107
|
+
*/},{key:"render",value:/**
|
|
75
108
|
* Converts this BaseNode instance into a renderable React node.
|
|
76
109
|
* Recursively processes child nodes and uses `React.createElement` to construct the final React element.
|
|
77
110
|
* @returns A ReactNode representing the rendered element.
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
111
|
+
*/function render(){if(!isValidElementType(this.element)){var a=getComponentType(this.element);throw new Error("Invalid element type: ".concat(a," provided!"))}var b=this.props,c=b.children,d=b.key,e=_objectWithoutProperties(b,_excluded2),f=void 0;// Extract children and key
|
|
112
|
+
// More accurate type
|
|
113
|
+
if(void 0!==c&&null!==c)if(!Array.isArray(c))f=this._normalizeChild(c);else if(0<c.length){var g=c.map(this._normalizeChild);// Normalize each child in the array
|
|
114
|
+
// Check if all children are null/undefined (e.g. conditional rendering resulted in nothing)
|
|
82
115
|
f=g.every(function(a){return null===a||void 0===a})?void 0:g}else f=void 0;// Prepare props for React.createElement
|
|
83
|
-
var h=_objectSpread(_objectSpread({},
|
|
84
|
-
key:
|
|
85
|
-
});//
|
|
116
|
+
var h=_objectSpread(_objectSpread({},e),{},{// Cast otherProps
|
|
117
|
+
key:d// This is the key of the current BaseNode itself
|
|
118
|
+
});// Prepare props for React.createElement
|
|
119
|
+
// Delete key `nodeTheme` as it's not a valid DOM/React prop for the element
|
|
86
120
|
return delete h.nodeTheme,createElement(this.element,h,f)}}])}();/**
|
|
87
121
|
* Factory function to create a BaseNode instance.
|
|
88
122
|
* @param element The React element type.
|
|
89
123
|
* @param props The props for the node.
|
|
90
124
|
* @returns BaseNodeInstance<E> - A new BaseNode instance.
|
|
91
125
|
*/export function Node(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c=_objectSpread({},b);// Ensure we are working with a mutable copy
|
|
92
|
-
// 'theme' prop itself is not directly used by BaseNode after this, nodeTheme is.
|
|
126
|
+
// 'theme' prop itself is not directly used by BaseNode after this, nodeTheme is used.
|
|
93
127
|
// We can keep `theme` in rawProps if needed for cloning or inspection.
|
|
94
128
|
return c.theme&&void 0===c.nodeTheme&&(c.nodeTheme=c.theme),new BaseNode(a,c)}/**
|
|
95
129
|
* Higher-order component wrapper that converts BaseNode components into React components.
|
|
130
|
+
* This wrapper ensures proper theme propagation and component rendering in the React ecosystem.
|
|
96
131
|
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* @
|
|
132
|
+
* Key features:
|
|
133
|
+
* - Converts BaseNode instances to React elements via render()
|
|
134
|
+
* - Handles theme inheritance and merging
|
|
135
|
+
* - Preserves component props
|
|
136
|
+
* - Type-safe with generic prop types
|
|
137
|
+
* @template T - The props type for the wrapped component
|
|
138
|
+
* @param component Component function that returns a BaseNode or ReactNode
|
|
139
|
+
* @returns A React function component that handles BaseNode conversion and theme propagation
|
|
103
140
|
* @example
|
|
104
|
-
*
|
|
105
|
-
*
|
|
141
|
+
* // Basic usage
|
|
142
|
+
* const Button = Component((props) => {
|
|
143
|
+
* return Node('button', {
|
|
144
|
+
* ...props,
|
|
145
|
+
* theme: { color: 'blue' }
|
|
146
|
+
* })
|
|
106
147
|
* })
|
|
107
|
-
*/export function Component(a){
|
|
148
|
+
*/export function Component(a){// Create wrapper component that handles theme and rendering
|
|
149
|
+
return function(){var b=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},c=a(_objectSpread({},b));// Execute wrapped component
|
|
150
|
+
// Handle BaseNode results - requires special processing
|
|
151
|
+
if(c instanceof BaseNode){var d,e;// Theme merging: Check if we need to handle theme inheritance
|
|
152
|
+
if(!!(null!==b&&void 0!==b&&b.theme||null!==b&&void 0!==b&&b.nodeTheme)||!!(null!==(d=c.rawProps)&&void 0!==d&&d.theme||null!==(e=c.rawProps)&&void 0!==e&&e.nodeTheme)){var f,g;return new BaseNode(c.element,_objectSpread(_objectSpread({},c.rawProps),{},{// Theme priority: props.theme > rawProps.theme > rawProps.nodeTheme
|
|
153
|
+
nodeTheme:(null===b||void 0===b?void 0:b.theme)||(null===(f=c.rawProps)||void 0===f?void 0:f.theme)||(null===(g=c.rawProps)||void 0===g?void 0:g.nodeTheme)})).render()}return c.render();// No theme to handle, just render
|
|
154
|
+
}// Direct return for non-BaseNode results (standard React nodes)
|
|
155
|
+
return c}}
|
package/dist/node.type.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Attributes as ReactAttributes, ComponentProps, CSSProperties, ReactNode, JSX, ElementType, ComponentType, JSXElementConstructor,
|
|
2
|
-
export type NodeElement = ReactNode |
|
|
1
|
+
import type { Attributes as ReactAttributes, ComponentProps, CSSProperties, ReactNode, JSX, ElementType, ComponentType, JSXElementConstructor, Component } from 'react';
|
|
2
|
+
export type NodeElement = ReactNode | Component<any, any> | ElementType | ComponentType<any> | BaseNodeInstance<any> | ((props?: any) => ReactNode | Promise<ReactNode> | Component<any> | BaseNodeInstance<any>);
|
|
3
3
|
/**
|
|
4
4
|
* Defines valid child types that can be passed to a node:
|
|
5
5
|
* - ReactNode: Any valid React child (elements, strings, numbers, etc.)
|
|
@@ -7,7 +7,7 @@ export type NodeElement = ReactNode | ReactInstance | ElementType | ComponentTyp
|
|
|
7
7
|
* - BaseNodeInstance: Other node instances in the tree
|
|
8
8
|
* - Function: Lazy child evaluation, useful for conditional rendering and hooks
|
|
9
9
|
*/
|
|
10
|
-
export type Children = ReactNode |
|
|
10
|
+
export type Children = ReactNode | Component<any> | NodeElement | BaseNodeInstance<any>;
|
|
11
11
|
/**
|
|
12
12
|
* Forward declaration of the BaseNode interface to avoid circular dependencies.
|
|
13
13
|
* Defines the core structure and capabilities of a BaseNode instance.
|
package/dist/node.type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.type.d.ts","sourceRoot":"","sources":["../src/node.type.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,IAAI,eAAe,EAC7B,cAAc,EACd,aAAa,EACb,SAAS,EACT,GAAG,EACH,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,
|
|
1
|
+
{"version":3,"file":"node.type.d.ts","sourceRoot":"","sources":["../src/node.type.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,IAAI,eAAe,EAC7B,cAAc,EACd,aAAa,EACb,SAAS,EACT,GAAG,EACH,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,SAAS,EACV,MAAM,OAAO,CAAA;AAEd,MAAM,MAAM,WAAW,GACnB,SAAS,GACT,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,GACnB,WAAW,GACX,aAAa,CAAC,GAAG,CAAC,GAClB,gBAAgB,CAA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,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,gBAAgB,CAAC,CAAC,CAAC,CAAA;CACrG"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meonode/ui",
|
|
3
3
|
"description": "A structured approach to component composition with built-in theming, prop separation, and dynamic children handling.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.13",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/main.js",
|
|
7
7
|
"types": "./dist/main.d.ts",
|