@lmjs/core 2.1.24 → 2.2.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/build/plugins-registry.js +2 -1
- package/dist/lumenjs-core.js +66 -7
- package/package.json +1 -1
- package/src/_re.js +159 -34
- package/src/dom-shim.js +432 -39
- package/src/lstnrs.js +5 -1
- package/src/ws.js +15 -27
- package/vendor/reconnecting-websocket.js +463 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmjs/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "LumenJS reactive core runtime — the reactive engine, HTML/JS AST compiler, realtime socket client, and delegated event listeners powering LumenJS applications.",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/",
|
package/src/_re.js
CHANGED
|
@@ -81,6 +81,7 @@ console.log = function () {
|
|
|
81
81
|
// flag yet — flip it by hand until that decision is made.
|
|
82
82
|
var _lumenDevMode = true;
|
|
83
83
|
var _lumenErrorLog = [];
|
|
84
|
+
var _lumenLoggedExprs = {};
|
|
84
85
|
|
|
85
86
|
// 2026-09-21: every mounted subview's own engine instance (renderHST()'s
|
|
86
87
|
// 'sub' type — real view="..." mounts, NOT :for/:if "section" renders,
|
|
@@ -133,6 +134,22 @@ function reportLumenError(info) {
|
|
|
133
134
|
};
|
|
134
135
|
_lumenErrorLog.push(entry);
|
|
135
136
|
|
|
137
|
+
if (_lumenDevMode && entry.stage === 'expression') {
|
|
138
|
+
// V1 rendered a path into not-yet-loaded data as blank, silently, and
|
|
139
|
+
// real V1 pages rely on that while their async data arrives. Log each
|
|
140
|
+
// distinct expression once; that "not loaded yet" shape as a warning.
|
|
141
|
+
var dedupeKey = (entry.view || '') + '|' + (entry.expr || '') + '|' + rawMessage;
|
|
142
|
+
if (_lumenLoggedExprs[dedupeKey]) return entry;
|
|
143
|
+
_lumenLoggedExprs[dedupeKey] = true;
|
|
144
|
+
if (/ is not defined$/.test(rawMessage)) {
|
|
145
|
+
console.warn('[LumenJS] "' + (entry.view || 'unknown') + '" — {{' + entry.expr + '}}: ' + entry.message + ' anywhere in scope, so it is shown as literal text.');
|
|
146
|
+
return entry;
|
|
147
|
+
}
|
|
148
|
+
if (/Cannot read propert(y|ies) of (undefined|null)/.test(rawMessage)) {
|
|
149
|
+
console.warn('[LumenJS] "' + (entry.view || 'unknown') + '" — ' + entry.expr + ' is empty for now (' + entry.message + '). Fine if its data is still loading.');
|
|
150
|
+
return entry;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
136
153
|
if (_lumenDevMode) {
|
|
137
154
|
console.error(
|
|
138
155
|
'[LumenJS] ' + entry.stage + ' error in "' + (entry.view || 'unknown') + '"' +
|
|
@@ -730,16 +747,31 @@ class _lm {
|
|
|
730
747
|
]);
|
|
731
748
|
return evaluator2.apply(null, [...Object.values(strippedCtx), expr]);
|
|
732
749
|
} catch (e2) {
|
|
750
|
+
if (e2 instanceof ReferenceError) this._lastUnresolved = true;
|
|
733
751
|
reportLumenError({ stage: 'expression', expr: expr, error: e2 });
|
|
734
752
|
return undefined;
|
|
735
753
|
}
|
|
736
754
|
}
|
|
737
755
|
}
|
|
756
|
+
if (e instanceof ReferenceError) this._lastUnresolved = true;
|
|
738
757
|
reportLumenError({ stage: 'expression', expr: expr, error: e });
|
|
739
758
|
return undefined;
|
|
740
759
|
}
|
|
741
760
|
}
|
|
742
761
|
|
|
762
|
+
// A text mustache naming something that exists nowhere (not loading
|
|
763
|
+
// data — a ReferenceError) stays literal, as V1 left any mustache
|
|
764
|
+
// outside its bind= list: real V1 prose/code samples rely on that.
|
|
765
|
+
_textMustache(content) {
|
|
766
|
+
this._lastUnresolved = false;
|
|
767
|
+
let v = this.getVal(content);
|
|
768
|
+
let unresolved = this._lastUnresolved && (v === undefined || v === null || v === '');
|
|
769
|
+
this._lastUnresolved = false;
|
|
770
|
+
if (!unresolved) return v;
|
|
771
|
+
let raw = String(content);
|
|
772
|
+
return /^\s*\{\{[\s\S]*\}\}\s*$/.test(raw) ? raw : '{{' + raw + '}}';
|
|
773
|
+
}
|
|
774
|
+
|
|
743
775
|
getVals(effect) {
|
|
744
776
|
let val = '';
|
|
745
777
|
// let mss = [];
|
|
@@ -748,13 +780,13 @@ class _lm {
|
|
|
748
780
|
for (let i = 0; i < effect.splits.length; i++) {
|
|
749
781
|
let split = effect.splits[i];
|
|
750
782
|
if (split.type == 'mustache') {
|
|
751
|
-
val += this.
|
|
783
|
+
val += this._textMustache(split.content);
|
|
752
784
|
} else {
|
|
753
785
|
val += split.content;
|
|
754
786
|
}
|
|
755
787
|
}
|
|
756
788
|
} else {
|
|
757
|
-
val = this.
|
|
789
|
+
val = this._textMustache(effect.content);
|
|
758
790
|
}
|
|
759
791
|
} else if (effect.type == "attr" || effect.type == "event") {
|
|
760
792
|
for (let i = 0; i < effect.splits.length; i++) {
|
|
@@ -852,6 +884,19 @@ class _lm {
|
|
|
852
884
|
const _view = this.view.views[i];
|
|
853
885
|
if (!subsNames.includes(_view.subPath)) subsNames.push(_view.subPath);
|
|
854
886
|
}
|
|
887
|
+
if (!subsNames.length) return;
|
|
888
|
+
// A view's <script> only runs once its DOM is inserted into the
|
|
889
|
+
// document. When this engine's own DOM is still detached (a subview
|
|
890
|
+
// nested inside another subview mid-construction), mounting children
|
|
891
|
+
// now would render them before the parent script declared the data
|
|
892
|
+
// they read. Wait until it's connected, bounded (~2s) so an orphaned
|
|
893
|
+
// engine doesn't retry forever.
|
|
894
|
+
if (this._RealDOM && this._RealDOM.length && !this._RealDOM.some(function (nd) { return nd && nd.isConnected; })) {
|
|
895
|
+
this._vxrWaits = (this._vxrWaits || 0) + 1;
|
|
896
|
+
if (this._vxrWaits <= 200) setTimeout(() => this.updateVXRs(k), 10);
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
this._vxrWaits = 0;
|
|
855
900
|
// cl(subsNames);
|
|
856
901
|
// 2026-09-17: real bug found and fixed — this used to always call
|
|
857
902
|
// the plain, no-args renderView(n, true, {}), which only ever
|
|
@@ -1080,7 +1125,10 @@ class _lm {
|
|
|
1080
1125
|
// THIS call — the in-flight call finishes processing the
|
|
1081
1126
|
// CURRENT data itself; anything that changed meanwhile is
|
|
1082
1127
|
// picked up by the next real update() call regardless.
|
|
1083
|
-
|
|
1128
|
+
// A change arriving mid-pass is remembered and re-run once the
|
|
1129
|
+
// pass finishes — nothing guarantees another update() comes
|
|
1130
|
+
// (e.g. `items = data; items[i].x = y` in one tick).
|
|
1131
|
+
if (cx._updating) { cx._dirty = true; continue; }
|
|
1084
1132
|
cx._updating = true;
|
|
1085
1133
|
try {
|
|
1086
1134
|
|
|
@@ -1378,7 +1426,17 @@ class _lm {
|
|
|
1378
1426
|
}
|
|
1379
1427
|
} else {
|
|
1380
1428
|
if (tx.forX.as['k'] != "") tx._re.update(tx.forX.as['k']);
|
|
1381
|
-
else
|
|
1429
|
+
else {
|
|
1430
|
+
tx._re.update(tx.forX.js);
|
|
1431
|
+
// Bare :for="items" spreads each item's own
|
|
1432
|
+
// keys into the row's scope, so the row's
|
|
1433
|
+
// mustaches are keyed by those names — a key
|
|
1434
|
+
// added or changed later ({{dateLeft}}) needs
|
|
1435
|
+
// its own refresh.
|
|
1436
|
+
for (const ik in vx) {
|
|
1437
|
+
if (Object.prototype.hasOwnProperty.call(vx, ik) && ik !== tx.forX.js) tx._re.update(ik);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1382
1440
|
// cl("Updating", tx.forX);
|
|
1383
1441
|
}
|
|
1384
1442
|
|
|
@@ -1411,6 +1469,10 @@ class _lm {
|
|
|
1411
1469
|
|
|
1412
1470
|
} finally {
|
|
1413
1471
|
cx._updating = false;
|
|
1472
|
+
if (cx._dirty) {
|
|
1473
|
+
cx._dirty = false;
|
|
1474
|
+
Promise.resolve().then(() => this.updateLXRs(k));
|
|
1475
|
+
}
|
|
1414
1476
|
}
|
|
1415
1477
|
}
|
|
1416
1478
|
}
|
|
@@ -2414,22 +2476,31 @@ class _lm {
|
|
|
2414
2476
|
}
|
|
2415
2477
|
(par.view._slots ?? (par.view._slots = {}))[slotName] = childs;
|
|
2416
2478
|
}
|
|
2417
|
-
} else if (doc.attrs && doc.attrs.hasOwnProperty('tpl')
|
|
2418
|
-
//
|
|
2419
|
-
//
|
|
2420
|
-
//
|
|
2421
|
-
//
|
|
2422
|
-
//
|
|
2423
|
-
//
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2479
|
+
} else if (doc.attrs && (doc.attrs.hasOwnProperty('tpl') || doc.attrs.hasOwnProperty('comp'))) {
|
|
2480
|
+
// V1 include on a plain element (`<div comp="card"
|
|
2481
|
+
// :data="items">`, the template carrying its own :for):
|
|
2482
|
+
// rendered inline, in THIS engine and scope, so the
|
|
2483
|
+
// host's reactive vars keep driving it. :data needs no
|
|
2484
|
+
// runtime handling — fcs.js's linkTemplateReactiveVars()
|
|
2485
|
+
// already made those names reactive in the host view.
|
|
2486
|
+
let _elAttrs = Object.assign({}, doc.attrs);
|
|
2487
|
+
delete _elAttrs['tpl']; delete _elAttrs['comp']; delete _elAttrs[':data'];
|
|
2488
|
+
el = par.createEl(doc.name, _elAttrs, [], doc.evs, doc);
|
|
2489
|
+
let _tplEntry = _resolveTemplateEntry(doc.attrs);
|
|
2490
|
+
if (_tplEntry) {
|
|
2491
|
+
for (const rv of (_tplEntry.reactiveVars || [])) {
|
|
2492
|
+
if (Array.isArray(par.reactiveVariables) && par.reactiveVariables.indexOf(rv) === -1) par.reactiveVariables.push(rv);
|
|
2493
|
+
}
|
|
2494
|
+
let childs = [];
|
|
2495
|
+
for (const dc of _tplEntry.hst) {
|
|
2496
|
+
let chils = par.walk(dc, el);
|
|
2497
|
+
if (chils) {
|
|
2498
|
+
if (Array.isArray(chils)) { if (chils.length) childs = [...childs, ...chils]; }
|
|
2499
|
+
else childs.push(chils);
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2502
|
+
childs.length ? el.append(...childs) : null;
|
|
2503
|
+
}
|
|
2433
2504
|
} else {
|
|
2434
2505
|
el = par.createEl(doc.name, doc.attrs, [], doc.evs, doc);
|
|
2435
2506
|
|
|
@@ -2962,6 +3033,36 @@ function dtp(el, t) {
|
|
|
2962
3033
|
}
|
|
2963
3034
|
}
|
|
2964
3035
|
|
|
3036
|
+
// Same region order V1's own auto-injection used (core.js ~L1840).
|
|
3037
|
+
const _V1_DEFAULT_LAYOUT = {
|
|
3038
|
+
hst: ['nav', 'header', 'body', 'footer'].map(function (r) {
|
|
3039
|
+
let attrs = {}; attrs[r] = "";
|
|
3040
|
+
return { type: "tag", name: "div", isV: false, attrs: attrs, ax: {}, evs: {}, ex: {}, children: [] };
|
|
3041
|
+
}),
|
|
3042
|
+
reactiveVars: [],
|
|
3043
|
+
regions: ['nav', 'header', 'footer'],
|
|
3044
|
+
};
|
|
3045
|
+
|
|
3046
|
+
// V1's tpl="name" / comp="name" includes (src/tpls/*.tpl, src/comps/*.tpl).
|
|
3047
|
+
// Real V1 content uses both interchangeably, sometimes with a leading "/",
|
|
3048
|
+
// so each attribute checks its own folder first and the other as fallback.
|
|
3049
|
+
function _resolveTemplateEntry(attrs) {
|
|
3050
|
+
let _payload = (typeof _vcD !== 'undefined' && _vcD) || (typeof _vcData !== 'undefined' ? _vcData : undefined);
|
|
3051
|
+
let isComp = !attrs.hasOwnProperty('tpl') && attrs.hasOwnProperty('comp');
|
|
3052
|
+
let name = String(isComp ? attrs['comp'] : attrs['tpl']).replace(/^\/+/, '');
|
|
3053
|
+
let folders = isComp ? ['comps', 'tpls'] : ['tpls', 'comps'];
|
|
3054
|
+
let bucket = _payload && _payload.tpls;
|
|
3055
|
+
for (const f of folders) {
|
|
3056
|
+
let entry = bucket && bucket[btoa("src/" + f + "/" + name + ".tpl")];
|
|
3057
|
+
if (entry) return entry;
|
|
3058
|
+
}
|
|
3059
|
+
reportLumenError({
|
|
3060
|
+
stage: 'tpl',
|
|
3061
|
+
error: new Error((isComp ? 'comp' : 'tpl') + '="' + name + '" — no such file at src/' + folders[0] + '/' + name + '.tpl'),
|
|
3062
|
+
});
|
|
3063
|
+
return null;
|
|
3064
|
+
}
|
|
3065
|
+
|
|
2965
3066
|
async function renderSection(tx, doc, par, k, sectionsData) {
|
|
2966
3067
|
if (tx.node.isConnected) {
|
|
2967
3068
|
if (k) {
|
|
@@ -2982,19 +3083,9 @@ async function renderSection(tx, doc, par, k, sectionsData) {
|
|
|
2982
3083
|
// children instead, walked by the SAME engine instance rendering
|
|
2983
3084
|
// everything else here (this section already has its own vx/vrs —
|
|
2984
3085
|
// no separate scope, no isolated instance, just this item's content).
|
|
2985
|
-
if (doc.attrs && doc.attrs.hasOwnProperty('tpl')) {
|
|
2986
|
-
let
|
|
2987
|
-
|
|
2988
|
-
let _tplKey = btoa("src/tpls/" + _tplName + ".tpl");
|
|
2989
|
-
let _tplEntry = _payload && _payload.tpls && _payload.tpls[_tplKey];
|
|
2990
|
-
if (_tplEntry) {
|
|
2991
|
-
hst = _tplEntry.hst;
|
|
2992
|
-
} else {
|
|
2993
|
-
reportLumenError({
|
|
2994
|
-
stage: 'tpl',
|
|
2995
|
-
error: new Error('tpl="' + _tplName + '" — no such file at src/tpls/' + _tplName + '.tpl'),
|
|
2996
|
-
});
|
|
2997
|
-
}
|
|
3086
|
+
if (doc.attrs && (doc.attrs.hasOwnProperty('tpl') || doc.attrs.hasOwnProperty('comp'))) {
|
|
3087
|
+
let _tplEntry = _resolveTemplateEntry(doc.attrs);
|
|
3088
|
+
if (_tplEntry) hst = _tplEntry.hst;
|
|
2998
3089
|
}
|
|
2999
3090
|
|
|
3000
3091
|
// 2026-09-17: real bug found and fixed — a subview mounted INSIDE a
|
|
@@ -3244,11 +3335,45 @@ async function renderView(n, isSub, d, type = 'views', viewsArr, scopeBase = ["V
|
|
|
3244
3335
|
} else {
|
|
3245
3336
|
let _re = await renderHST(hst, n, 'main');
|
|
3246
3337
|
// cl("RRR", _re);
|
|
3338
|
+
|
|
3339
|
+
// V1's per-view auth gate (core.js renderView): a view whose
|
|
3340
|
+
// <settings> has requireAuth: true only mounts when
|
|
3341
|
+
// Reactor({auth}) (or a global Auth()) returns truthy;
|
|
3342
|
+
// otherwise it hands off to appSettings.authView (or the
|
|
3343
|
+
// default view) with {redirect, data}. Nothing is mounted
|
|
3344
|
+
// yet at this point, so bailing out leaves the page as-is.
|
|
3345
|
+
if (_re.view.settings && _re.view.settings.requireAuth) {
|
|
3346
|
+
let authFunc = appSettings.auth && typeof appSettings.auth === "function"
|
|
3347
|
+
? appSettings.auth
|
|
3348
|
+
: (typeof Auth === "function" ? Auth : null);
|
|
3349
|
+
if (typeof authFunc !== "function") {
|
|
3350
|
+
setError(null, "No Reactor.auth() function detected! Please add one");
|
|
3351
|
+
return;
|
|
3352
|
+
}
|
|
3353
|
+
if (!authFunc()) {
|
|
3354
|
+
let fallback = (appSettings.authView || appSettings.defaultView || "home").toLowerCase();
|
|
3355
|
+
if (fallback == n.toLowerCase()) {
|
|
3356
|
+
setError(null, "The auth view '" + n + "' itself has requireAuth: true — it can never render");
|
|
3357
|
+
return;
|
|
3358
|
+
}
|
|
3359
|
+
return renderView(fallback, null, { redirect: n.toLowerCase(), data: clone(View.props) });
|
|
3360
|
+
}
|
|
3361
|
+
}
|
|
3362
|
+
|
|
3247
3363
|
let layout = _re.view.settings.layout;
|
|
3248
3364
|
|
|
3249
3365
|
let filePathL = "src/layouts/" + layout + ".layout";
|
|
3250
3366
|
let fileKeyL = btoa(filePathL);
|
|
3251
|
-
let hstL = _payload['layouts'][fileKeyL];
|
|
3367
|
+
let hstL = _payload['layouts'] && _payload['layouts'][fileKeyL];
|
|
3368
|
+
if (!hstL) {
|
|
3369
|
+
// V1 had no layout files — it injected nav/header/body/
|
|
3370
|
+
// footer regions itself. A migrated V1 project (no
|
|
3371
|
+
// src/layouts/ at all) gets that same built-in shape.
|
|
3372
|
+
if (layout && layout !== 'default') {
|
|
3373
|
+
reportLumenError({ stage: 'layout', error: new Error('layout "' + layout + '" not found at ' + filePathL + ' — using the built-in default layout') });
|
|
3374
|
+
}
|
|
3375
|
+
hstL = JSON.parse(JSON.stringify(_V1_DEFAULT_LAYOUT));
|
|
3376
|
+
}
|
|
3252
3377
|
// cl(_rel);
|
|
3253
3378
|
|
|
3254
3379
|
|