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.
- package/dist/lilact.development.js +100 -11
- 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 +100 -11
- 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 +100 -11
- 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 +115 -21
- 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,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
|
-
|
|
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 (
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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,
|