lilact 0.30.0 → 0.31.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.
- package/dist/lilact.development.js +167 -53
- package/dist/lilact.development.js.map +3 -3
- package/dist/lilact.development.min.js +25 -25
- package/dist/lilact.development.min.js.map +3 -3
- package/dist/lilact.production.min.js +25 -25
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/accessories.ErrorBoundary.html +8 -8
- package/docs/classes/accessories.Suspense.html +7 -7
- package/docs/classes/components.Component.html +11 -11
- package/docs/classes/components.HTMLComponent.html +11 -11
- package/docs/classes/components.RootComponent.html +11 -11
- package/docs/functions/components.cloneComponent.html +1 -1
- package/docs/functions/components.createComponent.html +1 -1
- package/docs/functions/components.createPortal.html +1 -1
- package/docs/functions/components.createRoot.html +1 -1
- package/docs/functions/components.hotReloadRoot.html +1 -1
- package/docs/functions/components.memo.html +1 -1
- package/docs/functions/components.render.html +1 -1
- package/docs/functions/components.replaceAllComponentInstances.html +1 -0
- package/docs/functions/components.replaceComponentEntity.html +1 -1
- package/docs/functions/run.lazy.html +1 -1
- package/docs/functions/run.run.html +1 -1
- package/docs/functions/run.runScripts.html +1 -1
- package/docs/hierarchy.html +1 -1
- package/docs/modules/components.html +1 -1
- package/docs/static/index.html +1 -1
- package/docs/static/lilact.development.js +167 -53
- package/docs/static/lilact.development.js.map +3 -3
- package/docs/static/lilact.development.min.js +25 -25
- package/docs/static/lilact.development.min.js.map +3 -3
- package/docs/static/lilact.production.min.js +25 -25
- package/docs/variables/components.cloneElement.html +1 -1
- package/examples/index.html +1 -1
- package/examples/lilact.development.js +167 -53
- package/examples/lilact.development.js.map +3 -3
- package/examples/lilact.development.min.js +25 -25
- package/examples/lilact.development.min.js.map +3 -3
- package/examples/lilact.production.min.js +25 -25
- package/package.json +1 -1
- package/src/components.jsx +209 -80
- package/src/lilact.jsx +1 -1
- package/src/run.jsx +85 -53
|
@@ -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,12 +2371,62 @@ 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 hotEntityAliases = /* @__PURE__ */ new Map();
|
|
2375
|
+
function resolveHotEntity(entity) {
|
|
2376
|
+
entity = getComponentEntity(entity);
|
|
2377
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2378
|
+
while (typeof entity === "function" && hotEntityAliases.has(entity) && !visited.has(entity)) {
|
|
2379
|
+
visited.add(entity);
|
|
2380
|
+
entity = hotEntityAliases.get(entity);
|
|
2381
|
+
}
|
|
2382
|
+
return entity;
|
|
2383
|
+
}
|
|
2384
|
+
var componentInstances = /* @__PURE__ */ new Map();
|
|
2385
|
+
function registerComponentCore(core) {
|
|
2386
|
+
const entity = getComponentEntity(core.entity);
|
|
2387
|
+
if (typeof entity !== "function") return;
|
|
2388
|
+
let instances = componentInstances.get(entity);
|
|
2389
|
+
if (!instances) {
|
|
2390
|
+
instances = /* @__PURE__ */ new Set();
|
|
2391
|
+
componentInstances.set(entity, instances);
|
|
2392
|
+
}
|
|
2393
|
+
instances.add(core);
|
|
2394
|
+
core.registered_entity = entity;
|
|
2395
|
+
}
|
|
2396
|
+
function unregisterComponentCore(core) {
|
|
2397
|
+
const entity = core.registered_entity;
|
|
2398
|
+
if (!entity) return;
|
|
2399
|
+
const instances = componentInstances.get(entity);
|
|
2400
|
+
if (instances) {
|
|
2401
|
+
instances.delete(core);
|
|
2402
|
+
if (instances.size === 0) {
|
|
2403
|
+
componentInstances.delete(entity);
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
delete core.registered_entity;
|
|
2407
|
+
}
|
|
2408
|
+
function moveComponentCore(core, oldEntity, newEntity) {
|
|
2409
|
+
const oldInstances = componentInstances.get(oldEntity);
|
|
2410
|
+
if (oldInstances) {
|
|
2411
|
+
oldInstances.delete(core);
|
|
2412
|
+
if (oldInstances.size === 0) {
|
|
2413
|
+
componentInstances.delete(oldEntity);
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
let newInstances = componentInstances.get(newEntity);
|
|
2417
|
+
if (!newInstances) {
|
|
2418
|
+
newInstances = /* @__PURE__ */ new Set();
|
|
2419
|
+
componentInstances.set(newEntity, newInstances);
|
|
2420
|
+
}
|
|
2421
|
+
newInstances.add(core);
|
|
2422
|
+
core.registered_entity = newEntity;
|
|
2423
|
+
}
|
|
2373
2424
|
function replaceComponentEntity(componentCore, nextEntity) {
|
|
2374
2425
|
if (!componentCore || typeof nextEntity !== "function") {
|
|
2375
2426
|
return false;
|
|
2376
2427
|
}
|
|
2377
2428
|
const oldEntity = getComponentEntity(componentCore.entity);
|
|
2378
|
-
const newEntity =
|
|
2429
|
+
const newEntity = resolveHotEntity(nextEntity);
|
|
2379
2430
|
if (oldEntity === newEntity) {
|
|
2380
2431
|
return true;
|
|
2381
2432
|
}
|
|
@@ -2383,19 +2434,43 @@ function replaceComponentEntity(componentCore, nextEntity) {
|
|
|
2383
2434
|
if (!component) {
|
|
2384
2435
|
return false;
|
|
2385
2436
|
}
|
|
2386
|
-
|
|
2387
|
-
const newIsClass = isClass(newEntity);
|
|
2388
|
-
if (oldIsClass !== newIsClass) {
|
|
2437
|
+
if (typeof oldEntity !== "function" || typeof newEntity !== "function" || isClass(oldEntity) !== isClass(newEntity)) {
|
|
2389
2438
|
return false;
|
|
2390
2439
|
}
|
|
2391
|
-
if (
|
|
2440
|
+
if (isClass(newEntity)) {
|
|
2392
2441
|
Object.setPrototypeOf(component, newEntity.prototype);
|
|
2393
2442
|
} else {
|
|
2394
|
-
component.render = newEntity;
|
|
2443
|
+
component.render = newEntity.bind(component);
|
|
2395
2444
|
}
|
|
2396
2445
|
componentCore.entity = newEntity;
|
|
2446
|
+
moveComponentCore(componentCore, oldEntity, newEntity);
|
|
2397
2447
|
return true;
|
|
2398
2448
|
}
|
|
2449
|
+
function replaceAllComponentInstances(oldEntity, newEntity) {
|
|
2450
|
+
oldEntity = getComponentEntity(oldEntity);
|
|
2451
|
+
newEntity = getComponentEntity(newEntity);
|
|
2452
|
+
if (typeof oldEntity !== "function" || typeof newEntity !== "function") {
|
|
2453
|
+
return 0;
|
|
2454
|
+
}
|
|
2455
|
+
newEntity = resolveHotEntity(newEntity);
|
|
2456
|
+
if (oldEntity === newEntity) {
|
|
2457
|
+
return 0;
|
|
2458
|
+
}
|
|
2459
|
+
hotEntityAliases.set(oldEntity, newEntity);
|
|
2460
|
+
const instances = componentInstances.get(oldEntity);
|
|
2461
|
+
if (!instances) {
|
|
2462
|
+
return 0;
|
|
2463
|
+
}
|
|
2464
|
+
let count = 0;
|
|
2465
|
+
for (const core of [...instances]) {
|
|
2466
|
+
if (!replaceComponentEntity(core, newEntity)) {
|
|
2467
|
+
continue;
|
|
2468
|
+
}
|
|
2469
|
+
core.apply(core.props, core.state);
|
|
2470
|
+
count++;
|
|
2471
|
+
}
|
|
2472
|
+
return count;
|
|
2473
|
+
}
|
|
2399
2474
|
var ComponentCache = class {
|
|
2400
2475
|
constructor(owner) {
|
|
2401
2476
|
__publicField(this, "owner");
|
|
@@ -2411,8 +2486,8 @@ var ComponentCache = class {
|
|
|
2411
2486
|
componentCore = bucket[bucket[IDX]];
|
|
2412
2487
|
bucket[IDX]++;
|
|
2413
2488
|
const oldEntity = getComponentEntity(componentCore.entity);
|
|
2414
|
-
const newEntity =
|
|
2415
|
-
const incompatible = typeof oldEntity
|
|
2489
|
+
const newEntity = resolveHotEntity(nextEntity);
|
|
2490
|
+
const incompatible = typeof oldEntity !== typeof newEntity || typeof oldEntity === "function" && isClass(oldEntity) !== isClass(newEntity);
|
|
2416
2491
|
if (incompatible) {
|
|
2417
2492
|
componentCore = construct_func();
|
|
2418
2493
|
} else if (newEntity) {
|
|
@@ -2603,6 +2678,7 @@ var ComponentCore = class {
|
|
|
2603
2678
|
}
|
|
2604
2679
|
}
|
|
2605
2680
|
async cleanup() {
|
|
2681
|
+
unregisterComponentCore(this);
|
|
2606
2682
|
try {
|
|
2607
2683
|
const promises = [];
|
|
2608
2684
|
if (this.props?.ref) {
|
|
@@ -2837,8 +2913,7 @@ var renderErrorHandler = (c, e) => {
|
|
|
2837
2913
|
};
|
|
2838
2914
|
function constructFunc(core, parent) {
|
|
2839
2915
|
let comp = core;
|
|
2840
|
-
if (core[TEXT2]
|
|
2841
|
-
} else {
|
|
2916
|
+
if (core[TEXT2] === void 0) {
|
|
2842
2917
|
let entity = core.entity;
|
|
2843
2918
|
let memoized = false;
|
|
2844
2919
|
if (typeof entity === "object") {
|
|
@@ -2849,51 +2924,63 @@ function constructFunc(core, parent) {
|
|
|
2849
2924
|
throw new Error("Invalid component.");
|
|
2850
2925
|
}
|
|
2851
2926
|
}
|
|
2927
|
+
entity = resolveHotEntity(entity);
|
|
2852
2928
|
if (typeof entity === "string") {
|
|
2853
2929
|
comp = new HTMLComponent(entity, core.props);
|
|
2854
|
-
} else {
|
|
2855
|
-
if (
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2930
|
+
} else if (isClass(entity)) {
|
|
2931
|
+
if (entity?.defaultProps) {
|
|
2932
|
+
core.props = {
|
|
2933
|
+
...entity.defaultProps,
|
|
2934
|
+
...core.props
|
|
2935
|
+
};
|
|
2936
|
+
}
|
|
2937
|
+
comp = new entity(core.props);
|
|
2938
|
+
const desc = Object.getOwnPropertyDescriptor(comp, "state");
|
|
2939
|
+
if (desc) {
|
|
2940
|
+
if (typeof desc.get !== "function" && typeof desc.set !== "function") {
|
|
2941
|
+
comp[CORE].state = comp.state;
|
|
2942
|
+
Object.defineProperty(comp, "state", {
|
|
2943
|
+
get() {
|
|
2944
|
+
return this[CORE].state;
|
|
2945
|
+
},
|
|
2946
|
+
set(value) {
|
|
2947
|
+
if (this[CORE].state === void 0) {
|
|
2948
|
+
this[CORE].state = value;
|
|
2949
|
+
} else {
|
|
2950
|
+
throw new Error(
|
|
2951
|
+
"Assigning component state this way is not allowed."
|
|
2952
|
+
);
|
|
2874
2953
|
}
|
|
2875
|
-
}
|
|
2876
|
-
}
|
|
2877
|
-
}
|
|
2878
|
-
} else if (typeof entity === "function") {
|
|
2879
|
-
if (entity?.defaultProps) {
|
|
2880
|
-
core.props = { ...entity.defaultProps, ...core.props };
|
|
2954
|
+
}
|
|
2955
|
+
});
|
|
2881
2956
|
}
|
|
2882
|
-
comp = new Component(core.props);
|
|
2883
|
-
comp.render = entity.bind(comp);
|
|
2884
|
-
comp[CORE].hooks = [];
|
|
2885
|
-
comp[CORE].hook_index = 0;
|
|
2886
|
-
} else {
|
|
2887
|
-
throw new Error("Error in constructing component.");
|
|
2888
2957
|
}
|
|
2889
|
-
|
|
2890
|
-
if (
|
|
2891
|
-
|
|
2958
|
+
} else if (typeof entity === "function") {
|
|
2959
|
+
if (entity?.defaultProps) {
|
|
2960
|
+
core.props = {
|
|
2961
|
+
...entity.defaultProps,
|
|
2962
|
+
...core.props
|
|
2963
|
+
};
|
|
2892
2964
|
}
|
|
2965
|
+
comp = new Component(core.props);
|
|
2966
|
+
comp.render = entity.bind(comp);
|
|
2967
|
+
comp[CORE].hooks = [];
|
|
2968
|
+
comp[CORE].hook_index = 0;
|
|
2969
|
+
} else {
|
|
2970
|
+
throw new Error("Error in constructing component.");
|
|
2971
|
+
}
|
|
2972
|
+
comp[CORE].entity = entity;
|
|
2973
|
+
registerComponentCore(comp[CORE]);
|
|
2974
|
+
if (core.container) {
|
|
2975
|
+
comp[CORE].container = core.container;
|
|
2976
|
+
}
|
|
2977
|
+
if (memoized) {
|
|
2978
|
+
comp[CORE][MEMOIZED] = true;
|
|
2893
2979
|
}
|
|
2894
|
-
if (memoized) comp[CORE][MEMOIZED] = true;
|
|
2895
2980
|
}
|
|
2896
|
-
if (parent instanceof ComponentCore)
|
|
2981
|
+
if (parent instanceof ComponentCore) {
|
|
2982
|
+
comp[CORE].parent = parent;
|
|
2983
|
+
}
|
|
2897
2984
|
return comp;
|
|
2898
2985
|
}
|
|
2899
2986
|
function prepareCore(parent, core) {
|
|
@@ -3173,12 +3260,16 @@ function createRoot(element) {
|
|
|
3173
3260
|
root.cleanup();
|
|
3174
3261
|
element.innerHTML = "";
|
|
3175
3262
|
}
|
|
3263
|
+
},
|
|
3264
|
+
getCore() {
|
|
3265
|
+
console.log(root, root[CORE]);
|
|
3266
|
+
return root[CORE];
|
|
3176
3267
|
}
|
|
3177
3268
|
};
|
|
3178
3269
|
}
|
|
3179
3270
|
function hotReloadRoot(rootCore, nextEntity, props) {
|
|
3180
3271
|
if (!rootCore || !rootCore.component) {
|
|
3181
|
-
throw new Error("Invalid
|
|
3272
|
+
throw new Error("Invalid root component.");
|
|
3182
3273
|
}
|
|
3183
3274
|
const replaced = replaceComponentEntity(rootCore, nextEntity);
|
|
3184
3275
|
if (!replaced) {
|
|
@@ -3186,7 +3277,7 @@ function hotReloadRoot(rootCore, nextEntity, props) {
|
|
|
3186
3277
|
"Cannot hot-reload the root from a class component to a function component, or vice versa."
|
|
3187
3278
|
);
|
|
3188
3279
|
}
|
|
3189
|
-
rootCore.apply(props === void 0 ? rootCore.props : props);
|
|
3280
|
+
rootCore.apply(props === void 0 ? rootCore.props : { ...rootCore.props, ...props });
|
|
3190
3281
|
return rootCore;
|
|
3191
3282
|
}
|
|
3192
3283
|
function createPortal(children, element) {
|
|
@@ -3828,7 +3919,10 @@ function require2(path2) {
|
|
|
3828
3919
|
return loadModule(path2, options2);
|
|
3829
3920
|
}
|
|
3830
3921
|
function makeImportsObject(mod, options2 = {}) {
|
|
3831
|
-
mod.importsObject = {};
|
|
3922
|
+
mod.importsObject ?? (mod.importsObject = {});
|
|
3923
|
+
for (const key of Object.keys(mod.importsObject)) {
|
|
3924
|
+
delete mod.importsObject[key];
|
|
3925
|
+
}
|
|
3832
3926
|
for (const path2 in mod.meta.imports) {
|
|
3833
3927
|
const imps = mod.meta.imports[path2];
|
|
3834
3928
|
const exps = loadModule(path2, {
|
|
@@ -3848,7 +3942,7 @@ function makeImportsObject(mod, options2 = {}) {
|
|
|
3848
3942
|
for (const i2 of imps.import_defaults) {
|
|
3849
3943
|
if (!Object.prototype.hasOwnProperty.call(exps, "default")) {
|
|
3850
3944
|
throw new Error(
|
|
3851
|
-
|
|
3945
|
+
"Imported module does not export a default."
|
|
3852
3946
|
);
|
|
3853
3947
|
}
|
|
3854
3948
|
mod.importsObject[i2] = exps.default;
|
|
@@ -3857,9 +3951,26 @@ function makeImportsObject(mod, options2 = {}) {
|
|
|
3857
3951
|
mod.importsObject[i2] = { ...exps };
|
|
3858
3952
|
}
|
|
3859
3953
|
}
|
|
3954
|
+
return mod.importsObject;
|
|
3955
|
+
}
|
|
3956
|
+
function exportEntries(value) {
|
|
3957
|
+
return value && typeof value === "object" ? value : { default: value };
|
|
3958
|
+
}
|
|
3959
|
+
function replaceReloadedExports(previousExports2, nextExports2) {
|
|
3960
|
+
if (!previousExports2) return;
|
|
3961
|
+
const oldExports = exportEntries(previousExports2);
|
|
3962
|
+
const newExports = exportEntries(nextExports2);
|
|
3963
|
+
for (const name of Object.keys(oldExports)) {
|
|
3964
|
+
const oldExport = oldExports[name];
|
|
3965
|
+
const newExport = newExports[name];
|
|
3966
|
+
if (typeof oldExport === "function" && typeof newExport === "function") {
|
|
3967
|
+
lilact_default.replaceAllComponentInstances(oldExport, newExport);
|
|
3968
|
+
}
|
|
3969
|
+
}
|
|
3860
3970
|
}
|
|
3861
3971
|
function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, options = {}) {
|
|
3862
3972
|
let module = required_scripts[path];
|
|
3973
|
+
const previousExports = module?.loaded ? module.exports : void 0;
|
|
3863
3974
|
if (!module) {
|
|
3864
3975
|
module = createModule(path, {
|
|
3865
3976
|
code: jsx
|
|
@@ -3903,7 +4014,9 @@ function run(jsx, path = `InlineJSX-${++lilact_default.eval_num}`, options = {})
|
|
|
3903
4014
|
globalThis.Fragment = lilact_default.Fragment;
|
|
3904
4015
|
const result = eval(processed);
|
|
3905
4016
|
module.loaded = true;
|
|
3906
|
-
|
|
4017
|
+
const nextExports = isEmpty(module.exports) ? result : module.exports;
|
|
4018
|
+
replaceReloadedExports(previousExports, nextExports);
|
|
4019
|
+
return nextExports;
|
|
3907
4020
|
} catch (value) {
|
|
3908
4021
|
const error2 = report(value, path);
|
|
3909
4022
|
error2.sourcePhase ?? (error2.sourcePhase = "runtime");
|
|
@@ -7010,7 +7123,7 @@ function transpileJSX(jsx2, {
|
|
|
7010
7123
|
|
|
7011
7124
|
// .tmp/src/lilact.jsx
|
|
7012
7125
|
var Lilact2 = {
|
|
7013
|
-
VERSION: "RC.
|
|
7126
|
+
VERSION: "RC.7",
|
|
7014
7127
|
// Configuration
|
|
7015
7128
|
defaultTransitionTimeout: 300,
|
|
7016
7129
|
defaultIsEqual: Object.is,
|
|
@@ -7158,6 +7271,7 @@ export {
|
|
|
7158
7271
|
releaseSyntheticEvent,
|
|
7159
7272
|
releaseTimers,
|
|
7160
7273
|
render,
|
|
7274
|
+
replaceAllComponentInstances,
|
|
7161
7275
|
replaceComponentEntity,
|
|
7162
7276
|
require2 as require,
|
|
7163
7277
|
required_scripts,
|