lilact 0.18.0 → 0.19.0
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/lilact.development.js +34 -9
- package/dist/lilact.development.js.map +3 -3
- package/dist/lilact.development.min.js +16 -16
- package/dist/lilact.development.min.js.map +3 -3
- package/dist/lilact.production.min.js +17 -17
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/accessories.ErrorBoundary.html +8 -8
- package/docs/classes/accessories.Suspense.html +7 -7
- package/docs/classes/components.Component.html +11 -11
- package/docs/classes/components.HTMLComponent.html +11 -11
- package/docs/classes/components.RootComponent.html +11 -11
- package/docs/functions/components.createComponent.html +1 -1
- package/docs/functions/components.createPortal.html +11 -0
- package/docs/functions/components.createRoot.html +1 -1
- package/docs/functions/components.memo.html +1 -1
- package/docs/functions/components.render.html +1 -1
- package/docs/functions/misc.Fragment.html +1 -1
- package/docs/functions/misc.Portal.html +4 -0
- package/docs/functions/misc.deepEqual.html +1 -1
- package/docs/functions/misc.forwardRef.html +1 -1
- package/docs/functions/misc.getComponentByPointer.html +1 -1
- package/docs/functions/misc.isAsync.html +1 -1
- package/docs/functions/misc.isClass.html +1 -1
- package/docs/functions/misc.isEmpty.html +1 -1
- package/docs/functions/misc.isError.html +1 -1
- package/docs/functions/misc.isThenable.html +1 -1
- package/docs/functions/misc.shallowEqual.html +1 -1
- package/docs/functions/misc.toBool.html +1 -1
- package/docs/functions/timers.timeoutPromise.html +4 -5
- package/docs/hierarchy.html +1 -1
- package/docs/modules/components.html +1 -1
- package/docs/modules/misc.html +1 -1
- package/docs/static/demos/portal.jsx +56 -0
- package/docs/static/index.html +6 -2
- package/docs/static/lilact.development.js +34 -9
- package/docs/static/lilact.development.js.map +3 -3
- package/docs/static/lilact.development.min.js +16 -16
- package/docs/static/lilact.development.min.js.map +3 -3
- package/docs/static/lilact.production.min.js +17 -17
- package/docs/variables/misc.Children.html +2 -2
- package/examples/demos/portal.jsx +56 -0
- package/examples/index.html +6 -2
- package/examples/lilact.development.js +34 -9
- package/examples/lilact.development.js.map +3 -3
- package/examples/lilact.development.min.js +16 -16
- package/examples/lilact.development.min.js.map +3 -3
- package/examples/lilact.production.min.js +17 -17
- package/package.json +1 -1
- package/src/components.jsx +46 -9
- package/src/lilact.jsx +1 -1
- package/src/misc.jsx +18 -1
package/src/components.jsx
CHANGED
|
@@ -97,7 +97,7 @@ class ComponentCache
|
|
|
97
97
|
if(ex.cleanup) {
|
|
98
98
|
ex.cleanup();
|
|
99
99
|
}
|
|
100
|
-
else if(ex.element) {
|
|
100
|
+
else if(ex.element && !ex.portal) {
|
|
101
101
|
ex.element.parentElement.removeChild(ex.element);
|
|
102
102
|
}
|
|
103
103
|
});
|
|
@@ -209,7 +209,6 @@ if(DEBUG) {
|
|
|
209
209
|
this.element[COMPONENT] = this.component;
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
|
|
213
212
|
if(next_props.ref) {
|
|
214
213
|
if(typeof(next_props.ref)==='function') {
|
|
215
214
|
next_props.ref(this.element || this.component);
|
|
@@ -266,6 +265,12 @@ if(DEBUG) {
|
|
|
266
265
|
}
|
|
267
266
|
}
|
|
268
267
|
|
|
268
|
+
|
|
269
|
+
if( this?.portal ) {
|
|
270
|
+
this.element = this.portal;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
|
|
269
274
|
if(this.outlet?.constructor?.name!=='Array') {
|
|
270
275
|
this.outlet = [this.outlet];
|
|
271
276
|
}
|
|
@@ -341,7 +346,7 @@ if(DEBUG) {
|
|
|
341
346
|
this.component.componentWillUnmount();
|
|
342
347
|
}
|
|
343
348
|
|
|
344
|
-
if(this?.element?.parentElement) {
|
|
349
|
+
if(this?.element?.parentElement && !this.portal) {
|
|
345
350
|
this.element.parentElement.removeChild( this.element );
|
|
346
351
|
}
|
|
347
352
|
|
|
@@ -538,6 +543,8 @@ if(DEBUG) {
|
|
|
538
543
|
|
|
539
544
|
appendElement(core)
|
|
540
545
|
{
|
|
546
|
+
if(core.portal) return;
|
|
547
|
+
|
|
541
548
|
this.scanZombies(core.container, core.element);
|
|
542
549
|
|
|
543
550
|
if(core?.element.parentNode===null) {
|
|
@@ -643,9 +650,14 @@ function constructFunc(core, parent) // returns {text} or component, and not com
|
|
|
643
650
|
let entity = core.entity;
|
|
644
651
|
let memoized = false;
|
|
645
652
|
|
|
646
|
-
if(typeof(entity)==='object'
|
|
647
|
-
|
|
648
|
-
|
|
653
|
+
if(typeof(entity)==='object') {
|
|
654
|
+
if( entity[MEMOIZED] ) {
|
|
655
|
+
memoized = entity[MEMOIZED];
|
|
656
|
+
entity = entity.component;
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
throw new Error("Invalid component.");
|
|
660
|
+
}
|
|
649
661
|
}
|
|
650
662
|
|
|
651
663
|
if(typeof(entity)==='string') {
|
|
@@ -1131,8 +1143,6 @@ export function createComponent(entity, props={}, ...children)
|
|
|
1131
1143
|
}
|
|
1132
1144
|
}
|
|
1133
1145
|
|
|
1134
|
-
//if(entity===null) return children; // <> style fragment
|
|
1135
|
-
|
|
1136
1146
|
props.key = generateComponentKey(entity, props);
|
|
1137
1147
|
props.children = children;
|
|
1138
1148
|
|
|
@@ -1179,6 +1189,27 @@ export function createRoot(element)
|
|
|
1179
1189
|
}
|
|
1180
1190
|
}
|
|
1181
1191
|
|
|
1192
|
+
/**
|
|
1193
|
+
* Creates a portal — a way to render children into a DOM node
|
|
1194
|
+
* that exists outside the current component hierarchy.
|
|
1195
|
+
*
|
|
1196
|
+
* Note: In React, events from portals propagate according to the React tree rather
|
|
1197
|
+
* than the DOM tree. For example, if you click inside a portal, and the portal is
|
|
1198
|
+
* wrapped in `<div onClick>`, that onClick handler will fire. Lilact doesn't act
|
|
1199
|
+
* this way. In Lilact, event propagation follows DOM tree, while the ownership
|
|
1200
|
+
* follow the JSX structure.
|
|
1201
|
+
*
|
|
1202
|
+
* @param {Component} children - The component(s) to render into the portal.
|
|
1203
|
+
* @param {Element} element - The DOM node that will receive the portal content.
|
|
1204
|
+
* @returns {Component} A portal object that can be rendered.
|
|
1205
|
+
*/
|
|
1206
|
+
|
|
1207
|
+
export function createPortal(children, element)
|
|
1208
|
+
{
|
|
1209
|
+
return <Lilact.Portal view={element}>{children}</Lilact.Portal>;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
|
|
1182
1213
|
/**
|
|
1183
1214
|
* Renders a component into a target DOM element.
|
|
1184
1215
|
* If the component maintains internal state, this typically mounts it (or updates the existing tree) under `element`.
|
|
@@ -1209,7 +1240,13 @@ export function render(component, element)
|
|
|
1209
1240
|
|
|
1210
1241
|
export function memo(component)
|
|
1211
1242
|
{
|
|
1212
|
-
|
|
1243
|
+
if(typeof(component)==='object') {
|
|
1244
|
+
component[MEMOIZED] = true;
|
|
1245
|
+
}
|
|
1246
|
+
else {
|
|
1247
|
+
component = { component, [MEMOIZED]: true };
|
|
1248
|
+
}
|
|
1249
|
+
return component;
|
|
1213
1250
|
}
|
|
1214
1251
|
|
|
1215
1252
|
|
package/src/lilact.jsx
CHANGED
package/src/misc.jsx
CHANGED
|
@@ -95,9 +95,26 @@ export const findDOMNode = (component)=>{
|
|
|
95
95
|
*
|
|
96
96
|
* @param children - The nodes to group without adding an extra DOM element.
|
|
97
97
|
*/
|
|
98
|
-
export
|
|
98
|
+
export function Fragment({children})
|
|
99
|
+
{
|
|
100
|
+
return children;
|
|
101
|
+
};
|
|
99
102
|
Fragment.displayName = "Fragment";
|
|
100
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Portal helper/utility.
|
|
106
|
+
*
|
|
107
|
+
* @param view - The DOM node that will receive the portal content.
|
|
108
|
+
* @param children - The nodes to put in the portal element.
|
|
109
|
+
*/
|
|
110
|
+
export function Portal({children, view})
|
|
111
|
+
{
|
|
112
|
+
this[CORE].portal = view;
|
|
113
|
+
|
|
114
|
+
return children;
|
|
115
|
+
};
|
|
116
|
+
Portal.displayName = "Portal";
|
|
117
|
+
|
|
101
118
|
/**
|
|
102
119
|
* Children namespace for utilities that operate on `props.children`. `Children` is deprecated
|
|
103
120
|
* and not recommended by React documentation itself. But `only` and `toArray` are used
|