lilact 0.29.3 → 0.30.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 (41) hide show
  1. package/dist/lilact.development.js +50 -58
  2. package/dist/lilact.development.js.map +2 -2
  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/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 -0
  19. package/docs/functions/components.memo.html +1 -1
  20. package/docs/functions/components.render.html +1 -1
  21. package/docs/functions/components.replaceComponentEntity.html +1 -0
  22. package/docs/functions/run.lazy.html +1 -1
  23. package/docs/functions/run.runScripts.html +1 -1
  24. package/docs/hierarchy.html +1 -1
  25. package/docs/modules/components.html +1 -1
  26. package/docs/static/lilact.development.js +50 -58
  27. package/docs/static/lilact.development.js.map +2 -2
  28. package/docs/static/lilact.development.min.js +23 -23
  29. package/docs/static/lilact.development.min.js.map +3 -3
  30. package/docs/static/lilact.production.min.js +23 -23
  31. package/docs/variables/components.cloneElement.html +1 -1
  32. package/examples/lilact.development.js +50 -58
  33. package/examples/lilact.development.js.map +2 -2
  34. package/examples/lilact.development.min.js +23 -23
  35. package/examples/lilact.development.min.js.map +3 -3
  36. package/examples/lilact.production.min.js +23 -23
  37. package/package.json +1 -1
  38. package/src/components.jsx +103 -79
  39. package/src/jsx.js +7 -32
  40. package/src/lilact.jsx +1 -1
  41. package/src/run.jsx +1 -6
@@ -2350,6 +2350,7 @@ __export(components_exports, {
2350
2350
  current_component: () => current_component,
2351
2351
  effect_timeout: () => effect_timeout,
2352
2352
  events_set: () => events_set,
2353
+ hotReloadRoot: () => hotReloadRoot,
2353
2354
  insertion_effects: () => insertion_effects,
2354
2355
  layout_effects: () => layout_effects,
2355
2356
  length_css_attributes_set: () => length_css_attributes_set,
@@ -2357,6 +2358,7 @@ __export(components_exports, {
2357
2358
  passive_effects: () => passive_effects,
2358
2359
  processEffects: () => processEffects,
2359
2360
  render: () => render,
2361
+ replaceComponentEntity: () => replaceComponentEntity,
2360
2362
  roots: () => roots,
2361
2363
  special_attributes: () => special_attributes,
2362
2364
  update_cbs: () => update_cbs,
@@ -2368,15 +2370,18 @@ var SVG_NS = "http://www.w3.org/2000/svg";
2368
2370
  function getComponentEntity(entity) {
2369
2371
  return entity?.[MEMOIZED] ? entity.component : entity;
2370
2372
  }
2371
- function replaceComponentEntity(comp, nextEntity) {
2372
- const core = comp?.[CORE];
2373
- if (!core || typeof nextEntity !== "function") {
2374
- return;
2373
+ function replaceComponentEntity(componentCore, nextEntity) {
2374
+ if (!componentCore || typeof nextEntity !== "function") {
2375
+ return false;
2375
2376
  }
2376
- const oldEntity = getComponentEntity(core.entity);
2377
+ const oldEntity = getComponentEntity(componentCore.entity);
2377
2378
  const newEntity = getComponentEntity(nextEntity);
2378
2379
  if (oldEntity === newEntity) {
2379
- return;
2380
+ return true;
2381
+ }
2382
+ const component = componentCore.component;
2383
+ if (!component) {
2384
+ return false;
2380
2385
  }
2381
2386
  const oldIsClass = isClass(oldEntity);
2382
2387
  const newIsClass = isClass(newEntity);
@@ -2384,11 +2389,11 @@ function replaceComponentEntity(comp, nextEntity) {
2384
2389
  return false;
2385
2390
  }
2386
2391
  if (newIsClass) {
2387
- Object.setPrototypeOf(comp, newEntity.prototype);
2392
+ Object.setPrototypeOf(component, newEntity.prototype);
2388
2393
  } else {
2389
- comp.render = newEntity.bind(comp);
2394
+ component.render = newEntity;
2390
2395
  }
2391
- core.entity = newEntity;
2396
+ componentCore.entity = newEntity;
2392
2397
  return true;
2393
2398
  }
2394
2399
  var ComponentCache = class {
@@ -2400,36 +2405,34 @@ var ComponentCache = class {
2400
2405
  this.owner = owner;
2401
2406
  }
2402
2407
  pick(key, construct_func, nextEntity) {
2403
- var _a;
2404
- let comp;
2408
+ let componentCore;
2405
2409
  let bucket = this.current_map.get(key);
2406
- const reusable = bucket && bucket.length > bucket[IDX];
2407
- if (reusable) {
2408
- comp = bucket[bucket[IDX]];
2410
+ if (bucket && bucket.length > bucket[IDX]) {
2411
+ componentCore = bucket[bucket[IDX]];
2409
2412
  bucket[IDX]++;
2410
- const oldEntity = getComponentEntity(comp?.[CORE]?.entity);
2413
+ const oldEntity = getComponentEntity(componentCore.entity);
2411
2414
  const newEntity = getComponentEntity(nextEntity);
2412
2415
  const incompatible = typeof oldEntity === "function" && typeof newEntity === "function" && isClass(oldEntity) !== isClass(newEntity);
2413
2416
  if (incompatible) {
2414
- comp = construct_func();
2415
- } else {
2416
- replaceComponentEntity(comp, nextEntity);
2417
+ componentCore = construct_func();
2418
+ } else if (newEntity) {
2419
+ replaceComponentEntity(componentCore, newEntity);
2417
2420
  }
2418
2421
  } else {
2419
- comp = construct_func();
2422
+ componentCore = construct_func();
2420
2423
  }
2421
2424
  bucket = this.new_map.get(key);
2422
- if (bucket !== void 0) {
2423
- bucket.push(comp);
2425
+ if (bucket) {
2426
+ bucket.push(componentCore);
2424
2427
  } else {
2425
- bucket = [comp];
2428
+ bucket = [componentCore];
2426
2429
  this.new_map.set(key, bucket);
2427
2430
  bucket[IDX] = 0;
2428
2431
  }
2429
- if (comp[CORE]) {
2430
- (_a = comp[CORE]).parent ?? (_a.parent = this.owner);
2432
+ if (componentCore) {
2433
+ componentCore.parent ?? (componentCore.parent = this.owner);
2431
2434
  }
2432
- return comp;
2435
+ return componentCore;
2433
2436
  }
2434
2437
  commit() {
2435
2438
  this.current_map.forEach((arr) => {
@@ -3173,6 +3176,19 @@ function createRoot(element) {
3173
3176
  }
3174
3177
  };
3175
3178
  }
3179
+ function hotReloadRoot(rootCore, nextEntity, props) {
3180
+ if (!rootCore || !rootCore.component) {
3181
+ throw new Error("Invalid Lilact root component.");
3182
+ }
3183
+ const replaced = replaceComponentEntity(rootCore, nextEntity);
3184
+ if (!replaced) {
3185
+ throw new Error(
3186
+ "Cannot hot-reload the root from a class component to a function component, or vice versa."
3187
+ );
3188
+ }
3189
+ rootCore.apply(props === void 0 ? rootCore.props : props);
3190
+ return rootCore;
3191
+ }
3176
3192
  function createPortal(children, element) {
3177
3193
  return createComponent2(lilact_default.Portal, { "view": element }, children);
3178
3194
  }
@@ -3855,7 +3871,6 @@ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, options = {})
3855
3871
  module.exports = {};
3856
3872
  module.loaded = false;
3857
3873
  module.error = void 0;
3858
- module.importsObject = void 0;
3859
3874
  module.meta = {};
3860
3875
  }
3861
3876
  let processed;
@@ -3867,8 +3882,7 @@ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, options = {})
3867
3882
  factory: "createComponent",
3868
3883
  appendSourcemap: true,
3869
3884
  injectTraceLabels: true,
3870
- produceCJS: false,
3871
- referentiateImports: true,
3885
+ produceCJS: true,
3872
3886
  blocksInfo: lilact_default.blocksInfo
3873
3887
  });
3874
3888
  } catch (value) {
@@ -3887,8 +3901,6 @@ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, options = {})
3887
3901
  globalThis.Lilact = lilact_default;
3888
3902
  globalThis.createComponent = lilact_default.createComponent;
3889
3903
  globalThis.Fragment = lilact_default.Fragment;
3890
- makeImportsObject(module, options);
3891
- lilact_default.scriptImportsObject = module.importsObject;
3892
3904
  const result = eval(processed);
3893
3905
  module.loaded = true;
3894
3906
  return isEmpty(module.exports) ? result : module.exports;
@@ -6829,11 +6841,6 @@ function transpileJSX(jsx2, {
6829
6841
  injectTraceLabels = false,
6830
6842
  discardComments = false,
6831
6843
  produceCJS = false,
6832
- referentiateImports = false,
6833
- importsObject = "Lilact.scriptImportsObject",
6834
- // first letter must be capital so components work as expected
6835
- importsObjectVar = "LilactImports",
6836
- // first letter must be capital so components work as expected
6837
6844
  logErrors = false,
6838
6845
  // lilact internal
6839
6846
  mappings = [],
@@ -6912,22 +6919,11 @@ function transpileJSX(jsx2, {
6912
6919
  const flattened_nodes = [];
6913
6920
  const codify = (outlen, node3, is_attr = false, is_xml = false) => {
6914
6921
  flattened_nodes.push(node3);
6915
- if (typeof node3 !== "object") {
6916
- if (referentiateImports && typeof node3 === "string") {
6917
- if (meta?.imported_names.has(node3)) {
6918
- let j = flattened_nodes.length - 2;
6919
- while (typeof flattened_nodes[j] === "string" && flattened_nodes[j].trim() === "" || typeof flattened_nodes[j] === "object" && flattened_nodes[j].type === "comment") j--;
6920
- if (typeof flattened_nodes[j] !== "string" || flattened_nodes[j] !== ".") {
6921
- return importsObjectVar + "." + node3;
6922
- }
6923
- }
6924
- }
6925
- return node3;
6926
- }
6927
- if (node3 === null) return "";
6922
+ if (typeof node3 !== "object") return node3;
6923
+ if (!node3) return "";
6928
6924
  node3.out_index = outlen;
6929
6925
  if (node3.type === "string") return jsx2.substring(node3.begin, node3.end);
6930
- if (node3.type === "import") return referentiateImports ? "" : node3.cjs;
6926
+ if (node3.type === "import") return node3.cjs;
6931
6927
  if (node3.type === "export") return node3.cjs;
6932
6928
  if (node3.type === "regex") return jsx2.substring(node3.begin, node3.end);
6933
6929
  if (node3.type === "comment") return discardComments || is_attr ? "" : jsx2.substring(node3.begin, node3.end);
@@ -6935,7 +6931,7 @@ function transpileJSX(jsx2, {
6935
6931
  if (node3.type === "parenthesis") {
6936
6932
  let out2 = "(";
6937
6933
  if (node3.out) {
6938
- if (produceCJS || referentiateImports) processImportExports(node3, jsx2, meta);
6934
+ if (produceCJS) processImportExports(node3, jsx2, meta);
6939
6935
  for (const ch2 of node3.out) {
6940
6936
  out2 += codify(outlen + out2.length - 1, ch2);
6941
6937
  }
@@ -6945,7 +6941,7 @@ function transpileJSX(jsx2, {
6945
6941
  if (node3.type === "js") {
6946
6942
  let out2 = "";
6947
6943
  if (node3.out) {
6948
- if (produceCJS || referentiateImports) processImportExports(node3, jsx2, meta);
6944
+ if (produceCJS) processImportExports(node3, jsx2, meta);
6949
6945
  for (const ch2 of node3.out) {
6950
6946
  if (is_xml && ch2.type === "comment") continue;
6951
6947
  out2 += codify(outlen + out2.length - (is_attr ? 1 : 0), ch2);
@@ -6960,9 +6956,6 @@ function transpileJSX(jsx2, {
6960
6956
  return out2;
6961
6957
  }
6962
6958
  if (node3.type === "xml") {
6963
- if (referentiateImports && meta?.imported_names?.has(node3.tag) && node3.tag[0] === node3.tag[0].toUpperCase()) {
6964
- node3.tag = importsObjectVar + "." + node3.tag;
6965
- }
6966
6959
  if (node3.tag.length === 0) {
6967
6960
  node3.tag = fragment;
6968
6961
  } else if (node3.tag[0] !== node3.tag[0].toUpperCase()) {
@@ -7000,9 +6993,6 @@ function transpileJSX(jsx2, {
7000
6993
  if (injectTraceLabels) {
7001
6994
  out = `/*LILACTBLOCK${++blocksInfo2.counter}:0,0:<EXEC>*/try{`;
7002
6995
  }
7003
- if (referentiateImports) {
7004
- out += `const ${importsObjectVar} = ${importsObject};`;
7005
- }
7006
6996
  out += codify(out.length, json);
7007
6997
  if (injectTraceLabels) {
7008
6998
  if (transpilerConfig.enableLabelStack) {
@@ -7020,7 +7010,7 @@ function transpileJSX(jsx2, {
7020
7010
 
7021
7011
  // .tmp/src/lilact.jsx
7022
7012
  var Lilact2 = {
7023
- VERSION: "RC.5",
7013
+ VERSION: "RC.6",
7024
7014
  // Configuration
7025
7015
  defaultTransitionTimeout: 300,
7026
7016
  defaultIsEqual: Object.is,
@@ -7147,6 +7137,7 @@ export {
7147
7137
  getComponentByPointer,
7148
7138
  globalErrorHandler,
7149
7139
  grabTimers,
7140
+ hotReloadRoot,
7150
7141
  id_num,
7151
7142
  insertion_effects,
7152
7143
  isAsync,
@@ -7167,6 +7158,7 @@ export {
7167
7158
  releaseSyntheticEvent,
7168
7159
  releaseTimers,
7169
7160
  render,
7161
+ replaceComponentEntity,
7170
7162
  require2 as require,
7171
7163
  required_scripts,
7172
7164
  resetTimers,