@meonode/ui 0.2.21 → 0.2.22
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 +9 -0
- package/dist/components/styled-renderer.client.d.ts +1 -3
- package/dist/components/styled-renderer.client.d.ts.map +1 -1
- package/dist/components/styled-renderer.client.js +1 -1
- package/dist/core.node.d.ts +1 -20
- package/dist/core.node.d.ts.map +1 -1
- package/dist/core.node.js +22 -46
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.2.22] - 2025-09-29
|
|
9
|
+
|
|
10
|
+
### Refactor
|
|
11
|
+
|
|
12
|
+
- **refactor(core)**: Refactor key and CSS prop handling for improved rendering
|
|
13
|
+
- Removed manual key generation logic, relying on React's reconciliation for array children.
|
|
14
|
+
- Streamlined CSS prop handling within `BaseNode` and `StyledRenderer` for better integration with styling solutions.
|
|
15
|
+
- Updated `createElement` calls to correctly spread children, supporting both single and array children.
|
|
16
|
+
|
|
8
17
|
## [0.2.21] - 2025-09-23
|
|
9
18
|
|
|
10
19
|
### Refactor
|
|
@@ -6,7 +6,5 @@ export interface StyledRendererProps<E extends NodeElement> {
|
|
|
6
6
|
children?: ReactNode;
|
|
7
7
|
css?: CSSInterpolation;
|
|
8
8
|
}
|
|
9
|
-
export default function StyledRenderer<E extends NodeElement, TProps extends Record<string, any>>({ element,
|
|
10
|
-
css: CSSInterpolation;
|
|
11
|
-
}, string | import("react").JSXElementConstructor<any>>;
|
|
9
|
+
export default function StyledRenderer<E extends NodeElement, TProps extends Record<string, any>>({ element, children, ...props }: StyledRendererProps<E> & TProps): import("react").ReactElement<Omit<StyledRendererProps<E> & TProps, "children" | "element">, string | import("react").JSXElementConstructor<any>>;
|
|
12
10
|
//# sourceMappingURL=styled-renderer.client.d.ts.map
|
|
@@ -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,EAAE,MAAM,OAAO,CAAA;AAEhD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,WAAW;IACxD,OAAO,EAAE,CAAC,CAAA;IACV,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,GAAG,CAAC,EAAE,gBAAgB,CAAA;CACvB;AAED,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,SAAS,WAAW,EAAE,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EAChG,OAAO,EACP,
|
|
1
|
+
{"version":3,"file":"styled-renderer.client.d.ts","sourceRoot":"","sources":["../../src/components/styled-renderer.client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAEhD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,WAAW;IACxD,OAAO,EAAE,CAAC,CAAA;IACV,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,GAAG,CAAC,EAAE,gBAAgB,CAAA;CACvB;AAED,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,SAAS,WAAW,EAAE,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EAChG,OAAO,EACP,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,MAAM,oJAEjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";var _excluded=["element","
|
|
1
|
+
"use client";var _excluded=["element","children"];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{jsx}from"@emotion/react";export default function StyledRenderer(a){var b=a.element,c=a.children,d=_objectWithoutProperties(a,_excluded);return jsx(b,d,c)}StyledRenderer.displayName="Styled";
|
package/dist/core.node.d.ts
CHANGED
|
@@ -172,22 +172,6 @@ export declare class BaseNode<E extends NodeElementType> implements NodeInstance
|
|
|
172
172
|
* @private
|
|
173
173
|
*/
|
|
174
174
|
private static _functionRenderer;
|
|
175
|
-
/**
|
|
176
|
-
* Generates a stable key for a node, especially for elements within an array.
|
|
177
|
-
*
|
|
178
|
-
* If an `existingKey` is provided, it is returned. Otherwise, a key is generated
|
|
179
|
-
* based on the element's type name and its index within a list of siblings.
|
|
180
|
-
* This helps prevent re-rendering issues in React when dealing with dynamic lists.
|
|
181
|
-
* @param options The options for key generation.
|
|
182
|
-
* @param options.nodeIndex The index of the node in an array of children.
|
|
183
|
-
* @param options.element The element for which to generate a key.
|
|
184
|
-
* @param options.existingKey An existing key, if one was already provided.
|
|
185
|
-
* @param options.children The children of the node, used to add complexity to the key.
|
|
186
|
-
* @returns A React key, or `undefined` if no key could be generated.
|
|
187
|
-
* @private
|
|
188
|
-
* @static
|
|
189
|
-
*/
|
|
190
|
-
private static _generateKey;
|
|
191
175
|
/**
|
|
192
176
|
* Processes a single raw node, recursively converting it into a `BaseNode` or other renderable type.
|
|
193
177
|
*
|
|
@@ -198,11 +182,8 @@ export declare class BaseNode<E extends NodeElementType> implements NodeInstance
|
|
|
198
182
|
* - **Valid React Elements**: Converts them into `BaseNode` instances, extracting props and propagating the theme.
|
|
199
183
|
* - **React Component Types**: Wraps them in a `BaseNode` with the parent theme.
|
|
200
184
|
* - **React Component Instances**: Renders them and processes the output recursively.
|
|
201
|
-
*
|
|
202
|
-
* It also generates a stable key for elements within an array if one is not provided.
|
|
203
185
|
* @param node The raw child node to process.
|
|
204
186
|
* @param passedTheme The theme inherited from the parent.
|
|
205
|
-
* @param nodeIndex The index of the child if it is in an array, used for key generation.
|
|
206
187
|
* @returns A processed `NodeElement` (typically a `BaseNode` instance or a primitive).
|
|
207
188
|
* @private
|
|
208
189
|
* @static
|
|
@@ -231,7 +212,7 @@ export declare class BaseNode<E extends NodeElementType> implements NodeInstance
|
|
|
231
212
|
* 1. Validating that the node's `element` type is renderable.
|
|
232
213
|
* 2. Normalizing processed children into `ReactNode`s using `_normalizeChild`.
|
|
233
214
|
* 3. Caching normalized children to avoid re-processing on subsequent renders.
|
|
234
|
-
* 4. Assembling the final props, including `
|
|
215
|
+
* 4. Assembling the final props, including `style`, and other attributes.
|
|
235
216
|
* 5. If the element has a `css` prop, it may be wrapped in a `StyledRenderer` to handle
|
|
236
217
|
* CSS-in-JS styling.
|
|
237
218
|
* 6. Finally, calling `React.createElement` with the element, props, and children.
|
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,EACP,YAAY,EAEb,MAAM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AAC,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,4 +1,4 @@
|
|
|
1
|
-
"use strict";var _excluded=["ref","key","children","nodetheme","theme","props"],_excluded2=["style"],_excluded3=["style","css"],_excluded4=["style"],_excluded5=["children","
|
|
1
|
+
"use strict";var _excluded=["ref","key","children","nodetheme","theme","props"],_excluded2=["style"],_excluded3=["style","css"],_excluded4=["style"],_excluded5=["children","css","nativeProps"];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 _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{createStableHash,isNodeInstance,resolveDefaultStyle}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,omit,omitUndefined}from"./helper/common.helper.js";import StyledRenderer from"./components/styled-renderer.client.js";import{resolveObjWithTheme}from"./helper/theme.helper.js";/**
|
|
2
2
|
* Represents a node in a React component tree with theme and styling capabilities.
|
|
3
3
|
* This class wraps React elements and handles:
|
|
4
4
|
* - Props processing and normalization
|
|
@@ -112,7 +112,7 @@ if(BaseNode._processedChildrenMapCache.has(d))return void BaseNode._processedChi
|
|
|
112
112
|
* @returns The processed children, ready for normalization and rendering.
|
|
113
113
|
* @private
|
|
114
114
|
*/_processChildren(a,b){if(a){// Use RSC-safe caching strategy
|
|
115
|
-
var c=this._getCachedChildren(a,b);if(c)return c;var d;return d="function"==typeof a?a:Array.isArray(a)?a.map(function(a
|
|
115
|
+
var c=this._getCachedChildren(a,b);if(c)return c;var d;return d="function"==typeof a?a:Array.isArray(a)?a.map(function(a){return BaseNode._processRawNode(a,b)}):BaseNode._processRawNode(a,b),BaseNode._isServer||this._setCachedChildren(a,b,d),d}}/**
|
|
116
116
|
* Renders a processed `NodeElement` into a `ReactNode`, applying a theme and key if necessary.
|
|
117
117
|
*
|
|
118
118
|
* This static method centralizes the logic for converting various types of processed elements
|
|
@@ -163,26 +163,12 @@ return!0}}/**
|
|
|
163
163
|
*/static _functionRenderer(a){var b,c=a.render,d=a.passedTheme;// Invoke the render function to get the child node.
|
|
164
164
|
try{b=c()}catch(a){b=null}// Handle null/undefined
|
|
165
165
|
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,d
|
|
166
|
+
if(Array.isArray(b))return b.map(function(a,b){var c=BaseNode._processRawNode(a,d);return BaseNode._renderProcessedNode(c,d,"".concat(getElementTypeName(a),"-").concat(b))});// Handle React.Component instance
|
|
167
167
|
if(b instanceof React.Component){var e=b.render(),f=BaseNode._processRawNode(e,d);return BaseNode._renderProcessedNode(f,d)}// Handle BaseNode instance or NodeInstance
|
|
168
168
|
if(b instanceof BaseNode||isNodeInstance(b)){var g,h=b;// If nodetheme is missing and passedTheme exists, inject it
|
|
169
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)
|
|
170
170
|
if("string"==typeof b||"number"==typeof b||"boolean"==typeof b)return b;// Process any other result types
|
|
171
171
|
var i=BaseNode._processRawNode(b,d);return i?BaseNode._renderProcessedNode(i,d):b}/**
|
|
172
|
-
* Generates a stable key for a node, especially for elements within an array.
|
|
173
|
-
*
|
|
174
|
-
* If an `existingKey` is provided, it is returned. Otherwise, a key is generated
|
|
175
|
-
* based on the element's type name and its index within a list of siblings.
|
|
176
|
-
* This helps prevent re-rendering issues in React when dealing with dynamic lists.
|
|
177
|
-
* @param options The options for key generation.
|
|
178
|
-
* @param options.nodeIndex The index of the node in an array of children.
|
|
179
|
-
* @param options.element The element for which to generate a key.
|
|
180
|
-
* @param options.existingKey An existing key, if one was already provided.
|
|
181
|
-
* @param options.children The children of the node, used to add complexity to the key.
|
|
182
|
-
* @returns A React key, or `undefined` if no key could be generated.
|
|
183
|
-
* @private
|
|
184
|
-
* @static
|
|
185
|
-
*//**
|
|
186
172
|
* Processes a single raw node, recursively converting it into a `BaseNode` or other renderable type.
|
|
187
173
|
*
|
|
188
174
|
* This is a central method for normalizing children. It handles various types of input:
|
|
@@ -192,37 +178,27 @@ var i=BaseNode._processRawNode(b,d);return i?BaseNode._renderProcessedNode(i,d):
|
|
|
192
178
|
* - **Valid React Elements**: Converts them into `BaseNode` instances, extracting props and propagating the theme.
|
|
193
179
|
* - **React Component Types**: Wraps them in a `BaseNode` with the parent theme.
|
|
194
180
|
* - **React Component Instances**: Renders them and processes the output recursively.
|
|
195
|
-
*
|
|
196
|
-
* It also generates a stable key for elements within an array if one is not provided.
|
|
197
181
|
* @param node The raw child node to process.
|
|
198
182
|
* @param passedTheme The theme inherited from the parent.
|
|
199
|
-
* @param nodeIndex The index of the child if it is in an array, used for key generation.
|
|
200
183
|
* @returns A processed `NodeElement` (typically a `BaseNode` instance or a primitive).
|
|
201
184
|
* @private
|
|
202
185
|
* @static
|
|
203
|
-
*/static _processRawNode(a,b
|
|
204
|
-
){var d=getComponentType(a);// Determine the type of the raw node
|
|
186
|
+
*/static _processRawNode(a,b){var c=getComponentType(a);// Determine the type of the raw node
|
|
205
187
|
// Case 1: Child is already a BaseNode instance
|
|
206
|
-
if(a instanceof BaseNode||isNodeInstance(a)){var
|
|
188
|
+
if(a instanceof BaseNode||isNodeInstance(a)){var d=a.rawProps||{},e=d.theme||d.nodetheme||b;// Get initial raw props of the child
|
|
207
189
|
// Prefer child's own theme
|
|
208
190
|
// Check if we can reuse the existing node
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
key:g}));// Create a new BaseNode with merged props and theme
|
|
191
|
+
return d.nodetheme===e&&void 0!==d.key?a:new BaseNode(a.element,_objectSpread(_objectSpread({},d),{},{nodetheme:e// Use the determined theme for the new node
|
|
192
|
+
}));// Create a new BaseNode with merged props and theme
|
|
212
193
|
}// Case 2: Child is a primitive (string, number, boolean, null, undefined)
|
|
213
|
-
if("string"===
|
|
214
|
-
if(BaseNode._isFunctionChild(a)){
|
|
215
|
-
//
|
|
216
|
-
|
|
217
|
-
return new BaseNode(
|
|
218
|
-
|
|
219
|
-
if(
|
|
220
|
-
return
|
|
221
|
-
key:p})}// Case 6: Handle instances of React.Component
|
|
222
|
-
if(a instanceof React.Component){var q=a.render();// Recursively process the rendered element with a parent theme and index if available
|
|
223
|
-
return BaseNode._processRawNode(q,b,c)}// Case 7: Fallback for other ReactNode types (e.g., Fragments, Portals if not caught by isValidElement)
|
|
224
|
-
// These are returned as-is. If they are elements within an array, React expects them to have keys.
|
|
225
|
-
// This logic primarily adds keys to BaseNode instances we create, other ReactNodes are returned as-is.
|
|
194
|
+
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).
|
|
195
|
+
if(BaseNode._isFunctionChild(a))return new BaseNode(BaseNode._functionRenderer,{render:a,passedTheme:b});// Case 4: Child is a React Element (JSX element like <div> or <MyComponent>)
|
|
196
|
+
if(isValidElement(a)){var f=a.props,g=f.style,h=_objectWithoutProperties(f,_excluded4),i=_objectSpread(_objectSpread({},h),g||{}),j=i.theme||i.nodetheme||b;return new BaseNode(a.type,_objectSpread(_objectSpread({},i),{},{nodetheme:j}))}// Case 5: Child is an ElementType (string tag, class component, Memo/ForwardRef)
|
|
197
|
+
if(isReactClassComponent(a)||"object"===c&&(isMemo(a)||isForwardRef(a)))// ElementTypes don't have an intrinsic key from the node itself.
|
|
198
|
+
return new BaseNode(a,{nodetheme:b// Apply parent theme
|
|
199
|
+
});// Case 6: Handle instances of React.Component
|
|
200
|
+
if(a instanceof React.Component){var k=a.render();// Recursively process the rendered element with a parent theme and index if available
|
|
201
|
+
return BaseNode._processRawNode(k,b)}// Case 7: Fallback for other ReactNode types (e.g., Fragments, Portals if not caught by isValidElement)
|
|
226
202
|
return a}/**
|
|
227
203
|
* Renders the `BaseNode` into a `ReactElement`.
|
|
228
204
|
*
|
|
@@ -231,22 +207,22 @@ return a}/**
|
|
|
231
207
|
* 1. Validating that the node's `element` type is renderable.
|
|
232
208
|
* 2. Normalizing processed children into `ReactNode`s using `_normalizeChild`.
|
|
233
209
|
* 3. Caching normalized children to avoid re-processing on subsequent renders.
|
|
234
|
-
* 4. Assembling the final props, including `
|
|
210
|
+
* 4. Assembling the final props, including `style`, and other attributes.
|
|
235
211
|
* 5. If the element has a `css` prop, it may be wrapped in a `StyledRenderer` to handle
|
|
236
212
|
* CSS-in-JS styling.
|
|
237
213
|
* 6. Finally, calling `React.createElement` with the element, props, and children.
|
|
238
214
|
* @returns The rendered `ReactElement`.
|
|
239
215
|
* @throws {Error} If the node's `element` is not a valid React element type.
|
|
240
216
|
*/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.
|
|
242
|
-
if(this.element===Fragment||isFragment(this.element))return createElement(this.element
|
|
217
|
+
var c=this.props,d=c.children,e=c.css,f=c.nativeProps,g=_objectWithoutProperties(c,_excluded5),h=void 0;if(d!==void 0&&null!==d){if(!this._normalizedChildren||this._childrenHash!==createStableHash(d,this.props.nodetheme||this.props.theme))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
|
|
218
|
+
if(this.element===Fragment||isFragment(this.element))return createElement(this.element,...(Array.isArray(h)?h:[h]));// If the element has a `css` prop and has style tag, render using the `StyledRenderer` component
|
|
243
219
|
// This enables emotion-based style handling for the element
|
|
244
|
-
if(this.element&&!hasNoStyleTag(this.element)&&
|
|
220
|
+
if(this.element&&!hasNoStyleTag(this.element)&&e){// Set displayName for easier debugging in React DevTools
|
|
245
221
|
try{var j=getElementTypeName(this.element);StyledRenderer.displayName="Styled(".concat(j,")")}catch(a){// swallow: displayName is not critical
|
|
246
|
-
}return createElement(StyledRenderer,_objectSpread(_objectSpread({element:this.element},g),{},{
|
|
222
|
+
}return createElement(StyledRenderer,_objectSpread(_objectSpread({element:this.element},g),{},{css:e,suppressHydrationWarning:!0},f),...(Array.isArray(h)?h:[h]))}// For other elements, create the React element directly
|
|
247
223
|
// Set displayName for easier debugging in React DevTools
|
|
248
224
|
try{this.element.displayName=getElementTypeName(this.element)}catch(a){// swallow: displayName is not critical
|
|
249
|
-
}return createElement(this.element,_objectSpread(_objectSpread({},g),
|
|
225
|
+
}return createElement(this.element,_objectSpread(_objectSpread({},g),f),...(Array.isArray(h)?h:[h]))}/**
|
|
250
226
|
* Ensures the necessary DOM elements for portal rendering are created and attached.
|
|
251
227
|
*
|
|
252
228
|
* On the client-side, this method checks for or creates a `div` element appended
|
|
@@ -293,7 +269,7 @@ return this._portalReactRoot}}}/**
|
|
|
293
269
|
* @param props The props for the node (optional).
|
|
294
270
|
* @param additionalProps Additional props to merge into the node (optional).
|
|
295
271
|
* @returns A new `BaseNode` instance as a `NodeInstance<E>`.
|
|
296
|
-
*/_defineProperty(BaseNode,"_isServer","undefined"==typeof window),_defineProperty(BaseNode,"_processedChildrenWeakCache",new WeakMap),_defineProperty(BaseNode,"_processedChildrenMapCache",new Map),_defineProperty(BaseNode,"_MAX_PROCESSED_CHILDREN_CACHE",1e3)
|
|
272
|
+
*/_defineProperty(BaseNode,"_isServer","undefined"==typeof window),_defineProperty(BaseNode,"_processedChildrenWeakCache",new WeakMap),_defineProperty(BaseNode,"_processedChildrenMapCache",new Map),_defineProperty(BaseNode,"_MAX_PROCESSED_CHILDREN_CACHE",1e3);export function Node(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},d=_objectSpread(_objectSpread({},b),c);return d.theme&&!d.nodetheme&&(d.nodetheme=d.theme),new BaseNode(a,d)}/**
|
|
297
273
|
* Creates a curried node factory for a given React element or component type.
|
|
298
274
|
*
|
|
299
275
|
* Returns a function that, when called with props, produces a `NodeInstance<E>`.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meonode/ui",
|
|
3
3
|
"description": "A structured approach to component composition, direct CSS-first prop styling, built-in theming, smart prop handling (including raw property pass-through), and dynamic children.",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.22",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/main.js",
|
|
7
7
|
"types": "./dist/main.d.ts",
|