lilact 0.30.1 → 0.31.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 +82 -60
  2. package/dist/lilact.development.js.map +2 -2
  3. package/dist/lilact.development.min.js +29 -29
  4. package/dist/lilact.development.min.js.map +3 -3
  5. package/dist/lilact.production.min.js +29 -29
  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.memo.html +1 -1
  19. package/docs/functions/components.render.html +1 -1
  20. package/docs/functions/components.replaceAllComponentInstances.html +1 -1
  21. package/docs/functions/components.replaceComponentEntity.html +1 -1
  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 +82 -60
  27. package/docs/static/lilact.development.js.map +2 -2
  28. package/docs/static/lilact.development.min.js +29 -29
  29. package/docs/static/lilact.development.min.js.map +3 -3
  30. package/docs/static/lilact.production.min.js +29 -29
  31. package/docs/variables/components.cloneElement.html +1 -1
  32. package/examples/lilact.development.js +82 -60
  33. package/examples/lilact.development.js.map +2 -2
  34. package/examples/lilact.development.min.js +29 -29
  35. package/examples/lilact.development.min.js.map +3 -3
  36. package/examples/lilact.production.min.js +29 -29
  37. package/package.json +1 -1
  38. package/src/components.jsx +121 -98
  39. package/src/jsx.js +6 -2
  40. package/src/lilact.jsx +1 -1
  41. package/src/run.jsx +1 -0
  42. package/src/symbols.jsx +5 -1
  43. package/docs/functions/components.hotReloadRoot.html +0 -1
@@ -1716,11 +1716,13 @@ __export(symbols_exports, {
1716
1716
  INTERVAL: () => INTERVAL,
1717
1717
  IS_ZOMBIE: () => IS_ZOMBIE,
1718
1718
  LAZY: () => LAZY,
1719
+ LOCATION: () => LOCATION,
1719
1720
  MEMOIZED: () => MEMOIZED,
1720
1721
  REPEAT: () => REPEAT,
1721
1722
  TEXT: () => TEXT2
1722
1723
  });
1723
1724
  var [
1725
+ LOCATION,
1724
1726
  CORE,
1725
1727
  COMPONENT,
1726
1728
  TEXT2,
@@ -1736,6 +1738,7 @@ var [
1736
1738
  CALLBACK,
1737
1739
  ARGS
1738
1740
  ] = [
1741
+ /* @__PURE__ */ Symbol.for("LILACT:LOCATION"),
1739
1742
  /* @__PURE__ */ Symbol.for("LILACT:CORE"),
1740
1743
  /* @__PURE__ */ Symbol.for("LILACT:COMPONENT"),
1741
1744
  /* @__PURE__ */ Symbol.for("LILACT:TEXT"),
@@ -2350,7 +2353,6 @@ __export(components_exports, {
2350
2353
  current_component: () => current_component,
2351
2354
  effect_timeout: () => effect_timeout,
2352
2355
  events_set: () => events_set,
2353
- hotReloadRoot: () => hotReloadRoot,
2354
2356
  insertion_effects: () => insertion_effects,
2355
2357
  layout_effects: () => layout_effects,
2356
2358
  length_css_attributes_set: () => length_css_attributes_set,
@@ -2371,6 +2373,16 @@ var SVG_NS = "http://www.w3.org/2000/svg";
2371
2373
  function getComponentEntity(entity) {
2372
2374
  return entity?.[MEMOIZED] ? entity.component : entity;
2373
2375
  }
2376
+ var hotEntityAliases = /* @__PURE__ */ new Map();
2377
+ function resolveHotEntity(entity) {
2378
+ entity = getComponentEntity(entity);
2379
+ const visited = /* @__PURE__ */ new Set();
2380
+ while (typeof entity === "function" && hotEntityAliases.has(entity) && !visited.has(entity)) {
2381
+ visited.add(entity);
2382
+ entity = hotEntityAliases.get(entity);
2383
+ }
2384
+ return entity;
2385
+ }
2374
2386
  var componentInstances = /* @__PURE__ */ new Map();
2375
2387
  function registerComponentCore(core) {
2376
2388
  const entity = getComponentEntity(core.entity);
@@ -2416,7 +2428,7 @@ function replaceComponentEntity(componentCore, nextEntity) {
2416
2428
  return false;
2417
2429
  }
2418
2430
  const oldEntity = getComponentEntity(componentCore.entity);
2419
- const newEntity = getComponentEntity(nextEntity);
2431
+ const newEntity = resolveHotEntity(nextEntity);
2420
2432
  if (oldEntity === newEntity) {
2421
2433
  return true;
2422
2434
  }
@@ -2442,6 +2454,11 @@ function replaceAllComponentInstances(oldEntity, newEntity) {
2442
2454
  if (typeof oldEntity !== "function" || typeof newEntity !== "function") {
2443
2455
  return 0;
2444
2456
  }
2457
+ newEntity = resolveHotEntity(newEntity);
2458
+ if (oldEntity === newEntity) {
2459
+ return 0;
2460
+ }
2461
+ hotEntityAliases.set(oldEntity, newEntity);
2445
2462
  const instances = componentInstances.get(oldEntity);
2446
2463
  if (!instances) {
2447
2464
  return 0;
@@ -2471,7 +2488,7 @@ var ComponentCache = class {
2471
2488
  componentCore = bucket[bucket[IDX]];
2472
2489
  bucket[IDX]++;
2473
2490
  const oldEntity = getComponentEntity(componentCore.entity);
2474
- const newEntity = getComponentEntity(nextEntity);
2491
+ const newEntity = resolveHotEntity(nextEntity);
2475
2492
  const incompatible = typeof oldEntity !== typeof newEntity || typeof oldEntity === "function" && isClass(oldEntity) !== isClass(newEntity);
2476
2493
  if (incompatible) {
2477
2494
  componentCore = construct_func();
@@ -2898,10 +2915,11 @@ var renderErrorHandler = (c, e) => {
2898
2915
  };
2899
2916
  function constructFunc(core, parent) {
2900
2917
  let comp = core;
2901
- if (core[TEXT2] !== void 0) {
2902
- } else {
2918
+ if (core[TEXT2] === void 0) {
2903
2919
  let entity = core.entity;
2904
2920
  let memoized = false;
2921
+ const loc = core.props[LOCATION];
2922
+ if (loc) delete core.props[LOCATION];
2905
2923
  if (typeof entity === "object") {
2906
2924
  if (entity[MEMOIZED]) {
2907
2925
  memoized = entity[MEMOIZED];
@@ -2910,52 +2928,64 @@ function constructFunc(core, parent) {
2910
2928
  throw new Error("Invalid component.");
2911
2929
  }
2912
2930
  }
2931
+ entity = resolveHotEntity(entity);
2913
2932
  if (typeof entity === "string") {
2914
2933
  comp = new HTMLComponent(entity, core.props);
2915
- } else {
2916
- if (isClass(entity)) {
2917
- if (entity?.defaultProps) {
2918
- core.props = { ...entity.defaultProps, ...core.props };
2919
- }
2920
- comp = new entity(core.props);
2921
- const desc = Object.getOwnPropertyDescriptor(comp, "state");
2922
- if (desc) {
2923
- if (typeof desc.get !== "function" && typeof desc.set !== "function") {
2924
- comp[CORE].state = comp.state;
2925
- Object.defineProperty(comp, "state", {
2926
- get() {
2927
- return this[CORE].state;
2928
- },
2929
- set(v) {
2930
- if (this[CORE].state === void 0) {
2931
- this[CORE].state = v;
2932
- } else {
2933
- throw new Error("Assigning component state this way is not allowed.");
2934
- }
2934
+ } else if (isClass(entity)) {
2935
+ if (entity?.defaultProps) {
2936
+ core.props = {
2937
+ ...entity.defaultProps,
2938
+ ...core.props
2939
+ };
2940
+ }
2941
+ comp = new entity(core.props);
2942
+ const desc = Object.getOwnPropertyDescriptor(comp, "state");
2943
+ if (desc) {
2944
+ if (typeof desc.get !== "function" && typeof desc.set !== "function") {
2945
+ comp[CORE].state = comp.state;
2946
+ Object.defineProperty(comp, "state", {
2947
+ get() {
2948
+ return this[CORE].state;
2949
+ },
2950
+ set(value) {
2951
+ if (this[CORE].state === void 0) {
2952
+ this[CORE].state = value;
2953
+ } else {
2954
+ throw new Error(
2955
+ "Assigning component state this way is not allowed."
2956
+ );
2935
2957
  }
2936
- });
2937
- }
2938
- }
2939
- } else if (typeof entity === "function") {
2940
- if (entity?.defaultProps) {
2941
- core.props = { ...entity.defaultProps, ...core.props };
2958
+ }
2959
+ });
2942
2960
  }
2943
- comp = new Component(core.props);
2944
- comp.render = entity.bind(comp);
2945
- comp[CORE].hooks = [];
2946
- comp[CORE].hook_index = 0;
2947
- } else {
2948
- throw new Error("Error in constructing component.");
2949
2961
  }
2950
- comp[CORE].entity = entity;
2951
- registerComponentCore(comp[CORE]);
2952
- if (core.container) {
2953
- comp[CORE].container = core.container;
2962
+ } else if (typeof entity === "function") {
2963
+ if (entity?.defaultProps) {
2964
+ core.props = {
2965
+ ...entity.defaultProps,
2966
+ ...core.props
2967
+ };
2954
2968
  }
2969
+ comp = new Component(core.props);
2970
+ comp.render = entity.bind(comp);
2971
+ comp[CORE].hooks = [];
2972
+ comp[CORE].hook_index = 0;
2973
+ } else {
2974
+ throw new Error("Error in constructing component.");
2975
+ }
2976
+ if (loc) comp[CORE].location = loc;
2977
+ comp[CORE].entity = entity;
2978
+ registerComponentCore(comp[CORE]);
2979
+ if (core.container) {
2980
+ comp[CORE].container = core.container;
2981
+ }
2982
+ if (memoized) {
2983
+ comp[CORE][MEMOIZED] = true;
2955
2984
  }
2956
- if (memoized) comp[CORE][MEMOIZED] = true;
2957
2985
  }
2958
- if (parent instanceof ComponentCore) comp[CORE].parent = parent;
2986
+ if (parent instanceof ComponentCore) {
2987
+ comp[CORE].parent = parent;
2988
+ }
2959
2989
  return comp;
2960
2990
  }
2961
2991
  function prepareCore(parent, core) {
@@ -3237,24 +3267,10 @@ function createRoot(element) {
3237
3267
  }
3238
3268
  },
3239
3269
  getCore() {
3240
- console.log(root, root[CORE]);
3241
3270
  return root[CORE];
3242
3271
  }
3243
3272
  };
3244
3273
  }
3245
- function hotReloadRoot(rootCore, nextEntity, props) {
3246
- if (!rootCore || !rootCore.component) {
3247
- throw new Error("Invalid root component.");
3248
- }
3249
- const replaced = replaceComponentEntity(rootCore, nextEntity);
3250
- if (!replaced) {
3251
- throw new Error(
3252
- "Cannot hot-reload the root from a class component to a function component, or vice versa."
3253
- );
3254
- }
3255
- rootCore.apply(props === void 0 ? rootCore.props : { ...rootCore.props, ...props });
3256
- return rootCore;
3257
- }
3258
3274
  function createPortal(children, element) {
3259
3275
  return createComponent2(lilact_default.Portal, { "view": element }, children);
3260
3276
  }
@@ -3969,6 +3985,7 @@ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, options = {})
3969
3985
  appendSourcemap: true,
3970
3986
  injectTraceLabels: true,
3971
3987
  produceCJS: true,
3988
+ addLocationProp: true,
3972
3989
  blocksInfo: lilact_default.blocksInfo
3973
3990
  });
3974
3991
  } catch (value) {
@@ -6216,6 +6233,7 @@ function processImportExports(node3, jsx2, meta) {
6216
6233
  }
6217
6234
 
6218
6235
  // .tmp/src/jsx.js
6236
+ var LOCATION2 = /* @__PURE__ */ Symbol.for("LILACT:LOCATION");
6219
6237
  var transpilerConfig = {
6220
6238
  setBlockLabels: true,
6221
6239
  enableLabelStack: false,
@@ -6930,6 +6948,7 @@ function transpileJSX(jsx2, {
6930
6948
  discardComments = false,
6931
6949
  produceCJS = false,
6932
6950
  logErrors = false,
6951
+ addLocationProp = false,
6933
6952
  // lilact internal
6934
6953
  mappings = [],
6935
6954
  meta,
@@ -7073,7 +7092,10 @@ function transpileJSX(jsx2, {
7073
7092
  }
7074
7093
  }
7075
7094
  const loc = getRowCol(eols, node3.begin);
7076
- out2 = ` ${factory}( ${node3.tag}, { ${out2} )`;
7095
+ if (addLocationProp)
7096
+ out2 = ` ${factory}( ${node3.tag}, { [Lilact.LOCATION]:["${path2}", ${loc}], ${out2} )`;
7097
+ else
7098
+ out2 = ` ${factory}( ${node3.tag}, { ${out2} )`;
7077
7099
  return out2;
7078
7100
  }
7079
7101
  };
@@ -7098,7 +7120,7 @@ function transpileJSX(jsx2, {
7098
7120
 
7099
7121
  // .tmp/src/lilact.jsx
7100
7122
  var Lilact2 = {
7101
- VERSION: "RC.6",
7123
+ VERSION: "RC.7",
7102
7124
  // Configuration
7103
7125
  defaultTransitionTimeout: 300,
7104
7126
  defaultIsEqual: Object.is,
@@ -7176,6 +7198,7 @@ export {
7176
7198
  INTERVAL,
7177
7199
  IS_ZOMBIE,
7178
7200
  LAZY,
7201
+ LOCATION,
7179
7202
  Lilact2 as Lilact,
7180
7203
  Link,
7181
7204
  MEMOIZED,
@@ -7225,7 +7248,6 @@ export {
7225
7248
  getComponentByPointer,
7226
7249
  globalErrorHandler,
7227
7250
  grabTimers,
7228
- hotReloadRoot,
7229
7251
  id_num,
7230
7252
  insertion_effects,
7231
7253
  isAsync,