@meonode/ui 0.1.13 → 0.1.14
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/README.md +97 -60
- package/dist/core.node.d.ts +2 -0
- package/dist/core.node.d.ts.map +1 -1
- package/dist/core.node.js +14 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -164,129 +164,166 @@ const Dashboard = Component(() =>
|
|
|
164
164
|
### With Conditional Children That Contains Hook
|
|
165
165
|
|
|
166
166
|
```ts
|
|
167
|
-
// Wraps a hook-capable component into a BaseNode-compatible Client Component
|
|
168
167
|
'use client'
|
|
169
168
|
/**
|
|
170
169
|
* This file demonstrates integration between React hooks and BaseNode components
|
|
171
|
-
* using the @meonode/ui library for declarative UI construction
|
|
170
|
+
* using the @meonode/ui library for declarative UI construction.
|
|
171
|
+
* It explores various rendering patterns, Higher-Order Component (HOC) usage,
|
|
172
|
+
* and theme propagation with @meonode/ui components.
|
|
172
173
|
*/
|
|
173
|
-
import { Component, Column, Row, Div, P, Node } from '@meonode/ui'
|
|
174
|
+
import { Component, Column, Row, Div, P, Node } from '@meonode/ui' // Theme type is not explicitly imported or used as a prop type in this file's components.
|
|
174
175
|
import { useState, useEffect } from 'react'
|
|
176
|
+
import { CssBaseline, TextField } from '@meonode/mui'
|
|
175
177
|
|
|
176
178
|
/**
|
|
177
|
-
* Global theme configuration
|
|
178
|
-
* Contains color palette definitions used
|
|
179
|
-
*
|
|
179
|
+
* Global theme configuration.
|
|
180
|
+
* Contains color palette definitions used by @meonode/ui components
|
|
181
|
+
* when they resolve theme strings from context.
|
|
182
|
+
* This can be extracted to a separate theme file for larger applications.
|
|
180
183
|
*/
|
|
181
184
|
const theme = {
|
|
182
185
|
background: { primary: 'lightgreen', secondary: 'lightyellow' },
|
|
183
186
|
}
|
|
184
187
|
|
|
185
188
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
189
|
+
* The page's main logic is defined as a function (which may use React hooks).
|
|
190
|
+
* This function is wrapped in the `Component` HOC from @meonode/ui.
|
|
191
|
+
* The HOC standardizes it as a React component, ensuring it returns a ReactNode.
|
|
192
|
+
* This makes the component compatible with React's rendering process,
|
|
193
|
+
* supporting both client-side and server-side rendering.
|
|
188
194
|
*/
|
|
189
195
|
export default Component(() => {
|
|
190
|
-
//
|
|
191
|
-
const [
|
|
196
|
+
// State hook to control the visibility of additional content sections.
|
|
197
|
+
const [showMore, setShowDetails] = useState(false) // 'showMore' controls visibility, 'setShowDetails' is the updater.
|
|
192
198
|
|
|
193
199
|
/**
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* -
|
|
200
|
+
* The main layout is structured as a Column.
|
|
201
|
+
* It includes:
|
|
202
|
+
* - A header row with a button to toggle the visibility of additional content.
|
|
203
|
+
* - A series of examples demonstrating different ways to render detail components,
|
|
204
|
+
* both unconditionally and conditionally, highlighting theme propagation.
|
|
197
205
|
*/
|
|
198
206
|
return Column({
|
|
199
|
-
theme,
|
|
207
|
+
theme, // Provide the global theme to the Column and its descendants via React context.
|
|
200
208
|
padding: 20,
|
|
201
209
|
gap: 15,
|
|
202
210
|
children: [
|
|
203
|
-
//
|
|
211
|
+
CssBaseline, // Applies baseline MUI styles.
|
|
212
|
+
// Interactive header section for toggling more content.
|
|
204
213
|
Row({
|
|
205
214
|
gap: 10,
|
|
206
215
|
children: [
|
|
207
216
|
Div({
|
|
208
|
-
onClick: () => setShowDetails(prev => !prev), //
|
|
209
|
-
cursor: 'pointer',
|
|
210
|
-
userSelect: 'none', //
|
|
217
|
+
onClick: () => setShowDetails(prev => !prev), // Click handler to toggle the 'showMore' state.
|
|
218
|
+
cursor: 'pointer', // Visual cue for clickability.
|
|
219
|
+
userSelect: 'none', // Prevents text selection on the button.
|
|
211
220
|
padding: '10px 20px',
|
|
212
|
-
backgroundColor: 'theme.background.primary', //
|
|
221
|
+
backgroundColor: 'theme.background.primary', // Background color sourced from the theme context.
|
|
213
222
|
borderRadius: 5,
|
|
214
223
|
fontWeight: 'bold',
|
|
215
|
-
children:
|
|
224
|
+
children: showMore ? 'Hide' : 'Show More', // Dynamically sets button text based on 'showMore' state.
|
|
216
225
|
}),
|
|
217
226
|
],
|
|
218
227
|
}),
|
|
219
228
|
|
|
220
229
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* 4. Non-working example with raw Node usage
|
|
230
|
+
* Unconditional rendering examples:
|
|
231
|
+
* Demonstrates rendering DetailComponent (returns a @meonode/ui Node instance) and
|
|
232
|
+
* ReturnRenderedDetailComponent (returns a ReactNode), and usage of the Node HOC.
|
|
233
|
+
* Pay attention to how theme is (or isn't) propagated to these components.
|
|
226
234
|
*/
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
235
|
+
DetailComponent({ info: 'Here are some details 1!' }), // Renders DetailComponent; its internal Row sources theme from parent Column's context.
|
|
236
|
+
DetailComponent({ info: 'Here are some details 2!' }).render(), // Renders DetailComponent (invoking .render()); its internal Row sources theme from parent Column's context.
|
|
237
|
+
// Node(DetailComponent, { info: 'Here are some details 3!' }), // ❌ Fails: Node HOC expects its first argument (a component function) to return ReactNode. DetailComponent returns a @meonode/ui Node instance.
|
|
238
|
+
|
|
239
|
+
ReturnRenderedDetailComponent({ info: 'Here are some details 4!' }), // Renders ReturnRenderedDetailComponent; its internal Row inherits theme from parent Column's context.
|
|
240
|
+
Node(ReturnRenderedDetailComponent, { info: 'Here are some details 5!' }), // Node HOC with a function returning ReactNode: Renders. Theme from Column is NOT propagated by Node HOC to the internal Row.
|
|
241
|
+
Node(ReturnRenderedDetailComponent, { info: 'Here are some details 6!' }).render(), // Node HOC (then .render()): Renders. Theme from Column is NOT propagated by Node HOC to the internal Row.
|
|
242
|
+
// Node(DetailComponent, { info: 'Here are some details 7!' }).render(), // ❌ Fails: Same reason as above; Node HOC expects a function returning ReactNode.
|
|
230
243
|
|
|
231
|
-
|
|
232
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Conditional rendering examples (shown when 'showMore' is true):
|
|
246
|
+
* These demonstrate various wrapping techniques (inline functions, Component HOC)
|
|
247
|
+
* and their effect on rendering and theme propagation for both types of detail components.
|
|
248
|
+
*/
|
|
249
|
+
showMore && (() => DetailComponent({ info: 'Here are some details 8!' })), // Method 1 (inline function wrapper): Renders DetailComponent; its internal Row sources theme from context.
|
|
250
|
+
showMore && (() => DetailComponent({ info: 'Here are some details 9!' }).render()), // Method 2 (inline function wrapper + .render()): Renders DetailComponent; its internal Row sources theme from context.
|
|
251
|
+
showMore && Component(() => DetailComponent({ info: 'Here are some details 10!' })), // Method 3 (Component HOC wrapper): Renders DetailComponent; its internal Row sources theme from context.
|
|
252
|
+
|
|
253
|
+
showMore && (() => ReturnRenderedDetailComponent({ info: 'Here are some details 12!' })), // Method 4 (inline function wrapper): Renders ReturnRenderedDetailComponent; internal Row inherits theme from Column's context.
|
|
254
|
+
showMore && Component(() => ReturnRenderedDetailComponent({ info: 'Here are some details 13!' })), // Method 5 (Component HOC wrapper): Renders ReturnRenderedDetailComponent; internal Row inherits theme from Column's context.
|
|
255
|
+
showMore && Node(ReturnRenderedDetailComponent, { info: 'Here are some details 14!' }).render(), // Method 6 (Node HOC + .render()): Renders. Theme from Column is NOT propagated by Node HOC to internal Row.
|
|
256
|
+
// showMore && ReturnRenderedDetailComponent({ info: 'Here are some details 15!' }), // ❌ Fails: Direct call to a component function using hooks (ReturnRenderedDetailComponent) inside render logic without a React-aware wrapper. This can violate Rules of Hooks.
|
|
233
257
|
],
|
|
234
258
|
})
|
|
235
259
|
})
|
|
236
260
|
|
|
237
261
|
/**
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
* @
|
|
262
|
+
* A component that displays a styled detail section.
|
|
263
|
+
* It uses `useEffect` for lifecycle logging. The internal `Row` component
|
|
264
|
+
* sources its theme from the React context established by an ancestor
|
|
265
|
+
* @meonode/ui component (e.g., the main Column in this page).
|
|
266
|
+
* This component returns a @meonode/ui `Row` Node instance.
|
|
267
|
+
*
|
|
268
|
+
* @param {object} props - Component properties.
|
|
269
|
+
* @param {string} props.info - Text content to display in the detail section.
|
|
270
|
+
* @returns {import('@meonode/ui').Node} A @meonode/ui Row Node instance.
|
|
242
271
|
*/
|
|
243
272
|
const DetailComponent = ({ info }: { info: string }) => {
|
|
244
|
-
//
|
|
273
|
+
// useEffect hook for logging component mount and unmount phases (for debugging).
|
|
245
274
|
useEffect(() => {
|
|
246
|
-
console.log('DetailComponent mounted')
|
|
275
|
+
console.log('DetailComponent mounted:', info) // Example mount log
|
|
247
276
|
return () => {
|
|
248
|
-
console.log('DetailComponent unmounted')
|
|
277
|
+
console.log('DetailComponent unmounted:', info) // Example unmount log
|
|
249
278
|
}
|
|
250
|
-
}, [])
|
|
279
|
+
}, [info]) // Effect depends on 'info' prop.
|
|
251
280
|
|
|
252
|
-
//
|
|
253
|
-
|
|
254
|
-
|
|
281
|
+
// Returns a @meonode/ui Row component configured with props and children.
|
|
282
|
+
// Its styling (e.g., backgroundColor) will resolve theme strings from React context.
|
|
283
|
+
return Row({
|
|
284
|
+
gap: 10,
|
|
285
|
+
padding: 4,
|
|
255
286
|
border: '1px solid green',
|
|
256
287
|
borderRadius: 6,
|
|
257
288
|
color: 'red',
|
|
258
|
-
backgroundColor: 'theme.background.secondary', //
|
|
259
|
-
children: P(info),
|
|
289
|
+
backgroundColor: 'theme.background.secondary', // Background color sourced from theme in React context.
|
|
290
|
+
children: [P(info), TextField({ background: 'theme.background.primary' })],
|
|
260
291
|
})
|
|
261
292
|
}
|
|
262
293
|
|
|
263
294
|
/**
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
295
|
+
* An alternative detail component implementation that explicitly calls `.render()`
|
|
296
|
+
* to return a `ReactNode` (a rendered React element) directly.
|
|
297
|
+
* This makes it compatible with wrappers like the `Node` HOC that expect a function returning `ReactNode`.
|
|
298
|
+
* It uses `useEffect` for lifecycle logging. The internal `Row` sources its
|
|
299
|
+
* theme from React context.
|
|
300
|
+
*
|
|
301
|
+
* @param {object} props - Component properties.
|
|
302
|
+
* @param {string} props.info - Text content to display.
|
|
303
|
+
* @returns {React.ReactNode} A rendered React element (the result of `Row(...).render()`).
|
|
269
304
|
*/
|
|
270
305
|
const ReturnRenderedDetailComponent = ({ info }: { info: string }) => {
|
|
271
|
-
//
|
|
306
|
+
// useEffect hook for logging component mount and unmount phases (for debugging).
|
|
272
307
|
useEffect(() => {
|
|
273
|
-
console.log('
|
|
308
|
+
console.log('ReturnRenderedDetailComponent mounted:', info) // Example mount log
|
|
274
309
|
return () => {
|
|
275
|
-
console.log('
|
|
310
|
+
console.log('ReturnRenderedDetailComponent unmounted:', info) // Example unmount log
|
|
276
311
|
}
|
|
277
|
-
}, [])
|
|
278
|
-
|
|
279
|
-
//
|
|
280
|
-
|
|
281
|
-
|
|
312
|
+
}, [info]) // Effect depends on 'info' prop.
|
|
313
|
+
|
|
314
|
+
// Constructs a @meonode/ui Row and immediately calls .render() on it.
|
|
315
|
+
// The Row itself will attempt to resolve theme strings (e.g., 'theme.background.secondary')
|
|
316
|
+
// from the React context provided by an ancestor @meonode/ui component (like the main Column).
|
|
317
|
+
return Row({
|
|
318
|
+
gap: 10,
|
|
319
|
+
padding: 4,
|
|
282
320
|
border: '1px solid green',
|
|
283
321
|
borderRadius: 6,
|
|
284
322
|
color: 'red',
|
|
285
|
-
backgroundColor: 'theme.background.secondary', // Theme-aware background
|
|
286
|
-
children: P(info),
|
|
287
|
-
}).render()
|
|
323
|
+
backgroundColor: 'theme.background.secondary', // Theme-aware background; relies on theme from React context.
|
|
324
|
+
children: [P(info), TextField({ background: 'theme.background.primary' })],
|
|
325
|
+
}).render() // Explicitly renders to ReactNode.
|
|
288
326
|
}
|
|
289
|
-
|
|
290
327
|
```
|
|
291
328
|
|
|
292
329
|
### Material UI Integration
|
package/dist/core.node.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare function Node<E extends NodeElement>(element: E, props?: Partial<
|
|
|
20
20
|
* @param component Component function that returns a BaseNode or ReactNode
|
|
21
21
|
* @returns A React function component that handles BaseNode conversion and theme propagation
|
|
22
22
|
* @example
|
|
23
|
+
* ```ts
|
|
23
24
|
* // Basic usage
|
|
24
25
|
* const Button = Component((props) => {
|
|
25
26
|
* return Node('button', {
|
|
@@ -27,6 +28,7 @@ export declare function Node<E extends NodeElement>(element: E, props?: Partial<
|
|
|
27
28
|
* theme: { color: 'blue' }
|
|
28
29
|
* })
|
|
29
30
|
* })
|
|
31
|
+
* ```
|
|
30
32
|
*/
|
|
31
33
|
export declare function Component<T extends Record<string, any> & {
|
|
32
34
|
theme?: Theme;
|
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,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
|
|
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;;;;;;;;;;;;;;;;;;;;;;GAsBG;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
|
@@ -14,7 +14,7 @@ if(!isValidElementType(a)){var g=getComponentType(a);throw new Error("Invalid el
|
|
|
14
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
15
|
// 1. Resolve styles and DOM props for this node
|
|
16
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
|
|
17
|
+
// 2. Process rawNoderen into BaseNode instances or primitives, passing down the currentTheme
|
|
18
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
|
|
19
19
|
)}else// For a single child, no index is passed; existing key logic in _processRawNode will apply
|
|
20
20
|
k=this._processRawNode(e,f);// 3. Construct final this.props
|
|
@@ -29,9 +29,9 @@ this.props=_objectSpread(_objectSpread({},j),{},{style:i,nodeTheme:f,children:k/
|
|
|
29
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
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
31
|
h=h.replace(/theme\.([a-zA-Z0-9_.-]+)/g,function(a,b){var c=getValueByPath(d,b);// Use 'theme' passed to the function
|
|
32
|
-
// Replace if themeValue is found and is a string or number.
|
|
32
|
+
// Replace it if themeValue is found and is a string or number.
|
|
33
33
|
// null is explicitly excluded to avoid 'null' string in output unless intended.
|
|
34
|
-
return void 0!==c&&null!==c&&("string"==typeof c||"number"==typeof c)?c+"":a;// If themeValue is not a string
|
|
34
|
+
return void 0!==c&&null!==c&&("string"==typeof c||"number"==typeof c)?c+"":a;// If themeValue is not a string or number or is undefined/null, keep the original placeholder
|
|
35
35
|
}),e[f]=h}}return e}/**
|
|
36
36
|
* React component that renders the result of a function child, supporting theme propagation.
|
|
37
37
|
*
|
|
@@ -48,7 +48,7 @@ if(f instanceof React.Component){var g=f.render(),h=e(g,c);return h instanceof B
|
|
|
48
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
|
|
49
49
|
key:d})).render():j.render();// If the node already has a theme or no theme is provided, render as-is.
|
|
50
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
|
|
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 an existing key or passed key
|
|
52
52
|
})).render()}return k.render()}// If the result is not a BaseNode (e.g., JSX, string, etc.), return it directly.
|
|
53
53
|
// Note: Non-BaseNode results will not automatically receive the theme.
|
|
54
54
|
return f}/**
|
|
@@ -78,16 +78,16 @@ var j=e(this._functionRenderer,void 0);// Generate key for function renderer
|
|
|
78
78
|
return new BaseNode(this._functionRenderer,{processRawNode:this._processRawNode.bind(this),render:a,passedTheme:b,key:j// Assign the generated key
|
|
79
79
|
})}// Case 4: Child is a React Element (JSX element like <div> or <MyComponent>)
|
|
80
80
|
if(isValidElement(a)){var k,l=_objectSpread({},a.props);// Extract and merge props from the JSX element, flattening style props
|
|
81
|
-
l=_objectSpread(_objectSpread({},l.style),l),delete l.style;// Remove original style object after merging
|
|
82
|
-
// Handle theme: prefer nodeTheme from child's props, fallback to parent theme
|
|
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
|
|
84
|
-
// Create new BaseNode instance with processed props and theme
|
|
81
|
+
l=_objectSpread(_objectSpread({},l.style),l),delete l.style;// Remove the original style object after merging
|
|
82
|
+
// Handle theme: prefer nodeTheme from child's props, fallback to the parent theme
|
|
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 a stable key from element type and index
|
|
84
|
+
// Create a new BaseNode instance with processed props and theme
|
|
85
85
|
return new BaseNode(a.type,_objectSpread(_objectSpread({},l),{},{nodeTheme:m,key:n// Assign the generated key
|
|
86
86
|
}))}// Case 5: Child is an ElementType (string tag, class component, Memo/ForwardRef)
|
|
87
87
|
if(isReactClassComponent(a)||"object"===d&&(isMemo(a)||isForwardRef(a))){// ElementTypes don't have an intrinsic key from the rawNode itself.
|
|
88
88
|
var o=e(a,void 0);return new BaseNode(a,{nodeTheme:b,// Apply parent theme
|
|
89
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
|
|
90
|
+
if(a instanceof React.Component){var p=a.render();// Recursively process the rendered element with a parent theme and index if available
|
|
91
91
|
return this._processRawNode(p,b,c)}// Case 7: Fallback for other ReactNode types (e.g., Fragments, Portals if not caught by isValidElement)
|
|
92
92
|
// These are returned as-is. If they are elements within an array, React expects them to have keys.
|
|
93
93
|
// This logic primarily adds keys to BaseNode instances we create, other ReactNodes are returned as-is.
|
|
@@ -111,12 +111,12 @@ return a}/**
|
|
|
111
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
112
|
// More accurate type
|
|
113
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
|
|
114
|
+
// Check if all children are null/undefined (e.g., conditional rendering resulted in nothing)
|
|
115
115
|
f=g.every(function(a){return null===a||void 0===a})?void 0:g}else f=void 0;// Prepare props for React.createElement
|
|
116
116
|
var h=_objectSpread(_objectSpread({},e),{},{// Cast otherProps
|
|
117
117
|
key:d// This is the key of the current BaseNode itself
|
|
118
118
|
});// Prepare props for React.createElement
|
|
119
|
-
// Delete key `nodeTheme` as it's not a valid DOM/React prop for the element
|
|
119
|
+
// Delete the key `nodeTheme` as it's not a valid DOM/React prop for the element
|
|
120
120
|
return delete h.nodeTheme,createElement(this.element,h,f)}}])}();/**
|
|
121
121
|
* Factory function to create a BaseNode instance.
|
|
122
122
|
* @param element The React element type.
|
|
@@ -138,6 +138,7 @@ return c.theme&&void 0===c.nodeTheme&&(c.nodeTheme=c.theme),new BaseNode(a,c)}/*
|
|
|
138
138
|
* @param component Component function that returns a BaseNode or ReactNode
|
|
139
139
|
* @returns A React function component that handles BaseNode conversion and theme propagation
|
|
140
140
|
* @example
|
|
141
|
+
* ```ts
|
|
141
142
|
* // Basic usage
|
|
142
143
|
* const Button = Component((props) => {
|
|
143
144
|
* return Node('button', {
|
|
@@ -145,7 +146,8 @@ return c.theme&&void 0===c.nodeTheme&&(c.nodeTheme=c.theme),new BaseNode(a,c)}/*
|
|
|
145
146
|
* theme: { color: 'blue' }
|
|
146
147
|
* })
|
|
147
148
|
* })
|
|
148
|
-
|
|
149
|
+
* ```
|
|
150
|
+
*/export function Component(a){// Create a wrapper component that handles theme and rendering
|
|
149
151
|
return function(){var b=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},c=a(_objectSpread({},b));// Execute wrapped component
|
|
150
152
|
// Handle BaseNode results - requires special processing
|
|
151
153
|
if(c instanceof BaseNode){var d,e;// Theme merging: Check if we need to handle theme inheritance
|
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.14",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/main.js",
|
|
7
7
|
"types": "./dist/main.d.ts",
|