@meonode/ui 0.3.4 → 0.3.5
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 +4 -163
- package/dist/core.node.d.ts.map +1 -1
- package/dist/core.node.js +30 -242
- package/package.json +1 -1
package/dist/core.node.d.ts
CHANGED
|
@@ -27,202 +27,59 @@ export declare class BaseNode<E extends NodeElementType> implements NodeInstance
|
|
|
27
27
|
private static _isServer;
|
|
28
28
|
/**
|
|
29
29
|
* Constructs a new BaseNode instance.
|
|
30
|
-
*
|
|
31
|
-
* This constructor initializes a node with a given React element or component type
|
|
32
|
-
* and the raw props passed to it. The props are not processed until they are
|
|
33
|
-
* accessed via the `props` getter, allowing for lazy evaluation.
|
|
34
|
-
* @param element The React element or component type this node will represent.
|
|
35
|
-
* @param rawProps The initial, unprocessed props for the element.
|
|
36
30
|
*/
|
|
37
31
|
constructor(element: E, rawProps?: Partial<NodeProps<E>>);
|
|
38
32
|
/**
|
|
39
33
|
* Lazily processes and retrieves the final, normalized props for the node.
|
|
40
|
-
*
|
|
41
|
-
* The first time this getter is accessed, it triggers `_processProps` to resolve
|
|
42
|
-
* styles, and children. Subsequent accesses return the cached result
|
|
43
|
-
* until the node is cloned or recreated.
|
|
44
|
-
* @returns The fully processed and normalized `FinalNodeProps`.
|
|
45
34
|
*/
|
|
46
35
|
get props(): FinalNodeProps;
|
|
47
36
|
/**
|
|
48
37
|
* 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
|
|
54
|
-
* @private
|
|
55
|
-
* @returns The processed `FinalNodeProps` ready for rendering.
|
|
56
38
|
*/
|
|
57
39
|
private _processProps;
|
|
58
40
|
/**
|
|
59
41
|
* Recursively processes raw children, converting them into `BaseNode` instances as needed.
|
|
60
|
-
*
|
|
61
|
-
* This method ensures consistent handling for all children.
|
|
62
|
-
*
|
|
63
|
-
* - If `children` is an array, each child is processed individually.
|
|
64
|
-
* - If `children` is a single node, it is processed directly.
|
|
65
|
-
* @param children The raw child or array of children to process.
|
|
66
|
-
* @returns The processed children, ready for normalization and rendering.
|
|
67
|
-
* @private
|
|
68
42
|
*/
|
|
69
43
|
private _processChildren;
|
|
70
44
|
/**
|
|
71
|
-
* Renders a processed `NodeElement` into a `ReactNode
|
|
72
|
-
*
|
|
73
|
-
* This static method centralizes the logic for converting various types of processed elements
|
|
74
|
-
* into renderable React nodes. It handles:
|
|
75
|
-
* - `BaseNode` instances: Re-wraps them to apply a new key.
|
|
76
|
-
* - React class components: Wraps them in a new `BaseNode`.
|
|
77
|
-
* - `NodeInstance` objects: Invokes their `render()` method.
|
|
78
|
-
* - React component instances: Invokes their `render()` method.
|
|
79
|
-
* - Functional components: Creates a React element from them.
|
|
80
|
-
* - Other valid `ReactNode` types (strings, numbers, etc.): Returns them as-is.
|
|
81
|
-
* @param processedElement The node element to render.
|
|
82
|
-
* @param passedKey The React key to assign.
|
|
83
|
-
* @returns A renderable `ReactNode`.
|
|
84
|
-
* @private
|
|
85
|
-
* @static
|
|
45
|
+
* Renders a processed `NodeElement` into a `ReactNode`.
|
|
86
46
|
*/
|
|
87
47
|
private static _renderProcessedNode;
|
|
88
48
|
/**
|
|
89
|
-
*
|
|
90
|
-
* @param node The node to render.
|
|
91
|
-
* @private
|
|
92
|
-
* @static
|
|
93
|
-
* @example
|
|
94
|
-
* ```typescript
|
|
95
|
-
* const myNode = Node('div', { children: [ () => 'Hello' ] });
|
|
96
|
-
* ```
|
|
49
|
+
* Checks if a node is a function child (render prop style).
|
|
97
50
|
*/
|
|
98
51
|
private static _isFunctionChild;
|
|
99
52
|
/**
|
|
100
53
|
* Renders the output of a function-as-a-child.
|
|
101
|
-
*
|
|
102
|
-
* This method is designed to handle "render prop" style children (`() => ReactNode`).
|
|
103
|
-
* It invokes the function and processes its result.
|
|
104
|
-
* @param props The properties for the function renderer.
|
|
105
|
-
* @param props.render The function to execute to get the child content.
|
|
106
|
-
* @returns The rendered `ReactNode`.
|
|
107
|
-
* @private
|
|
108
54
|
*/
|
|
109
55
|
private static _functionRenderer;
|
|
110
|
-
/**
|
|
111
|
-
* Generates a stable key for a node, especially for elements within an array.
|
|
112
|
-
*
|
|
113
|
-
* If an `existingKey` is provided, it is returned. Otherwise, a key is generated
|
|
114
|
-
* based on the element's type name and its index within a list of siblings.
|
|
115
|
-
* This helps prevent re-rendering issues in React when dealing with dynamic lists.
|
|
116
|
-
* @param options The options for key generation.
|
|
117
|
-
* @param options.nodeIndex The index of the node in an array of children.
|
|
118
|
-
* @param options.element The element for which to generate a key.
|
|
119
|
-
* @param options.existingKey An existing key, if one was already provided.
|
|
120
|
-
* @param options.children The children of the node, used to add complexity to the key.
|
|
121
|
-
* @returns A React key, or `undefined` if no key could be generated.
|
|
122
|
-
* @private
|
|
123
|
-
* @static
|
|
124
|
-
*/
|
|
125
|
-
private static _generateKey;
|
|
126
56
|
/**
|
|
127
57
|
* Processes a single raw node, recursively converting it into a `BaseNode` or other renderable type.
|
|
128
|
-
*
|
|
129
|
-
* This is a central method for normalizing children. It handles various types of input:
|
|
130
|
-
* - **`BaseNode` instances**: Re-creates them to ensure the correct key is applied.
|
|
131
|
-
* - **Primitives**: Returns strings, numbers, booleans, null, and undefined as-is.
|
|
132
|
-
* - **Functions (Render Props)**: Wraps them in a `BaseNode` that uses `_functionRenderer` to delay execution.
|
|
133
|
-
* - **Valid React Elements**: Converts them into `BaseNode` instances, extracting props.
|
|
134
|
-
* - **React Component Types**: Wraps them in a `BaseNode`.
|
|
135
|
-
* - **React Component Instances**: Renders them and processes the output recursively.
|
|
136
|
-
*
|
|
137
|
-
* It also generates a stable key for elements within an array if one is not provided.
|
|
138
|
-
* @param node The raw child node to process.
|
|
139
|
-
* @param nodeIndex The index of the child if it is in an array, used for key generation.
|
|
140
|
-
* @returns A processed `NodeElement` (typically a `BaseNode` instance or a primitive).
|
|
141
|
-
* @private
|
|
142
|
-
* @static
|
|
143
58
|
*/
|
|
144
59
|
private static _processRawNode;
|
|
145
60
|
/**
|
|
146
61
|
* Normalizes a processed child node into a final, renderable `ReactNode`.
|
|
147
|
-
*
|
|
148
|
-
* This method is called during the `render` phase. It takes a child that has already
|
|
149
|
-
* been processed by `_processChildren` and prepares it for `React.createElement`.
|
|
150
|
-
*
|
|
151
|
-
* - For `BaseNode` instances, it calls their `render()` method.
|
|
152
|
-
* - It validates that other children are valid React element types.
|
|
153
|
-
* - Primitives and other valid nodes are returned as-is.
|
|
154
|
-
* @param child The processed child node to normalize.
|
|
155
|
-
* @returns A renderable `ReactNode`.
|
|
156
|
-
* @throws {Error} If the child is not a valid React element type.
|
|
157
|
-
* @private
|
|
158
62
|
*/
|
|
159
63
|
private _normalizeChild;
|
|
160
64
|
/**
|
|
161
65
|
* Renders the `BaseNode` into a `ReactElement`.
|
|
162
|
-
*
|
|
163
|
-
* This method is the final step in the rendering pipeline. It constructs a React element
|
|
164
|
-
* by:
|
|
165
|
-
* 1. Validating that the node's `element` type is renderable.
|
|
166
|
-
* 2. Normalizing processed children into `ReactNode`s using `_normalizeChild`.
|
|
167
|
-
* 3. Caching normalized children to avoid re-processing on subsequent renders.
|
|
168
|
-
* 4. Assembling the final props, including `key`, `style`, and other attributes.
|
|
169
|
-
* 5. If the element has a `css` prop, it may be wrapped in a `StyledRenderer` to handle
|
|
170
|
-
* CSS-in-JS styling.
|
|
171
|
-
* 6. Finally, calling `React.createElement` with the element, props, and children.
|
|
172
|
-
* @returns The rendered `ReactElement`.
|
|
173
|
-
* @throws {Error} If the node's `element` is not a valid React element type.
|
|
174
66
|
*/
|
|
175
67
|
render(): ReactElement<FinalNodeProps>;
|
|
176
68
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* On the client-side, this method checks for or creates a `div` element appended
|
|
180
|
-
* to the `document.body` and initializes a React root on it. This setup is
|
|
181
|
-
* required for the `toPortal` method to function. It is idempotent and safe
|
|
182
|
-
* to call multiple times.
|
|
183
|
-
* @returns `true` if the portal infrastructure is ready, `false` if on the server.
|
|
184
|
-
* @private
|
|
69
|
+
* Portal infrastructure setup
|
|
185
70
|
*/
|
|
186
71
|
private _ensurePortalInfrastructure;
|
|
187
72
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* Mounts the node's rendered output into a detached DOM tree (a `div` appended to `document.body`),
|
|
191
|
-
* enabling UI elements like modals, tooltips, or notifications to appear above the main app content.
|
|
192
|
-
*
|
|
193
|
-
* Returns a `NodePortal` object with:
|
|
194
|
-
* - `render(content)`: Renders new content into the portal.
|
|
195
|
-
* - `update(next?)`: Rerenders the current node or new content.
|
|
196
|
-
* - `unmount()`: Unmounts the portal and removes the DOM element.
|
|
197
|
-
*
|
|
198
|
-
* Throws if called on the server (where `document.body` is unavailable).
|
|
199
|
-
* @returns A `NodePortal` instance for managing the portal.
|
|
73
|
+
* Portal rendering
|
|
200
74
|
*/
|
|
201
75
|
toPortal(): NodePortal;
|
|
202
76
|
}
|
|
203
77
|
/**
|
|
204
78
|
* Factory function to create a `BaseNode` instance.
|
|
205
|
-
* @template AdditionalProps Additional props to merge with node props.
|
|
206
|
-
* @template E The React element or component type.
|
|
207
|
-
* @param element The React element or component type to wrap.
|
|
208
|
-
* @param props The props for the node (optional).
|
|
209
|
-
* @param additionalProps Additional props to merge into the node (optional).
|
|
210
|
-
* @returns A new `BaseNode` instance as a `NodeInstance<E>`.
|
|
211
79
|
*/
|
|
212
80
|
export declare function Node<AdditionalProps extends Record<string, any>, E extends NodeElementType>(element: E, props?: MergedProps<E, AdditionalProps>, additionalProps?: AdditionalProps): NodeInstance<E>;
|
|
213
81
|
/**
|
|
214
82
|
* Creates a curried node factory for a given React element or component type.
|
|
215
|
-
*
|
|
216
|
-
* Returns a function that, when called with props, produces a `NodeInstance<E>`.
|
|
217
|
-
* Useful for creating reusable node factories for specific components or element types.
|
|
218
|
-
* @template AdditionalInitialProps Additional initial props to merge with node props.
|
|
219
|
-
* @template E The React element or component type.
|
|
220
|
-
* @param element The React element or component type to wrap.
|
|
221
|
-
* @param initialProps Initial props to apply to every node instance.
|
|
222
|
-
* @returns A function that takes node props and returns a `NodeInstance<E>`.
|
|
223
|
-
* @example
|
|
224
|
-
* const ButtonNode = createNode('button', { type: 'button' });
|
|
225
|
-
* const myButton = ButtonNode({ children: 'Click me', style: { color: 'red' } });
|
|
226
83
|
*/
|
|
227
84
|
export declare function createNode<AdditionalInitialProps extends Record<string, any>, E extends NodeElementType>(element: E, initialProps?: MergedProps<E, AdditionalInitialProps>): HasRequiredProps<PropsOf<E>> extends true ? (<AdditionalProps extends Record<string, any> = Record<string, any>>(props: MergedProps<E, AdditionalProps>) => NodeInstance<E>) & {
|
|
228
85
|
element: E;
|
|
@@ -231,22 +88,6 @@ export declare function createNode<AdditionalInitialProps extends Record<string,
|
|
|
231
88
|
};
|
|
232
89
|
/**
|
|
233
90
|
* Creates a node factory function where the first argument is `children` and the second is `props`.
|
|
234
|
-
*
|
|
235
|
-
* Useful for ergonomic creation of nodes where children are the primary concern,
|
|
236
|
-
* such as layout or container components.
|
|
237
|
-
*
|
|
238
|
-
* The returned function takes `children` as the first argument and `props` (excluding `children`) as the second.
|
|
239
|
-
* It merges any `initialProps` provided at factory creation, then creates a `BaseNode` instance.
|
|
240
|
-
*
|
|
241
|
-
* Type parameters:
|
|
242
|
-
* - `AdditionalInitialProps`: Extra props to merge with node props.
|
|
243
|
-
* - `E`: The React element or component type.
|
|
244
|
-
* @param element The React element or component type to wrap.
|
|
245
|
-
* @param initialProps Initial props to apply to every node instance (excluding `children`).
|
|
246
|
-
* @returns A function that takes `children` and `props`, returning a `NodeInstance<E>`.
|
|
247
|
-
* @example
|
|
248
|
-
* const Text = createChildrenFirstNode('p');
|
|
249
|
-
* const myDiv = Text('Hello', { className: 'text-lg' });
|
|
250
91
|
*/
|
|
251
92
|
export declare function createChildrenFirstNode<AdditionalInitialProps extends Record<string, any>, E extends NodeElementType>(element: E, initialProps?: Omit<NodeProps<E>, keyof AdditionalInitialProps | 'children'> & AdditionalInitialProps): HasRequiredProps<PropsOf<E>> extends true ? (<AdditionalProps extends Record<string, any> = Record<string, any>>(children: Children, props: Omit<MergedProps<E, AdditionalProps>, 'children'>) => NodeInstance<E>) & {
|
|
252
93
|
element: E;
|
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,EACR,MAAM,mBAAmB,CAAA;AAO1B;;;;;;;GAOG;AACH,qBAAa,QAAQ,CAAC,CAAC,SAAS,eAAe,CAAE,YAAW,YAAY,CAAC,CAAC,CAAC;IACzE,+EAA+E;IACxE,OAAO,EAAE,CAAC,CAAA;IACjB,kFAAkF;IAC3E,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAK;IAC3C,0CAA0C;IAC1C,SAAgB,UAAU,UAAO;IAEjC,sEAAsE;IACtE,OAAO,CAAC,MAAM,CAAC,CAAgB;IAC/B,4CAA4C;IAC5C,OAAO,CAAC,iBAAiB,CAA8B;IACvD,+CAA+C;IAC/C,OAAO,CAAC,gBAAgB,CAA0E;IAClG,oCAAoC;IACpC,OAAO,CAAC,mBAAmB,CAAC,
|
|
1
|
+
{"version":3,"file":"core.node.d.ts","sourceRoot":"","sources":["../src/core.node.ts"],"names":[],"mappings":"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"}
|
package/dist/core.node.js
CHANGED
|
@@ -7,262 +7,50 @@
|
|
|
7
7
|
* @template E The type of React element or component this node represents
|
|
8
8
|
*/export class BaseNode{/**
|
|
9
9
|
* Constructs a new BaseNode instance.
|
|
10
|
-
*
|
|
11
|
-
* This constructor initializes a node with a given React element or component type
|
|
12
|
-
* and the raw props passed to it. The props are not processed until they are
|
|
13
|
-
* accessed via the `props` getter, allowing for lazy evaluation.
|
|
14
|
-
* @param element The React element or component type this node will represent.
|
|
15
|
-
* @param rawProps The initial, unprocessed props for the element.
|
|
16
10
|
*/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 *//**
|
|
17
11
|
* Normalizes a processed child node into a final, renderable `ReactNode`.
|
|
18
|
-
|
|
19
|
-
* This method is called during the `render` phase. It takes a child that has already
|
|
20
|
-
* been processed by `_processChildren` and prepares it for `React.createElement`.
|
|
21
|
-
*
|
|
22
|
-
* - For `BaseNode` instances, it calls their `render()` method.
|
|
23
|
-
* - It validates that other children are valid React element types.
|
|
24
|
-
* - Primitives and other valid nodes are returned as-is.
|
|
25
|
-
* @param child The processed child node to normalize.
|
|
26
|
-
* @returns A renderable `ReactNode`.
|
|
27
|
-
* @throws {Error} If the child is not a valid React element type.
|
|
28
|
-
* @private
|
|
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
|
|
30
|
-
if(null===a||a===void 0)return a;// Primitives should be returned as-is (text nodes, numbers, booleans)
|
|
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
|
|
33
|
-
if("function"==typeof a.render)// React.Component instance
|
|
34
|
-
return a.render();// Validate element type before returning
|
|
35
|
-
if(!isValidElementType(a)&&!isPortal(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}/**
|
|
12
|
+
*/_defineProperty(this,"rawProps",{}),_defineProperty(this,"isBaseNode",!0),_defineProperty(this,"_portalDOMElement",null),_defineProperty(this,"_portalReactRoot",null),_defineProperty(this,"_normalizeChild",function(a){if(null===a||a===void 0)return a;var b=_typeof(a);if("string"===b||"number"===b||"boolean"===b)return a;if(a instanceof BaseNode||isNodeInstance(a))return a.render();if("function"==typeof a.render)return a.render();if(!isValidElementType(a)&&!isPortal(a)){var c=getComponentType(a);throw new Error("Invalid element type: ".concat(c," provided!"))}return a}),this.element=a,this.rawProps=b}/**
|
|
37
13
|
* Lazily processes and retrieves the final, normalized props for the node.
|
|
38
|
-
*
|
|
39
|
-
* The first time this getter is accessed, it triggers `_processProps` to resolve
|
|
40
|
-
* styles, and children. Subsequent accesses return the cached result
|
|
41
|
-
* until the node is cloned or recreated.
|
|
42
|
-
* @returns The fully processed and normalized `FinalNodeProps`.
|
|
43
14
|
*/get props(){return this._props||(this._props=this._processProps()),this._props}/**
|
|
44
15
|
* Processes raw props into a final, normalized form.
|
|
45
|
-
|
|
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
|
|
50
|
-
* @private
|
|
51
|
-
* @returns The processed `FinalNodeProps` ready for rendering.
|
|
52
|
-
*/_processProps(){// Destructure raw props into relevant parts
|
|
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
|
|
54
|
-
// Combine processed props into final normalized form
|
|
55
|
-
return omitUndefined(_objectSpread(_objectSpread({ref:b,key:c,css:_objectSpread(_objectSpread({},l),e),style:j},m),{},{nativeProps:k,children:n}))}/**
|
|
16
|
+
*/_processProps(){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);return omitUndefined(_objectSpread(_objectSpread({ref:b,key:c,css:_objectSpread(_objectSpread({},l),e),style:j},m),{},{nativeProps:k,children:n}))}/**
|
|
56
17
|
* Recursively processes raw children, converting them into `BaseNode` instances as needed.
|
|
57
|
-
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-
*
|
|
61
|
-
|
|
62
|
-
* @param children The raw child or array of children to process.
|
|
63
|
-
* @returns The processed children, ready for normalization and rendering.
|
|
64
|
-
* @private
|
|
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.
|
|
67
|
-
*
|
|
68
|
-
* This static method centralizes the logic for converting various types of processed elements
|
|
69
|
-
* into renderable React nodes. It handles:
|
|
70
|
-
* - `BaseNode` instances: Re-wraps them to apply a new key.
|
|
71
|
-
* - React class components: Wraps them in a new `BaseNode`.
|
|
72
|
-
* - `NodeInstance` objects: Invokes their `render()` method.
|
|
73
|
-
* - React component instances: Invokes their `render()` method.
|
|
74
|
-
* - Functional components: Creates a React element from them.
|
|
75
|
-
* - Other valid `ReactNode` types (strings, numbers, etc.): Returns them as-is.
|
|
76
|
-
* @param processedElement The node element to render.
|
|
77
|
-
* @param passedKey The React key to assign.
|
|
78
|
-
* @returns A renderable `ReactNode`.
|
|
79
|
-
* @private
|
|
80
|
-
* @static
|
|
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
|
|
84
|
-
// 4. React.Component instance: call its render
|
|
85
|
-
// 5. Functional component: create element with key
|
|
86
|
-
// 6. Other valid ReactNode types
|
|
87
|
-
}/**
|
|
88
|
-
* Renders this node into a `ReactNode`, handling function node element.
|
|
89
|
-
* @param node The node to render.
|
|
90
|
-
* @private
|
|
91
|
-
* @static
|
|
92
|
-
* @example
|
|
93
|
-
* ```typescript
|
|
94
|
-
* const myNode = Node('div', { children: [ () => 'Hello' ] });
|
|
95
|
-
* ```
|
|
96
|
-
*/static _isFunctionChild(a){// Basic function check
|
|
97
|
-
if("function"!=typeof a)return!1;// Exclude React component types
|
|
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
|
|
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
|
|
100
|
-
return!0}}/**
|
|
18
|
+
*/_processChildren(a){if(a){var b;return b="function"==typeof a?a:Array.isArray(a)?a.map(function(a){return BaseNode._processRawNode(a)}):BaseNode._processRawNode(a),b}}/**
|
|
19
|
+
* Renders a processed `NodeElement` into a `ReactNode`.
|
|
20
|
+
*/static _renderProcessedNode(a,b){var c={};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()}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}/**
|
|
21
|
+
* Checks if a node is a function child (render prop style).
|
|
22
|
+
*/static _isFunctionChild(a){if("function"!=typeof a)return!1;if(isReactClassComponent(a))return!1;if(isMemo(a))return!1;if(isForwardRef(a))return!1;try{return!(a.prototype&&"function"==typeof a.prototype.render)}catch(a){return!0}}/**
|
|
101
23
|
* Renders the output of a function-as-a-child.
|
|
102
|
-
|
|
103
|
-
* This method is designed to handle "render prop" style children (`() => ReactNode`).
|
|
104
|
-
* It invokes the function and processes its result.
|
|
105
|
-
* @param props The properties for the function renderer.
|
|
106
|
-
* @param props.render The function to execute to get the child content.
|
|
107
|
-
* @returns The rendered `ReactNode`.
|
|
108
|
-
* @private
|
|
109
|
-
*/static _functionRenderer(a){var b,c=a.render;// Invoke the render function to get the child node.
|
|
110
|
-
try{b=c()}catch(a){b=null}// Handle null/undefined
|
|
111
|
-
if(null===b||b===void 0)return b;// Handle arrays of elements (common in render props)
|
|
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)
|
|
115
|
-
if("string"==typeof b||"number"==typeof b||"boolean"==typeof b)return b;// Process any other result types
|
|
116
|
-
var f=BaseNode._processRawNode(b);return f?BaseNode._renderProcessedNode(f):b}/**
|
|
117
|
-
* Generates a stable key for a node, especially for elements within an array.
|
|
118
|
-
*
|
|
119
|
-
* If an `existingKey` is provided, it is returned. Otherwise, a key is generated
|
|
120
|
-
* based on the element's type name and its index within a list of siblings.
|
|
121
|
-
* This helps prevent re-rendering issues in React when dealing with dynamic lists.
|
|
122
|
-
* @param options The options for key generation.
|
|
123
|
-
* @param options.nodeIndex The index of the node in an array of children.
|
|
124
|
-
* @param options.element The element for which to generate a key.
|
|
125
|
-
* @param options.existingKey An existing key, if one was already provided.
|
|
126
|
-
* @param options.children The children of the node, used to add complexity to the key.
|
|
127
|
-
* @returns A React key, or `undefined` if no key could be generated.
|
|
128
|
-
* @private
|
|
129
|
-
* @static
|
|
130
|
-
*//**
|
|
24
|
+
*/static _functionRenderer(a){var b,c=a.render;try{b=c()}catch(a){b=null}if(null===b||b===void 0)return b;if(Array.isArray(b))return b.map(function(a,b){var c=BaseNode._processRawNode(a);return BaseNode._renderProcessedNode(c,"".concat(getElementTypeName(a),"-").concat(b))});if(b instanceof React.Component){var d=b.render(),e=BaseNode._processRawNode(d);return BaseNode._renderProcessedNode(e)}if(b instanceof BaseNode||isNodeInstance(b))return b.render();if("string"==typeof b||"number"==typeof b||"boolean"==typeof b)return b;var f=BaseNode._processRawNode(b);return f?BaseNode._renderProcessedNode(f):b}/**
|
|
131
25
|
* Processes a single raw node, recursively converting it into a `BaseNode` or other renderable type.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
* - **React Component Instances**: Renders them and processes the output recursively.
|
|
140
|
-
*
|
|
141
|
-
* It also generates a stable key for elements within an array if one is not provided.
|
|
142
|
-
* @param node The raw child node to process.
|
|
143
|
-
* @param nodeIndex The index of the child if it is in an array, used for key generation.
|
|
144
|
-
* @returns A processed `NodeElement` (typically a `BaseNode` instance or a primitive).
|
|
145
|
-
* @private
|
|
146
|
-
* @static
|
|
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
|
|
149
|
-
// Case 1: Child is already a BaseNode instance
|
|
150
|
-
if(a instanceof BaseNode||isNodeInstance(a)){var d=a.rawProps||{};// Get initial raw props of the child
|
|
151
|
-
// Check if we can reuse the existing node
|
|
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
|
|
154
|
-
}// Case 2: Child is a primitive (string, number, boolean, null, undefined)
|
|
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).
|
|
156
|
-
if(BaseNode._isFunctionChild(a)){// The key is for the BaseNode that wraps the _functionRenderer component.
|
|
157
|
-
// Functions themselves don't have a .key prop that we can access here.
|
|
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)
|
|
165
|
-
// These are returned as-is. If they are elements within an array, React expects them to have keys.
|
|
166
|
-
// This logic primarily adds keys to BaseNode instances we create, other ReactNodes are returned as-is.
|
|
26
|
+
*/static _processRawNode(a){// Primitives and null/undefined - return as-is
|
|
27
|
+
if(null===a||a===void 0||"string"==typeof a||"number"==typeof a||"boolean"==typeof a)return a;// Already processed nodes - return as-is
|
|
28
|
+
if(a instanceof BaseNode||isNodeInstance(a))return a;// Function children (render props) - wrap in function renderer
|
|
29
|
+
if(BaseNode._isFunctionChild(a))return new BaseNode(BaseNode._functionRenderer,{render:a});// React elements - extract props and wrap in BaseNode
|
|
30
|
+
if(isValidElement(a)){var b=a.props,c=b.style,d=_objectWithoutProperties(b,_excluded3),e=_objectSpread(_objectSpread({},d),c||{});return new BaseNode(a.type,_objectSpread(_objectSpread({},e),null!==a.key&&void 0!==a.key?{key:a.key}:{}))}// Component types - wrap in BaseNode
|
|
31
|
+
if(isReactClassComponent(a)||isMemo(a)||isForwardRef(a))return new BaseNode(a,{});// React.Component instances - render and process recursively
|
|
32
|
+
if(a instanceof React.Component){var f=a.render();return BaseNode._processRawNode(f)}// Everything else - return as-is
|
|
167
33
|
return a}/**
|
|
168
34
|
* Renders the `BaseNode` into a `ReactElement`.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
* 3. Caching normalized children to avoid re-processing on subsequent renders.
|
|
175
|
-
* 4. Assembling the final props, including `key`, `style`, and other attributes.
|
|
176
|
-
* 5. If the element has a `css` prop, it may be wrapped in a `StyledRenderer` to handle
|
|
177
|
-
* CSS-in-JS styling.
|
|
178
|
-
* 6. Finally, calling `React.createElement` with the element, props, and children.
|
|
179
|
-
* @returns The rendered `ReactElement`.
|
|
180
|
-
* @throws {Error} If the node's `element` is not a valid React element type.
|
|
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
|
|
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
|
|
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
|
|
184
|
-
// This enables emotion-based style handling for the element
|
|
185
|
-
if(this.element&&!hasNoStyleTag(this.element)&&g.css){// Set displayName for easier debugging in React DevTools
|
|
186
|
-
try{var j=getElementTypeName(this.element);StyledRenderer.displayName="Styled(".concat(j,")")}catch(a){// swallow: displayName is not critical
|
|
187
|
-
}return createElement(StyledRenderer,_objectSpread(_objectSpread({element:this.element},g),{},{key:e,suppressHydrationWarning:!0},f),h)}// For other elements, create the React element directly
|
|
188
|
-
// Set displayName for easier debugging in React DevTools
|
|
35
|
+
*/render(){var a=this;if(!isValidElementType(this.element)){var b=getComponentType(this.element);throw new Error("Invalid element type: ".concat(b," provided!"))}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}// Common props for all createElement calls
|
|
36
|
+
var j=_objectSpread(_objectSpread({},g),{},{key:e},f);// Fragment handling
|
|
37
|
+
if(this.element===Fragment||isFragment(this.element))return Array.isArray(h)?createElement(this.element,{key:e},...h):createElement(this.element,{key:e},h);// Styled component handling
|
|
38
|
+
if(this.element&&!hasNoStyleTag(this.element)&&g.css){try{var k=getElementTypeName(this.element);StyledRenderer.displayName="Styled(".concat(k,")")}catch(a){// swallow: displayName is not critical
|
|
39
|
+
}return createElement(StyledRenderer,_objectSpread(_objectSpread({element:this.element},j),{},{suppressHydrationWarning:!0}),...(Array.isArray(h)?h:[h]))}// Regular element handling with spread children
|
|
189
40
|
try{this.element.displayName=getElementTypeName(this.element)}catch(a){// swallow: displayName is not critical
|
|
190
|
-
}return createElement(this.element,
|
|
191
|
-
*
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
*
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
* @returns `true` if the portal infrastructure is ready, `false` if on the server.
|
|
198
|
-
* @private
|
|
199
|
-
*/_ensurePortalInfrastructure(){if(BaseNode._isServer)return!1;// If both exist and DOM is connected, we're ready
|
|
200
|
-
if(this._portalDOMElement&&this._portalReactRoot&&this._portalDOMElement.isConnected)return!0;// If DOM element exists but isn't connected, clear both DOM element and root
|
|
201
|
-
if(this._portalDOMElement&&!this._portalDOMElement.isConnected){// attempt to unmount root if present
|
|
202
|
-
if(this._portalReactRoot){try{this._portalReactRoot.unmount()}catch(a){// swallow: unmount might fail if already removed; avoid breaking the app
|
|
203
|
-
}this._portalReactRoot=null}this._portalDOMElement=null}// Create DOM element if needed
|
|
204
|
-
// Create react root if needed
|
|
205
|
-
if(this._portalDOMElement||(this._portalDOMElement=document.createElement("div"),document.body.appendChild(this._portalDOMElement)),!this._portalReactRoot){if(!this._portalDOMElement)return!1;var a=createRoot(this._portalDOMElement);this._portalReactRoot={render:a.render.bind(a),unmount:a.unmount.bind(a),update:function update(){/* will be patched later */}}}return!0}/**
|
|
206
|
-
* Renders the node into a React Portal.
|
|
207
|
-
*
|
|
208
|
-
* Mounts the node's rendered output into a detached DOM tree (a `div` appended to `document.body`),
|
|
209
|
-
* enabling UI elements like modals, tooltips, or notifications to appear above the main app content.
|
|
210
|
-
*
|
|
211
|
-
* Returns a `NodePortal` object with:
|
|
212
|
-
* - `render(content)`: Renders new content into the portal.
|
|
213
|
-
* - `update(next?)`: Rerenders the current node or new content.
|
|
214
|
-
* - `unmount()`: Unmounts the portal and removes the DOM element.
|
|
215
|
-
*
|
|
216
|
-
* Throws if called on the server (where `document.body` is unavailable).
|
|
217
|
-
* @returns A `NodePortal` instance for managing the portal.
|
|
218
|
-
*/toPortal(){var a=this;if(!this._ensurePortalInfrastructure()||!this._portalReactRoot)throw new Error("toPortal() can only be called in a client-side environment where document.body is available.");// Initial render
|
|
219
|
-
(function renderCurrent(){try{var b=a.render();a._portalReactRoot.render(b)}catch(a){// swallow render errors to avoid breaking caller
|
|
220
|
-
}})();// Patch the root with an update() method and a safe unmount that also removes DOM element.
|
|
221
|
-
try{var b=this._portalReactRoot.unmount.bind(this._portalReactRoot),c=this._portalReactRoot;// Create typed handle
|
|
222
|
-
return c.update=function(b){try{if(!a._portalReactRoot)return;// If next is a BaseNode or NodeInstance, render its output
|
|
223
|
-
if(b instanceof BaseNode||b&&"function"==typeof b.render){var c=b.render?b.render():b;return void a._portalReactRoot.render(c)}// Otherwise assume a ReactNode and render directly
|
|
224
|
-
a._portalReactRoot.render(b)}catch(a){// swallow
|
|
41
|
+
}return createElement(this.element,j,...(Array.isArray(h)?h:[h]))}/**
|
|
42
|
+
* Portal infrastructure setup
|
|
43
|
+
*/_ensurePortalInfrastructure(){if(BaseNode._isServer)return!1;if(this._portalDOMElement&&this._portalReactRoot&&this._portalDOMElement.isConnected)return!0;if(this._portalDOMElement&&!this._portalDOMElement.isConnected){if(this._portalReactRoot){try{this._portalReactRoot.unmount()}catch(a){// swallow
|
|
44
|
+
}this._portalReactRoot=null}this._portalDOMElement=null}if(this._portalDOMElement||(this._portalDOMElement=document.createElement("div"),document.body.appendChild(this._portalDOMElement)),!this._portalReactRoot){if(!this._portalDOMElement)return!1;var a=createRoot(this._portalDOMElement);this._portalReactRoot={render:a.render.bind(a),unmount:a.unmount.bind(a),update:function update(){}}}return!0}/**
|
|
45
|
+
* Portal rendering
|
|
46
|
+
*/toPortal(){var a=this;if(!this._ensurePortalInfrastructure()||!this._portalReactRoot)throw new Error("toPortal() can only be called in a client-side environment where document.body is available.");(function renderCurrent(){try{var b=a.render();a._portalReactRoot.render(b)}catch(a){// swallow render errors to avoid breaking caller
|
|
47
|
+
}})();try{var b=this._portalReactRoot.unmount.bind(this._portalReactRoot),c=this._portalReactRoot;return c.update=function(b){try{if(!a._portalReactRoot)return;if(b instanceof BaseNode||b&&"function"==typeof b.render){var c=b.render?b.render():b;return void a._portalReactRoot.render(c)}a._portalReactRoot.render(b)}catch(a){// swallow
|
|
225
48
|
}},c.unmount=function(){try{b()}catch(a){// swallow
|
|
226
|
-
}//
|
|
227
|
-
|
|
228
|
-
}a._portalDOMElement=null}a._portalReactRoot=null},c}catch(a){// fallback: return the raw root as-is (without update/unmount patch)
|
|
229
|
-
return this._portalReactRoot}}}/**
|
|
49
|
+
}if(a._portalDOMElement){try{a._portalDOMElement.parentNode&&a._portalDOMElement.parentNode.removeChild(a._portalDOMElement)}catch(a){// swallow
|
|
50
|
+
}a._portalDOMElement=null}a._portalReactRoot=null},c}catch(a){return this._portalReactRoot}}}/**
|
|
230
51
|
* Factory function to create a `BaseNode` instance.
|
|
231
|
-
|
|
232
|
-
* @template E The React element or component type.
|
|
233
|
-
* @param element The React element or component type to wrap.
|
|
234
|
-
* @param props The props for the node (optional).
|
|
235
|
-
* @param additionalProps Additional props to merge into the node (optional).
|
|
236
|
-
* @returns A new `BaseNode` instance as a `NodeInstance<E>`.
|
|
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)}/**
|
|
52
|
+
*/_defineProperty(BaseNode,"_isServer","undefined"==typeof window);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)}/**
|
|
238
53
|
* Creates a curried node factory for a given React element or component type.
|
|
239
|
-
*
|
|
240
|
-
* Returns a function that, when called with props, produces a `NodeInstance<E>`.
|
|
241
|
-
* Useful for creating reusable node factories for specific components or element types.
|
|
242
|
-
* @template AdditionalInitialProps Additional initial props to merge with node props.
|
|
243
|
-
* @template E The React element or component type.
|
|
244
|
-
* @param element The React element or component type to wrap.
|
|
245
|
-
* @param initialProps Initial props to apply to every node instance.
|
|
246
|
-
* @returns A function that takes node props and returns a `NodeInstance<E>`.
|
|
247
|
-
* @example
|
|
248
|
-
* const ButtonNode = createNode('button', { type: 'button' });
|
|
249
|
-
* const myButton = ButtonNode({ children: 'Click me', style: { color: 'red' } });
|
|
250
54
|
*/export function createNode(a,b){var c=function Instance(c){return Node(a,_objectSpread(_objectSpread({},b),c))};return c.element=a,c}/**
|
|
251
55
|
* Creates a node factory function where the first argument is `children` and the second is `props`.
|
|
252
|
-
*
|
|
253
|
-
* Useful for ergonomic creation of nodes where children are the primary concern,
|
|
254
|
-
* such as layout or container components.
|
|
255
|
-
*
|
|
256
|
-
* The returned function takes `children` as the first argument and `props` (excluding `children`) as the second.
|
|
257
|
-
* It merges any `initialProps` provided at factory creation, then creates a `BaseNode` instance.
|
|
258
|
-
*
|
|
259
|
-
* Type parameters:
|
|
260
|
-
* - `AdditionalInitialProps`: Extra props to merge with node props.
|
|
261
|
-
* - `E`: The React element or component type.
|
|
262
|
-
* @param element The React element or component type to wrap.
|
|
263
|
-
* @param initialProps Initial props to apply to every node instance (excluding `children`).
|
|
264
|
-
* @returns A function that takes `children` and `props`, returning a `NodeInstance<E>`.
|
|
265
|
-
* @example
|
|
266
|
-
* const Text = createChildrenFirstNode('p');
|
|
267
|
-
* const myDiv = Text('Hello', { className: 'text-lg' });
|
|
268
56
|
*/export function createChildrenFirstNode(a,b){var c=function Instance(c,d){return Node(a,_objectSpread(_objectSpread(_objectSpread({},b),d),{},{children:c}))};return c.element=a,c}
|
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.3.
|
|
4
|
+
"version": "0.3.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/main.js",
|
|
7
7
|
"types": "./dist/main.d.ts",
|