lilact 0.19.0 → 0.21.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.
Files changed (48) hide show
  1. package/README.md +1 -1
  2. package/dist/lilact.development.js +139 -42
  3. package/dist/lilact.development.js.map +2 -2
  4. package/dist/lilact.development.min.js +16 -16
  5. package/dist/lilact.development.min.js.map +3 -3
  6. package/dist/lilact.production.min.js +17 -17
  7. package/docs/assets/search.js +1 -1
  8. package/docs/classes/accessories.ErrorBoundary.html +8 -8
  9. package/docs/classes/accessories.Suspense.html +7 -7
  10. package/docs/classes/components.Component.html +13 -11
  11. package/docs/classes/components.HTMLComponent.html +11 -11
  12. package/docs/classes/components.RootComponent.html +11 -11
  13. package/docs/functions/components.createComponent.html +1 -1
  14. package/docs/functions/components.createPortal.html +1 -1
  15. package/docs/functions/components.createRoot.html +1 -1
  16. package/docs/functions/components.memo.html +1 -1
  17. package/docs/functions/components.render.html +1 -1
  18. package/docs/functions/misc.deepEqual.html +1 -1
  19. package/docs/functions/misc.forwardRef.html +1 -1
  20. package/docs/functions/misc.getComponentByPointer.html +1 -1
  21. package/docs/functions/misc.isAsync.html +1 -1
  22. package/docs/functions/misc.isClass.html +1 -1
  23. package/docs/functions/misc.isEmpty.html +1 -1
  24. package/docs/functions/misc.isError.html +1 -1
  25. package/docs/functions/misc.isThenable.html +1 -1
  26. package/docs/functions/misc.shallowEqual.html +1 -1
  27. package/docs/functions/misc.toBool.html +1 -1
  28. package/docs/functions/timers.timeoutPromise.html +20 -11
  29. package/docs/index.html +1 -1
  30. package/docs/static/demos/legacy-context.jsx +79 -0
  31. package/docs/static/index.html +1 -0
  32. package/docs/static/lilact.development.js +139 -42
  33. package/docs/static/lilact.development.js.map +2 -2
  34. package/docs/static/lilact.development.min.js +16 -16
  35. package/docs/static/lilact.development.min.js.map +3 -3
  36. package/docs/static/lilact.production.min.js +17 -17
  37. package/docs/variables/misc.Children.html +19 -10
  38. package/examples/demos/legacy-context.jsx +79 -0
  39. package/examples/index.html +1 -0
  40. package/examples/lilact.development.js +139 -42
  41. package/examples/lilact.development.js.map +2 -2
  42. package/examples/lilact.development.min.js +16 -16
  43. package/examples/lilact.development.min.js.map +3 -3
  44. package/examples/lilact.production.min.js +17 -17
  45. package/package.json +1 -1
  46. package/src/components.jsx +13 -12
  47. package/src/lilact.jsx +1 -1
  48. package/src/misc.jsx +164 -46
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
 
@@ -2076,43 +2076,143 @@ function Portal({ children, view }) {
2076
2076
  Portal.displayName = "Portal";
2077
2077
  var Children = {
2078
2078
  /**
2079
- * Returns the only child from a children collection.
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`.
2101
+ *
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.
2080
2124
  *
2081
- * @param children - The children to read.
2082
- * @returns The single child (or null/exception based on the number of children).
2125
+ * @param {Iterable<any>} children
2126
+ * @returns {any}
2083
2127
  */
2084
2128
  only(children) {
2085
- var _a, _b;
2086
- children = [...children];
2087
- let i2 = 0;
2088
- while (i2 < children.length) {
2089
- if (((_b = (_a = children[i2]) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name) === "Array") {
2090
- children.splice(i2, 1, ...children[i2]);
2091
- i2--;
2092
- } else if (children[i2] === null || children[i2] === void 0) {
2093
- children.splice(i2, 1);
2094
- i2--;
2095
- }
2096
- if (i2 > 1) {
2097
- throw new Error("No child or child is not the only one");
2098
- }
2099
- 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
+ );
2100
2134
  }
2101
- if (children.length === 1) return children[0];
2135
+ return arr[0];
2102
2136
  },
2103
2137
  /**
2104
- * Converts component children into a flat array.
2138
+ * Maps over children (after flattening & omitting nil).
2105
2139
  *
2106
- * @param children - The children to convert.
2107
- * @returns An array representation of the children.
2140
+ * @param {Iterable<any>} children
2141
+ * @param {(child:any, index:number)=>any} fn
2142
+ * @returns {Array<any>}
2108
2143
  */
2109
- toArray(children) {
2110
- var _a;
2111
- if (children) {
2112
- if (((_a = children == null ? void 0 : children.constructor) == null ? void 0 : _a.name) === "Array") return [...children];
2113
- return [children];
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
+ }
2114
2191
  }
2115
- return [];
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;
2116
2216
  }
2117
2217
  };
2118
2218
  var forwardRef = (render2) => {
@@ -2296,7 +2396,7 @@ var ComponentCore = class {
2296
2396
  */
2297
2397
  // TODO: should componentDidUpdate be called after arranging/appending the outlet or before?
2298
2398
  apply(next_props = this.props, next_state = this.next_state || this.state) {
2299
- var _a, _b, _c, _d, _e;
2399
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2300
2400
  let do_rerender = true;
2301
2401
  if (this.outlet && (this == null ? void 0 : this[MEMOIZED])) {
2302
2402
  if (shallowEqual(this.props, next_props, "children") && shallowEqual((_a = this.props) == null ? void 0 : _a.children, next_props == null ? void 0 : next_props.children)) {
@@ -2315,6 +2415,12 @@ var ComponentCore = class {
2315
2415
  if (this.component.constructor.defaultProps) {
2316
2416
  next_props = { ...this.component.constructor.defaultProps, ...next_props };
2317
2417
  }
2418
+ if (((_e = (_d = this == null ? void 0 : this.parent) == null ? void 0 : _d.component) == null ? void 0 : _e.context) || ((_g = (_f = this == null ? void 0 : this.parent) == null ? void 0 : _f.component) == null ? void 0 : _g.getChildContext)) {
2419
+ this.context = { ...this.parent.component.context, ...(_i = (_h = this.parent.component).getChildContext) == null ? void 0 : _i.call(_h) };
2420
+ if (this.component.constructor.contextTypes) {
2421
+ PropTypes.checkPropTypes(this.component.constructor.contextTypes, this.context, "context", this.entity.name);
2422
+ }
2423
+ }
2318
2424
  if (this.component.shouldComponentUpdate && !this.component.shouldComponentUpdate(next_state, next_props, this.context)) return;
2319
2425
  if (typeof this.entity === "string") {
2320
2426
  if (!(this.element instanceof Element)) {
@@ -2366,7 +2472,7 @@ var ComponentCore = class {
2366
2472
  if (this == null ? void 0 : this.portal) {
2367
2473
  this.element = this.portal;
2368
2474
  }
2369
- if (((_e = (_d = this.outlet) == null ? void 0 : _d.constructor) == null ? void 0 : _e.name) !== "Array") {
2475
+ if (((_k = (_j = this.outlet) == null ? void 0 : _j.constructor) == null ? void 0 : _k.name) !== "Array") {
2370
2476
  this.outlet = [this.outlet];
2371
2477
  }
2372
2478
  this.outlet = [...this.outlet];
@@ -2885,20 +2991,11 @@ var Component = class {
2885
2991
  componentWillUnmount () {}
2886
2992
  getSnapshotBeforeUpdate (prevProps, prevState) {}
2887
2993
  shouldComponentUpdate (nextProps, nextState) {}
2994
+ getChildContext()
2888
2995
 
2889
2996
  static getDerivedStateFromError (error) {}
2890
2997
  static getDerivedStateFromProps (props, state) {}
2891
-
2892
-
2893
- */
2894
- /* // todo: maybe
2895
- static get contextType() { }
2896
- static set contextType(ctxt) { }
2897
-
2898
- static get childContextTypes() {}
2899
- static set childContextTypes(ctxt) { }
2900
-
2901
- getChildContext()
2998
+ static contextType
2902
2999
  */
2903
3000
  };
2904
3001
  var HTMLComponent = class extends Component {
@@ -5850,7 +5947,7 @@ function transpileJSX(jsx2, {
5850
5947
 
5851
5948
  // .tmp/src/lilact.jsx
5852
5949
  var Lilact2 = {
5853
- VERSION: "beta.19",
5950
+ VERSION: "beta.21",
5854
5951
  // Configuration
5855
5952
  defaultTransitionTimeout: 300,
5856
5953
  defaultIsEqual: Object.is,