lilact 0.31.6 → 0.31.7

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 (49) hide show
  1. package/dist/lilact.development.js +49 -16
  2. package/dist/lilact.development.js.map +3 -3
  3. package/dist/lilact.development.min.js +23 -23
  4. package/dist/lilact.development.min.js.map +3 -3
  5. package/dist/lilact.production.min.js +23 -23
  6. package/docs/assets/navigation.js +1 -1
  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 +11 -11
  11. package/docs/classes/components.HTMLComponent.html +11 -11
  12. package/docs/classes/components.RootComponent.html +11 -11
  13. package/docs/functions/components.cloneComponent.html +1 -1
  14. package/docs/functions/components.createComponent.html +1 -1
  15. package/docs/functions/components.createPortal.html +1 -1
  16. package/docs/functions/components.createRoot.html +1 -1
  17. package/docs/functions/components.memo.html +1 -1
  18. package/docs/functions/components.render.html +1 -1
  19. package/docs/functions/components.replaceAllComponentInstances.html +1 -1
  20. package/docs/functions/components.replaceComponentEntity.html +1 -1
  21. package/docs/functions/hooks.useCallback.html +2 -2
  22. package/docs/functions/hooks.useEffect.html +1 -1
  23. package/docs/functions/hooks.useImperativeHandle.html +1 -1
  24. package/docs/functions/hooks.useInsertionEffect.html +1 -1
  25. package/docs/functions/hooks.useLayoutEffect.html +1 -1
  26. package/docs/functions/hooks.useMemo.html +1 -1
  27. package/docs/functions/run.lazy.html +10 -1
  28. package/docs/functions/run.require.html +7 -1
  29. package/docs/functions/run.run.html +14 -1
  30. package/docs/functions/run.runScripts.html +8 -1
  31. package/docs/modules/run.html +1 -1
  32. package/docs/static/demos/error-callback.jsx +7 -9
  33. package/docs/static/lilact.development.js +49 -16
  34. package/docs/static/lilact.development.js.map +3 -3
  35. package/docs/static/lilact.development.min.js +23 -23
  36. package/docs/static/lilact.development.min.js.map +3 -3
  37. package/docs/static/lilact.production.min.js +23 -23
  38. package/docs/variables/components.cloneElement.html +1 -1
  39. package/examples/demos/error-callback.jsx +7 -9
  40. package/examples/lilact.development.js +49 -16
  41. package/examples/lilact.development.js.map +3 -3
  42. package/examples/lilact.development.min.js +23 -23
  43. package/examples/lilact.development.min.js.map +3 -3
  44. package/examples/lilact.production.min.js +23 -23
  45. package/package.json +1 -1
  46. package/src/components.jsx +74 -22
  47. package/src/hooks.jsx +6 -6
  48. package/src/run.jsx +62 -6
  49. package/docs/variables/run.required_scripts.html +0 -1
@@ -20,4 +20,4 @@ children.</p>
20
20
  </div><div class="tsd-tag-example"><h4 class="tsd-anchor-link" id="example-1">Example<a href="#example-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><pre><code class="ts"><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-7">panel</span><span class="hl-1"> = &lt;</span><span class="hl-8">Panel</span><span class="hl-1"> </span><span class="hl-8">className</span><span class="hl-1">=</span><span class="hl-2">&quot;compact&quot;</span><span class="hl-1">&gt;</span><span class="hl-5">Old</span><span class="hl-1"> </span><span class="hl-5">content</span><span class="hl-1">&lt;/</span><span class="hl-5">Panel</span><span class="hl-1">&gt;;</span><br/><br/><span class="hl-6">// Existing children are replaced when children are provided.</span><br/><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-7">updatedPanel</span><span class="hl-1"> = </span><span class="hl-0">cloneComponent</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-5">panel</span><span class="hl-1">,</span><br/><span class="hl-1"> { </span><span class="hl-5">className:</span><span class="hl-1"> </span><span class="hl-2">&#39;expanded&#39;</span><span class="hl-1"> },</span><br/><span class="hl-1"> &lt;</span><span class="hl-8">Heading</span><span class="hl-1">&gt;</span><span class="hl-5">New</span><span class="hl-1"> </span><span class="hl-5">content</span><span class="hl-1">&lt;/</span><span class="hl-5">Heading</span><span class="hl-1">&gt;</span><br/><span class="hl-1">);</span>
21
21
  </code><button type="button">Copy</button></pre>
22
22
 
23
- </div></div></li></ul></li></ul></div><aside class="tsd-sources"><ul><li>Defined in components.jsx:1520</li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">Lilact</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
23
+ </div></div></li></ul></li></ul></div><aside class="tsd-sources"><ul><li>Defined in components.jsx:1572</li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">Lilact</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
@@ -5,7 +5,7 @@ export default function() {
5
5
  Press to get Error! (With Curly Brackets)
6
6
  </button>
7
7
  <br/><br/>
8
- <button onClick={()=>doUnknown()}>
8
+ <button onClick={ () => doUnknown () }>
9
9
  Press to get Error! (Without Curly Brackets)
10
10
  </button>
11
11
 
@@ -16,14 +16,12 @@ export default function() {
16
16
  JS runtimes currently lack a consistent reporting mechanism for errors produced in eval,
17
17
  and as Lilact runs the transpiled JSX in eval, tracing errors has its own difficulties.
18
18
  <br/><br/>
19
- At the moment things work pretty nice and errors are tracked to the JSX scripts in
20
- {" "}<b>Firefox</b>{" "}and{" "}<b>Chrome</b>{" "}, but{" "}<b>Safari</b>{" "}
21
- has problems sometimes, as it drops the eval frame data on async or deferred calls.
22
- <br/><br/>
23
- Lilact has a tracking mechanism to overcome this, but for the sake of efficiency,
24
- it is block-based and only locates the code that is in {" {} "} blocks. As a result, the callbacks
25
- should be wrapped in a {" {} "} to be tracable in Safari. If not, it works,
26
- but it is not possible to display the exact location of some errors in Safari.</p>
19
+ Lilact has a tracing mechanism to overcome this, but for the sake of efficiency,
20
+ it is block-based and only locates the code that is in {" {} "} blocks. As a result, the
21
+ arrow callbacks should be wrapped in a {" {} "} (and return result if any) or be defined
22
+ somewhere else in the code (like useCallback) and only referenced from XML to be traceable
23
+ in all situations. If not, it works, but it is not possible to display the exact location
24
+ of some errors.</p>
27
25
  </center>
28
26
 
29
27
  }
@@ -2379,6 +2379,21 @@ function getComponentEntity(entity) {
2379
2379
  return entity?.[MEMOIZED] ? entity.component : entity;
2380
2380
  }
2381
2381
  var hotEntityAliases = /* @__PURE__ */ new Map();
2382
+ var hotEntityCacheTokens = /* @__PURE__ */ new WeakMap();
2383
+ function getHotEntityCacheToken(entity) {
2384
+ entity = getComponentEntity(entity);
2385
+ if (typeof entity !== "function") {
2386
+ return entity;
2387
+ }
2388
+ let token2 = hotEntityCacheTokens.get(entity);
2389
+ if (!token2) {
2390
+ const resolved = resolveHotEntity(entity);
2391
+ token2 = hotEntityCacheTokens.get(resolved) || {};
2392
+ hotEntityCacheTokens.set(entity, token2);
2393
+ hotEntityCacheTokens.set(resolved, token2);
2394
+ }
2395
+ return token2;
2396
+ }
2382
2397
  function resolveHotEntity(entity) {
2383
2398
  entity = getComponentEntity(entity);
2384
2399
  const visited = /* @__PURE__ */ new Set();
@@ -2434,6 +2449,9 @@ function replaceComponentEntity(componentCore, nextEntity) {
2434
2449
  }
2435
2450
  const oldEntity = getComponentEntity(componentCore.entity);
2436
2451
  const newEntity = resolveHotEntity(nextEntity);
2452
+ const cacheToken = hotEntityCacheTokens.get(oldEntity) || hotEntityCacheTokens.get(newEntity) || {};
2453
+ hotEntityCacheTokens.set(oldEntity, cacheToken);
2454
+ hotEntityCacheTokens.set(newEntity, cacheToken);
2437
2455
  if (oldEntity === newEntity) {
2438
2456
  return true;
2439
2457
  }
@@ -2463,6 +2481,9 @@ function replaceAllComponentInstances(oldEntity, newEntity) {
2463
2481
  if (oldEntity === newEntity) {
2464
2482
  return 0;
2465
2483
  }
2484
+ const cacheToken = hotEntityCacheTokens.get(oldEntity) || hotEntityCacheTokens.get(newEntity) || {};
2485
+ hotEntityCacheTokens.set(oldEntity, cacheToken);
2486
+ hotEntityCacheTokens.set(newEntity, cacheToken);
2466
2487
  hotEntityAliases.set(oldEntity, newEntity);
2467
2488
  const instances = componentInstances.get(oldEntity);
2468
2489
  if (!instances) {
@@ -2576,14 +2597,18 @@ var ComponentCore = class {
2576
2597
  if (do_rerender) {
2577
2598
  if (true) {
2578
2599
  if (this.entity?.propTypes) {
2579
- PropTypes.checkPropTypes(this.entity.propTypes, this.props, "prop", this.entity.name);
2600
+ PropTypes.checkPropTypes(this.entity.propTypes, next_props, "prop", this.entity.name);
2580
2601
  } else if (this.component?.propTypes) {
2581
- PropTypes.checkPropTypes(this.component.propTypes, this.props, "prop", this.component.name);
2602
+ PropTypes.checkPropTypes(this.component.propTypes, next_props, "prop", this.component.name);
2582
2603
  }
2583
2604
  }
2584
2605
  if (typeof next_state === "function") next_state = next_state(this.state);
2585
- if (this.component.constructor.defaultProps) {
2586
- next_props = { ...this.component.constructor.defaultProps, ...next_props };
2606
+ const defaultProps = this.entity?.defaultProps || this.component?.constructor?.defaultProps;
2607
+ if (defaultProps) {
2608
+ next_props = {
2609
+ ...defaultProps,
2610
+ ...next_props || {}
2611
+ };
2587
2612
  }
2588
2613
  if (this?.parent?.component?.context || this?.parent?.component?.getChildContext) {
2589
2614
  this.context = { ...this.parent.component.context, ...this.parent.component.getChildContext?.() };
@@ -2997,11 +3022,22 @@ function prepareCore(parent, core) {
2997
3022
  try {
2998
3023
  parent.cache ?? (parent.cache = new ComponentCache(parent));
2999
3024
  const isText = core[TEXT2] !== void 0;
3000
- const key = isText ? ":text:" : core.props?.key;
3001
- const entity = isText || core instanceof ComponentCore ? void 0 : core.entity;
3025
+ const isExistingCore = core instanceof ComponentCore;
3026
+ const entity = isText || isExistingCore ? void 0 : resolveHotEntity(core.entity);
3027
+ const hasExplicitKey = !isText && core.props && core.props.key !== void 0 && core.props.key !== null;
3028
+ let key;
3029
+ if (isText) {
3030
+ key = ":text:";
3031
+ } else if (hasExplicitKey) {
3032
+ key = core.props.key;
3033
+ } else if (typeof entity === "function") {
3034
+ key = getHotEntityCacheToken(entity);
3035
+ } else {
3036
+ key = entity;
3037
+ }
3002
3038
  return parent.cache.pick(
3003
3039
  key,
3004
- () => isText || core instanceof ComponentCore ? core : constructFunc(core, parent)[CORE],
3040
+ () => isText || isExistingCore ? core : constructFunc(core, parent)[CORE],
3005
3041
  entity
3006
3042
  );
3007
3043
  } catch (e) {
@@ -3509,7 +3545,7 @@ function useState(initialValue) {
3509
3545
  }
3510
3546
  return [hk.value, hk.set_func];
3511
3547
  }
3512
- function useCallback(callback, deps = void 0) {
3548
+ function useCallback(callback, deps) {
3513
3549
  if (deps !== void 0 && !Array.isArray(deps) && deps !== null && typeof deps !== "object") {
3514
3550
  throw new Error("Callback dependencies must be an array, object or omitted.");
3515
3551
  }
@@ -3601,7 +3637,7 @@ function useRef(initialValue = null) {
3601
3637
  }
3602
3638
  return hk;
3603
3639
  }
3604
- async function useLayoutEffect(effect, deps = void 0) {
3640
+ async function useLayoutEffect(effect, deps) {
3605
3641
  if (deps !== void 0 && !Array.isArray(deps) && deps !== null && typeof deps !== "object") {
3606
3642
  throw new Error("Layout effect dependencies must be an array, object or omitted.");
3607
3643
  }
@@ -3620,7 +3656,7 @@ async function useLayoutEffect(effect, deps = void 0) {
3620
3656
  NATIVE_TIMERS.clearTimeout(lilact_default.effect_timeout);
3621
3657
  lilact_default.effect_timeout = NATIVE_TIMERS.setTimeout(lilact_default.processEffects, 0);
3622
3658
  }
3623
- async function useEffect(effect, deps = void 0) {
3659
+ async function useEffect(effect, deps) {
3624
3660
  if (deps !== void 0 && !Array.isArray(deps) && deps !== null && typeof deps !== "object") {
3625
3661
  throw new Error("Effect dependencies must be an array, object or omitted.");
3626
3662
  }
@@ -3639,7 +3675,7 @@ async function useEffect(effect, deps = void 0) {
3639
3675
  NATIVE_TIMERS.clearTimeout(lilact_default.effect_timeout);
3640
3676
  lilact_default.effect_timeout = NATIVE_TIMERS.setTimeout(lilact_default.processEffects, 0);
3641
3677
  }
3642
- async function useInsertionEffect(effect, deps = void 0) {
3678
+ async function useInsertionEffect(effect, deps) {
3643
3679
  if (deps !== void 0 && !Array.isArray(deps) && deps !== null && typeof deps !== "object") {
3644
3680
  throw new Error("Insertion effect dependencies must be an array, object, or omitted.");
3645
3681
  }
@@ -3658,7 +3694,7 @@ async function useInsertionEffect(effect, deps = void 0) {
3658
3694
  NATIVE_TIMERS.clearTimeout(lilact_default.effect_timeout);
3659
3695
  lilact_default.effect_timeout = NATIVE_TIMERS.setTimeout(lilact_default.processEffects, 0);
3660
3696
  }
3661
- function useMemo(factory, deps = void 0) {
3697
+ function useMemo(factory, deps) {
3662
3698
  if (deps !== void 0 && !Array.isArray(deps) && deps !== null && typeof deps !== "object") {
3663
3699
  throw new Error("Memo dependencies must be an array or omitted.");
3664
3700
  }
@@ -3736,7 +3772,7 @@ function useDeferredValue(value, initialValue) {
3736
3772
  }, [value]);
3737
3773
  return deferred;
3738
3774
  }
3739
- function useImperativeHandle(ref, factory, deps = void 0) {
3775
+ function useImperativeHandle(ref, factory, deps) {
3740
3776
  if (deps !== void 0 && ref?.deps !== void 0 && shallowEqual(deps, ref.deps)) return;
3741
3777
  ref.deps = deps;
3742
3778
  if (typeof ref?.current !== "object") {
@@ -3823,10 +3859,7 @@ function createModule(path2, {
3823
3859
  mappings: [],
3824
3860
  meta: {},
3825
3861
  exports: {},
3826
- // True only after the module has been successfully evaluated.
3827
3862
  loaded: false,
3828
- // The promise for the request currently loading this resource.
3829
- // This is deliberately stored on the module to deduplicate requests.
3830
3863
  request: void 0,
3831
3864
  error: void 0
3832
3865
  };