lilact 0.18.0 → 0.20.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/README.md +1 -1
- package/dist/lilact.development.js +162 -37
- package/dist/lilact.development.js.map +3 -3
- package/dist/lilact.development.min.js +19 -19
- package/dist/lilact.development.min.js.map +3 -3
- package/dist/lilact.production.min.js +21 -21
- 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 +20 -12
- package/docs/hierarchy.html +1 -1
- package/docs/index.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 +162 -37
- package/docs/static/lilact.development.js.map +3 -3
- package/docs/static/lilact.development.min.js +19 -19
- package/docs/static/lilact.development.min.js.map +3 -3
- package/docs/static/lilact.production.min.js +21 -21
- package/docs/variables/misc.Children.html +19 -10
- package/examples/demos/portal.jsx +56 -0
- package/examples/index.html +6 -2
- package/examples/lilact.development.js +162 -37
- package/examples/lilact.development.js.map +3 -3
- package/examples/lilact.development.min.js +19 -19
- package/examples/lilact.development.min.js.map +3 -3
- package/examples/lilact.production.min.js +21 -21
- package/package.json +1 -1
- package/src/components.jsx +46 -9
- package/src/lilact.jsx +1 -1
- package/src/misc.jsx +178 -43
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ If you find Lilact useful, please consider sponsoring. Your support funds ongoin
|
|
|
29
29
|
|
|
30
30
|
## Overview
|
|
31
31
|
|
|
32
|
-
`Lilact` is a very lightweight implementation of the React API designed to run in the browser. It can be used as a single script that is around `90kb` minified and around `32kb` gzipped and includes its whole API.
|
|
32
|
+
`Lilact` is a very lightweight implementation of the React API designed to run in the browser. It can be used as a single script that is around `90kb` minified and around `32kb` gzipped and includes its whole API. It is tested and works on **Chrome**, **Firefox**, **Edge**, and **Safari**.
|
|
33
33
|
|
|
34
34
|
`Lilact` is very fast, uses minimal resources, and handles memory very efficiently.
|
|
35
35
|
|
|
@@ -1975,6 +1975,7 @@ __export(components_exports, {
|
|
|
1975
1975
|
capture_events_set: () => capture_events_set,
|
|
1976
1976
|
createComponent: () => createComponent2,
|
|
1977
1977
|
createElement: () => createElement,
|
|
1978
|
+
createPortal: () => createPortal,
|
|
1978
1979
|
createRoot: () => createRoot,
|
|
1979
1980
|
current_component: () => current_component,
|
|
1980
1981
|
effect_timeout: () => effect_timeout,
|
|
@@ -2032,6 +2033,7 @@ var misc_exports = {};
|
|
|
2032
2033
|
__export(misc_exports, {
|
|
2033
2034
|
Children: () => Children,
|
|
2034
2035
|
Fragment: () => Fragment2,
|
|
2036
|
+
Portal: () => Portal,
|
|
2035
2037
|
deepEqual: () => deepEqual,
|
|
2036
2038
|
eval_num: () => eval_num,
|
|
2037
2039
|
findDOMNode: () => findDOMNode,
|
|
@@ -2063,49 +2065,154 @@ var findDOMNode = (component) => {
|
|
|
2063
2065
|
if (!((_b = (_a = component[CORE]) == null ? void 0 : _a.element) == null ? void 0 : _b.parentNode)) throw new Error("findDOMNode only works on mounted components.");
|
|
2064
2066
|
return component[CORE].element;
|
|
2065
2067
|
};
|
|
2066
|
-
|
|
2068
|
+
function Fragment2({ children }) {
|
|
2067
2069
|
return children;
|
|
2068
|
-
}
|
|
2070
|
+
}
|
|
2069
2071
|
Fragment2.displayName = "Fragment";
|
|
2072
|
+
function Portal({ children, view }) {
|
|
2073
|
+
this[CORE].portal = view;
|
|
2074
|
+
return children;
|
|
2075
|
+
}
|
|
2076
|
+
Portal.displayName = "Portal";
|
|
2070
2077
|
var Children = {
|
|
2071
2078
|
/**
|
|
2072
|
-
*
|
|
2079
|
+
* @param {any} x
|
|
2080
|
+
* @returns {boolean}
|
|
2081
|
+
*/
|
|
2082
|
+
_isNil(x) {
|
|
2083
|
+
return x === null || x === void 0;
|
|
2084
|
+
},
|
|
2085
|
+
/**
|
|
2086
|
+
* Recursively flattens nested arrays into `out`, omitting null/undefined.
|
|
2087
|
+
* @param {Array<any>} out
|
|
2088
|
+
* @param {any} input
|
|
2089
|
+
*/
|
|
2090
|
+
_flattenInto(out, input) {
|
|
2091
|
+
if (this._isNil(input)) return;
|
|
2092
|
+
if (Array.isArray(input)) {
|
|
2093
|
+
for (const v of input) this._flattenInto(out, v);
|
|
2094
|
+
return;
|
|
2095
|
+
}
|
|
2096
|
+
out.push(input);
|
|
2097
|
+
},
|
|
2098
|
+
/**
|
|
2099
|
+
* Converts an iterable children collection into a flat array,
|
|
2100
|
+
* omitting `null`/`undefined`.
|
|
2073
2101
|
*
|
|
2074
|
-
* @param
|
|
2075
|
-
* @returns
|
|
2102
|
+
* @param {Iterable<any>} children
|
|
2103
|
+
* @returns {Array<any>}
|
|
2104
|
+
*/
|
|
2105
|
+
toArray(children) {
|
|
2106
|
+
const out = [];
|
|
2107
|
+
if (!children) return out;
|
|
2108
|
+
for (const item of children) {
|
|
2109
|
+
this._flattenInto(out, item);
|
|
2110
|
+
}
|
|
2111
|
+
return out;
|
|
2112
|
+
},
|
|
2113
|
+
/**
|
|
2114
|
+
* Returns the number of non-null/undefined children (after flattening).
|
|
2115
|
+
* @param {Iterable<any>} children
|
|
2116
|
+
* @returns {number}
|
|
2117
|
+
*/
|
|
2118
|
+
count(children) {
|
|
2119
|
+
return this.toArray(children).length;
|
|
2120
|
+
},
|
|
2121
|
+
/**
|
|
2122
|
+
* Returns the single child from a children collection (after flattening & omitting nil),
|
|
2123
|
+
* or throws if the remaining count is not exactly 1.
|
|
2124
|
+
*
|
|
2125
|
+
* @param {Iterable<any>} children
|
|
2126
|
+
* @returns {any}
|
|
2076
2127
|
*/
|
|
2077
2128
|
only(children) {
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
children.splice(i2, 1, ...children[i2]);
|
|
2084
|
-
i2--;
|
|
2085
|
-
} else if (children[i2] === null || children[i2] === void 0) {
|
|
2086
|
-
children.splice(i2, 1);
|
|
2087
|
-
i2--;
|
|
2088
|
-
}
|
|
2089
|
-
if (i2 > 1) {
|
|
2090
|
-
throw new Error("No child or child is not the only one");
|
|
2091
|
-
}
|
|
2092
|
-
i2++;
|
|
2129
|
+
const arr = this.toArray(children);
|
|
2130
|
+
if (arr.length !== 1) {
|
|
2131
|
+
throw new Error(
|
|
2132
|
+
arr.length === 0 ? "Expected exactly one child, but received none." : "Expected exactly one child, but received more than one."
|
|
2133
|
+
);
|
|
2093
2134
|
}
|
|
2094
|
-
|
|
2135
|
+
return arr[0];
|
|
2095
2136
|
},
|
|
2096
2137
|
/**
|
|
2097
|
-
*
|
|
2138
|
+
* Maps over children (after flattening & omitting nil).
|
|
2098
2139
|
*
|
|
2099
|
-
* @param
|
|
2100
|
-
* @
|
|
2140
|
+
* @param {Iterable<any>} children
|
|
2141
|
+
* @param {(child:any, index:number)=>any} fn
|
|
2142
|
+
* @returns {Array<any>}
|
|
2101
2143
|
*/
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2144
|
+
map(children, fn) {
|
|
2145
|
+
const arr = this.toArray(children);
|
|
2146
|
+
const out = [];
|
|
2147
|
+
for (let i2 = 0; i2 < arr.length; i2++) out.push(fn(arr[i2], i2));
|
|
2148
|
+
return out;
|
|
2149
|
+
},
|
|
2150
|
+
/**
|
|
2151
|
+
* Iterates over children (after flattening & omitting nil).
|
|
2152
|
+
* @param {Iterable<any>} children
|
|
2153
|
+
* @param {(child:any, index:number)=>void} fn
|
|
2154
|
+
*/
|
|
2155
|
+
forEach(children, fn) {
|
|
2156
|
+
const arr = this.toArray(children);
|
|
2157
|
+
for (let i2 = 0; i2 < arr.length; i2++) fn(arr[i2], i2);
|
|
2158
|
+
},
|
|
2159
|
+
/**
|
|
2160
|
+
* Finds the first child for which predicate returns true.
|
|
2161
|
+
*
|
|
2162
|
+
* @param {Iterable<any>} children
|
|
2163
|
+
* @param {(child:any, index:number)=>boolean} predicate
|
|
2164
|
+
* @returns {any|undefined}
|
|
2165
|
+
*/
|
|
2166
|
+
find(children, predicate) {
|
|
2167
|
+
const arr = this.toArray(children);
|
|
2168
|
+
for (let i2 = 0; i2 < arr.length; i2++) {
|
|
2169
|
+
if (predicate(arr[i2], i2)) return arr[i2];
|
|
2170
|
+
}
|
|
2171
|
+
return void 0;
|
|
2172
|
+
},
|
|
2173
|
+
/**
|
|
2174
|
+
* Finds exactly one matching child.
|
|
2175
|
+
* Throws if matched count is not exactly 1.
|
|
2176
|
+
*
|
|
2177
|
+
* @param {Iterable<any>} children
|
|
2178
|
+
* @param {(child:any, index:number)=>boolean} predicate
|
|
2179
|
+
* @returns {any}
|
|
2180
|
+
*/
|
|
2181
|
+
pickOne(children, predicate) {
|
|
2182
|
+
const arr = this.toArray(children);
|
|
2183
|
+
let found;
|
|
2184
|
+
let matches = 0;
|
|
2185
|
+
for (let i2 = 0; i2 < arr.length; i2++) {
|
|
2186
|
+
if (predicate(arr[i2], i2)) {
|
|
2187
|
+
matches++;
|
|
2188
|
+
found = arr[i2];
|
|
2189
|
+
if (matches > 1) break;
|
|
2190
|
+
}
|
|
2107
2191
|
}
|
|
2108
|
-
|
|
2192
|
+
if (matches !== 1) {
|
|
2193
|
+
throw new Error(
|
|
2194
|
+
matches === 0 ? "pickOne expected exactly one matching child, but matched none." : "pickOne expected exactly one matching child, but matched multiple."
|
|
2195
|
+
);
|
|
2196
|
+
}
|
|
2197
|
+
return found;
|
|
2198
|
+
},
|
|
2199
|
+
/**
|
|
2200
|
+
* Returns the first non-nil child (after flattening), or undefined.
|
|
2201
|
+
* @param {Iterable<any>} children
|
|
2202
|
+
* @returns {any|undefined}
|
|
2203
|
+
*/
|
|
2204
|
+
first(children) {
|
|
2205
|
+
const arr = this.toArray(children);
|
|
2206
|
+
return arr[0];
|
|
2207
|
+
},
|
|
2208
|
+
/**
|
|
2209
|
+
* Returns the last non-nil child (after flattening), or undefined.
|
|
2210
|
+
* @param {Iterable<any>} children
|
|
2211
|
+
* @returns {any|undefined}
|
|
2212
|
+
*/
|
|
2213
|
+
last(children) {
|
|
2214
|
+
const arr = this.toArray(children);
|
|
2215
|
+
return arr.length ? arr[arr.length - 1] : void 0;
|
|
2109
2216
|
}
|
|
2110
2217
|
};
|
|
2111
2218
|
var forwardRef = (render2) => {
|
|
@@ -2246,7 +2353,7 @@ var ComponentCache = class {
|
|
|
2246
2353
|
arr.slice(arr[IDX]).forEach((ex) => {
|
|
2247
2354
|
if (ex.cleanup) {
|
|
2248
2355
|
ex.cleanup();
|
|
2249
|
-
} else if (ex.element) {
|
|
2356
|
+
} else if (ex.element && !ex.portal) {
|
|
2250
2357
|
ex.element.parentElement.removeChild(ex.element);
|
|
2251
2358
|
}
|
|
2252
2359
|
});
|
|
@@ -2356,6 +2463,9 @@ var ComponentCore = class {
|
|
|
2356
2463
|
renderErrorHandler(this, e);
|
|
2357
2464
|
}
|
|
2358
2465
|
}
|
|
2466
|
+
if (this == null ? void 0 : this.portal) {
|
|
2467
|
+
this.element = this.portal;
|
|
2468
|
+
}
|
|
2359
2469
|
if (((_e = (_d = this.outlet) == null ? void 0 : _d.constructor) == null ? void 0 : _e.name) !== "Array") {
|
|
2360
2470
|
this.outlet = [this.outlet];
|
|
2361
2471
|
}
|
|
@@ -2411,7 +2521,7 @@ var ComponentCore = class {
|
|
|
2411
2521
|
if (this.component.componentWillUnmount) {
|
|
2412
2522
|
this.component.componentWillUnmount();
|
|
2413
2523
|
}
|
|
2414
|
-
if ((_b = this == null ? void 0 : this.element) == null ? void 0 : _b.parentElement) {
|
|
2524
|
+
if (((_b = this == null ? void 0 : this.element) == null ? void 0 : _b.parentElement) && !this.portal) {
|
|
2415
2525
|
this.element.parentElement.removeChild(this.element);
|
|
2416
2526
|
}
|
|
2417
2527
|
if (this.outlet !== void 0) {
|
|
@@ -2559,6 +2669,7 @@ var ComponentCore = class {
|
|
|
2559
2669
|
}
|
|
2560
2670
|
appendElement(core) {
|
|
2561
2671
|
var _a;
|
|
2672
|
+
if (core.portal) return;
|
|
2562
2673
|
this.scanZombies(core.container, core.element);
|
|
2563
2674
|
if ((core == null ? void 0 : core.element.parentNode) === null) {
|
|
2564
2675
|
core.container.element.insertBefore(
|
|
@@ -2628,9 +2739,13 @@ function constructFunc(core, parent) {
|
|
|
2628
2739
|
} else {
|
|
2629
2740
|
let entity = core.entity;
|
|
2630
2741
|
let memoized = false;
|
|
2631
|
-
if (typeof entity === "object"
|
|
2632
|
-
|
|
2633
|
-
|
|
2742
|
+
if (typeof entity === "object") {
|
|
2743
|
+
if (entity[MEMOIZED]) {
|
|
2744
|
+
memoized = entity[MEMOIZED];
|
|
2745
|
+
entity = entity.component;
|
|
2746
|
+
} else {
|
|
2747
|
+
throw new Error("Invalid component.");
|
|
2748
|
+
}
|
|
2634
2749
|
}
|
|
2635
2750
|
if (typeof entity === "string") {
|
|
2636
2751
|
comp = new HTMLComponent(entity, core.props);
|
|
@@ -2956,6 +3071,9 @@ function createRoot(element) {
|
|
|
2956
3071
|
}
|
|
2957
3072
|
};
|
|
2958
3073
|
}
|
|
3074
|
+
function createPortal(children, element) {
|
|
3075
|
+
return createComponent2(lilact_default.Portal, { "view": element }, children);
|
|
3076
|
+
}
|
|
2959
3077
|
function render(component, element) {
|
|
2960
3078
|
if (component[CORE] && (component[CORE].container || component[CORE].parent)) {
|
|
2961
3079
|
throw new Error("Component is already in use");
|
|
@@ -2963,7 +3081,12 @@ function render(component, element) {
|
|
|
2963
3081
|
return createRoot(element).render(component);
|
|
2964
3082
|
}
|
|
2965
3083
|
function memo(component) {
|
|
2966
|
-
|
|
3084
|
+
if (typeof component === "object") {
|
|
3085
|
+
component[MEMOIZED] = true;
|
|
3086
|
+
} else {
|
|
3087
|
+
component = { component, [MEMOIZED]: true };
|
|
3088
|
+
}
|
|
3089
|
+
return component;
|
|
2967
3090
|
}
|
|
2968
3091
|
var createElement = createComponent2;
|
|
2969
3092
|
var current_component = [];
|
|
@@ -5827,7 +5950,7 @@ function transpileJSX(jsx2, {
|
|
|
5827
5950
|
|
|
5828
5951
|
// .tmp/src/lilact.jsx
|
|
5829
5952
|
var Lilact2 = {
|
|
5830
|
-
VERSION: "beta.
|
|
5953
|
+
VERSION: "beta.20",
|
|
5831
5954
|
// Configuration
|
|
5832
5955
|
defaultTransitionTimeout: 300,
|
|
5833
5956
|
defaultIsEqual: Object.is,
|
|
@@ -5879,6 +6002,7 @@ export {
|
|
|
5879
6002
|
Lilact2 as Lilact,
|
|
5880
6003
|
Link,
|
|
5881
6004
|
NavLink,
|
|
6005
|
+
Portal,
|
|
5882
6006
|
PropTypes,
|
|
5883
6007
|
Provider,
|
|
5884
6008
|
RootComponent,
|
|
@@ -5902,6 +6026,7 @@ export {
|
|
|
5902
6026
|
createComponent2 as createComponent,
|
|
5903
6027
|
createContext,
|
|
5904
6028
|
createElement,
|
|
6029
|
+
createPortal,
|
|
5905
6030
|
createRoot,
|
|
5906
6031
|
createSyntheticEvent,
|
|
5907
6032
|
current_component,
|