lilact 0.30.0 → 0.30.1

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 (43) hide show
  1. package/dist/lilact.development.js +100 -11
  2. package/dist/lilact.development.js.map +3 -3
  3. package/dist/lilact.development.min.js +25 -25
  4. package/dist/lilact.development.min.js.map +3 -3
  5. package/dist/lilact.production.min.js +25 -25
  6. package/docs/assets/hierarchy.js +1 -1
  7. package/docs/assets/navigation.js +1 -1
  8. package/docs/assets/search.js +1 -1
  9. package/docs/classes/accessories.ErrorBoundary.html +8 -8
  10. package/docs/classes/accessories.Suspense.html +7 -7
  11. package/docs/classes/components.Component.html +11 -11
  12. package/docs/classes/components.HTMLComponent.html +11 -11
  13. package/docs/classes/components.RootComponent.html +11 -11
  14. package/docs/functions/components.cloneComponent.html +1 -1
  15. package/docs/functions/components.createComponent.html +1 -1
  16. package/docs/functions/components.createPortal.html +1 -1
  17. package/docs/functions/components.createRoot.html +1 -1
  18. package/docs/functions/components.hotReloadRoot.html +1 -1
  19. package/docs/functions/components.memo.html +1 -1
  20. package/docs/functions/components.render.html +1 -1
  21. package/docs/functions/components.replaceAllComponentInstances.html +1 -0
  22. package/docs/functions/components.replaceComponentEntity.html +1 -1
  23. package/docs/functions/run.lazy.html +1 -1
  24. package/docs/functions/run.run.html +1 -1
  25. package/docs/functions/run.runScripts.html +1 -1
  26. package/docs/hierarchy.html +1 -1
  27. package/docs/modules/components.html +1 -1
  28. package/docs/static/index.html +1 -1
  29. package/docs/static/lilact.development.js +100 -11
  30. package/docs/static/lilact.development.js.map +3 -3
  31. package/docs/static/lilact.development.min.js +25 -25
  32. package/docs/static/lilact.development.min.js.map +3 -3
  33. package/docs/static/lilact.production.min.js +25 -25
  34. package/docs/variables/components.cloneElement.html +1 -1
  35. package/examples/index.html +1 -1
  36. package/examples/lilact.development.js +100 -11
  37. package/examples/lilact.development.js.map +3 -3
  38. package/examples/lilact.development.min.js +25 -25
  39. package/examples/lilact.development.min.js.map +3 -3
  40. package/examples/lilact.production.min.js +25 -25
  41. package/package.json +1 -1
  42. package/src/components.jsx +115 -21
  43. package/src/run.jsx +85 -53
@@ -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:1403</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:1497</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>
@@ -227,7 +227,7 @@ function App()
227
227
  ['priorities.jsx', 'Effect Priorities'],
228
228
  ['forwardref.jsx', 'ForwardRef with Function Refs ( forwardRef, useImperativeHandle, useRef )'],
229
229
  ['memo.jsx', 'Component Memoization ( memo, useState )'],
230
- ['lazy.jsx', 'Lazy Loading ( lazy, require, Suspene, Spinner )'],
230
+ //['lazy.jsx', 'Lazy Loading ( lazy, require, Suspene, Spinner )'],
231
231
  ['proptypes.jsx', 'PropTypes Validation'],
232
232
  ['legacy-context.jsx', 'Legacy Context API'],
233
233
  ['redux.jsx', 'Redux and Dispatch ( Provider, useSelector, useDispatch, connect ), redux:( createStore )'],
@@ -2358,6 +2358,7 @@ __export(components_exports, {
2358
2358
  passive_effects: () => passive_effects,
2359
2359
  processEffects: () => processEffects,
2360
2360
  render: () => render,
2361
+ replaceAllComponentInstances: () => replaceAllComponentInstances,
2361
2362
  replaceComponentEntity: () => replaceComponentEntity,
2362
2363
  roots: () => roots,
2363
2364
  special_attributes: () => special_attributes,
@@ -2370,6 +2371,46 @@ var SVG_NS = "http://www.w3.org/2000/svg";
2370
2371
  function getComponentEntity(entity) {
2371
2372
  return entity?.[MEMOIZED] ? entity.component : entity;
2372
2373
  }
2374
+ var componentInstances = /* @__PURE__ */ new Map();
2375
+ function registerComponentCore(core) {
2376
+ const entity = getComponentEntity(core.entity);
2377
+ if (typeof entity !== "function") return;
2378
+ let instances = componentInstances.get(entity);
2379
+ if (!instances) {
2380
+ instances = /* @__PURE__ */ new Set();
2381
+ componentInstances.set(entity, instances);
2382
+ }
2383
+ instances.add(core);
2384
+ core.registered_entity = entity;
2385
+ }
2386
+ function unregisterComponentCore(core) {
2387
+ const entity = core.registered_entity;
2388
+ if (!entity) return;
2389
+ const instances = componentInstances.get(entity);
2390
+ if (instances) {
2391
+ instances.delete(core);
2392
+ if (instances.size === 0) {
2393
+ componentInstances.delete(entity);
2394
+ }
2395
+ }
2396
+ delete core.registered_entity;
2397
+ }
2398
+ function moveComponentCore(core, oldEntity, newEntity) {
2399
+ const oldInstances = componentInstances.get(oldEntity);
2400
+ if (oldInstances) {
2401
+ oldInstances.delete(core);
2402
+ if (oldInstances.size === 0) {
2403
+ componentInstances.delete(oldEntity);
2404
+ }
2405
+ }
2406
+ let newInstances = componentInstances.get(newEntity);
2407
+ if (!newInstances) {
2408
+ newInstances = /* @__PURE__ */ new Set();
2409
+ componentInstances.set(newEntity, newInstances);
2410
+ }
2411
+ newInstances.add(core);
2412
+ core.registered_entity = newEntity;
2413
+ }
2373
2414
  function replaceComponentEntity(componentCore, nextEntity) {
2374
2415
  if (!componentCore || typeof nextEntity !== "function") {
2375
2416
  return false;
@@ -2383,19 +2424,38 @@ function replaceComponentEntity(componentCore, nextEntity) {
2383
2424
  if (!component) {
2384
2425
  return false;
2385
2426
  }
2386
- const oldIsClass = isClass(oldEntity);
2387
- const newIsClass = isClass(newEntity);
2388
- if (oldIsClass !== newIsClass) {
2427
+ if (typeof oldEntity !== "function" || typeof newEntity !== "function" || isClass(oldEntity) !== isClass(newEntity)) {
2389
2428
  return false;
2390
2429
  }
2391
- if (newIsClass) {
2430
+ if (isClass(newEntity)) {
2392
2431
  Object.setPrototypeOf(component, newEntity.prototype);
2393
2432
  } else {
2394
- component.render = newEntity;
2433
+ component.render = newEntity.bind(component);
2395
2434
  }
2396
2435
  componentCore.entity = newEntity;
2436
+ moveComponentCore(componentCore, oldEntity, newEntity);
2397
2437
  return true;
2398
2438
  }
2439
+ function replaceAllComponentInstances(oldEntity, newEntity) {
2440
+ oldEntity = getComponentEntity(oldEntity);
2441
+ newEntity = getComponentEntity(newEntity);
2442
+ if (typeof oldEntity !== "function" || typeof newEntity !== "function") {
2443
+ return 0;
2444
+ }
2445
+ const instances = componentInstances.get(oldEntity);
2446
+ if (!instances) {
2447
+ return 0;
2448
+ }
2449
+ let count = 0;
2450
+ for (const core of [...instances]) {
2451
+ if (!replaceComponentEntity(core, newEntity)) {
2452
+ continue;
2453
+ }
2454
+ core.apply(core.props, core.state);
2455
+ count++;
2456
+ }
2457
+ return count;
2458
+ }
2399
2459
  var ComponentCache = class {
2400
2460
  constructor(owner) {
2401
2461
  __publicField(this, "owner");
@@ -2412,7 +2472,7 @@ var ComponentCache = class {
2412
2472
  bucket[IDX]++;
2413
2473
  const oldEntity = getComponentEntity(componentCore.entity);
2414
2474
  const newEntity = getComponentEntity(nextEntity);
2415
- const incompatible = typeof oldEntity === "function" && typeof newEntity === "function" && isClass(oldEntity) !== isClass(newEntity);
2475
+ const incompatible = typeof oldEntity !== typeof newEntity || typeof oldEntity === "function" && isClass(oldEntity) !== isClass(newEntity);
2416
2476
  if (incompatible) {
2417
2477
  componentCore = construct_func();
2418
2478
  } else if (newEntity) {
@@ -2603,6 +2663,7 @@ var ComponentCore = class {
2603
2663
  }
2604
2664
  }
2605
2665
  async cleanup() {
2666
+ unregisterComponentCore(this);
2606
2667
  try {
2607
2668
  const promises = [];
2608
2669
  if (this.props?.ref) {
@@ -2887,6 +2948,7 @@ function constructFunc(core, parent) {
2887
2948
  throw new Error("Error in constructing component.");
2888
2949
  }
2889
2950
  comp[CORE].entity = entity;
2951
+ registerComponentCore(comp[CORE]);
2890
2952
  if (core.container) {
2891
2953
  comp[CORE].container = core.container;
2892
2954
  }
@@ -3173,12 +3235,16 @@ function createRoot(element) {
3173
3235
  root.cleanup();
3174
3236
  element.innerHTML = "";
3175
3237
  }
3238
+ },
3239
+ getCore() {
3240
+ console.log(root, root[CORE]);
3241
+ return root[CORE];
3176
3242
  }
3177
3243
  };
3178
3244
  }
3179
3245
  function hotReloadRoot(rootCore, nextEntity, props) {
3180
3246
  if (!rootCore || !rootCore.component) {
3181
- throw new Error("Invalid Lilact root component.");
3247
+ throw new Error("Invalid root component.");
3182
3248
  }
3183
3249
  const replaced = replaceComponentEntity(rootCore, nextEntity);
3184
3250
  if (!replaced) {
@@ -3186,7 +3252,7 @@ function hotReloadRoot(rootCore, nextEntity, props) {
3186
3252
  "Cannot hot-reload the root from a class component to a function component, or vice versa."
3187
3253
  );
3188
3254
  }
3189
- rootCore.apply(props === void 0 ? rootCore.props : props);
3255
+ rootCore.apply(props === void 0 ? rootCore.props : { ...rootCore.props, ...props });
3190
3256
  return rootCore;
3191
3257
  }
3192
3258
  function createPortal(children, element) {
@@ -3828,7 +3894,10 @@ function require2(path2) {
3828
3894
  return loadModule(path2, options2);
3829
3895
  }
3830
3896
  function makeImportsObject(mod, options2 = {}) {
3831
- mod.importsObject = {};
3897
+ mod.importsObject ?? (mod.importsObject = {});
3898
+ for (const key of Object.keys(mod.importsObject)) {
3899
+ delete mod.importsObject[key];
3900
+ }
3832
3901
  for (const path2 in mod.meta.imports) {
3833
3902
  const imps = mod.meta.imports[path2];
3834
3903
  const exps = loadModule(path2, {
@@ -3848,7 +3917,7 @@ function makeImportsObject(mod, options2 = {}) {
3848
3917
  for (const i2 of imps.import_defaults) {
3849
3918
  if (!Object.prototype.hasOwnProperty.call(exps, "default")) {
3850
3919
  throw new Error(
3851
- `Imported module does not export a default.`
3920
+ "Imported module does not export a default."
3852
3921
  );
3853
3922
  }
3854
3923
  mod.importsObject[i2] = exps.default;
@@ -3857,9 +3926,26 @@ function makeImportsObject(mod, options2 = {}) {
3857
3926
  mod.importsObject[i2] = { ...exps };
3858
3927
  }
3859
3928
  }
3929
+ return mod.importsObject;
3930
+ }
3931
+ function exportEntries(value) {
3932
+ return value && typeof value === "object" ? value : { default: value };
3933
+ }
3934
+ function replaceReloadedExports(previousExports2, nextExports2) {
3935
+ if (!previousExports2) return;
3936
+ const oldExports = exportEntries(previousExports2);
3937
+ const newExports = exportEntries(nextExports2);
3938
+ for (const name of Object.keys(oldExports)) {
3939
+ const oldExport = oldExports[name];
3940
+ const newExport = newExports[name];
3941
+ if (typeof oldExport === "function" && typeof newExport === "function") {
3942
+ lilact_default.replaceAllComponentInstances(oldExport, newExport);
3943
+ }
3944
+ }
3860
3945
  }
3861
3946
  function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, options = {}) {
3862
3947
  let module = required_scripts[path];
3948
+ const previousExports = module?.loaded ? module.exports : void 0;
3863
3949
  if (!module) {
3864
3950
  module = createModule(path, {
3865
3951
  code: jsx
@@ -3903,7 +3989,9 @@ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, options = {})
3903
3989
  globalThis.Fragment = lilact_default.Fragment;
3904
3990
  const result = eval(processed);
3905
3991
  module.loaded = true;
3906
- return isEmpty(module.exports) ? result : module.exports;
3992
+ const nextExports = isEmpty(module.exports) ? result : module.exports;
3993
+ replaceReloadedExports(previousExports, nextExports);
3994
+ return nextExports;
3907
3995
  } catch (value) {
3908
3996
  const error2 = report(value, path);
3909
3997
  error2.sourcePhase ?? (error2.sourcePhase = "runtime");
@@ -7158,6 +7246,7 @@ export {
7158
7246
  releaseSyntheticEvent,
7159
7247
  releaseTimers,
7160
7248
  render,
7249
+ replaceAllComponentInstances,
7161
7250
  replaceComponentEntity,
7162
7251
  require2 as require,
7163
7252
  required_scripts,