@lmjs/core 2.2.2 → 2.3.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/src/dom-shim.js CHANGED
@@ -942,17 +942,17 @@
942
942
  }
943
943
  var real = EVENT_NAME_MAP[evt] || evt;
944
944
  listen(real, function (e) {
945
- if (atAttr) {
946
- var el = e.target;
947
- var match = null;
948
- while (el && el.nodeType === 1) {
949
- if (_hasAnyAt(el)) { match = el; break; }
950
- el = el.parentElement;
945
+ // Like jQuery (which V1 always ran on): a delegated handler fires for EVERY matching element
946
+ // from the target up, nearest first, until one stops propagation or returns false — not just
947
+ // the nearest match, which silently dropped a parent's @click inside a clickable child.
948
+ if (atAttr || (selector && _isNode(node))) {
949
+ for (var el = e.target; el && el.nodeType === 1 && node.contains(el); el = el.parentElement) {
950
+ var hit = atAttr ? _hasAnyAt(el) : (el.matches && el.matches(selector));
951
+ if (!hit) continue;
952
+ var ret = _callHandler(handler, el, e);
953
+ if (ret === false) { e.preventDefault(); e.stopPropagation(); }
954
+ if (e.cancelBubble) break;
951
955
  }
952
- if (match && node.contains(match)) _callHandler(handler, match, e);
953
- } else if (selector && _isNode(node)) {
954
- var match2 = e.target.closest(selector);
955
- if (match2 && node.contains(match2)) _callHandler(handler, match2, e);
956
956
  } else {
957
957
  _callHandler(handler, node, e);
958
958
  }
package/src/lstnrs.js CHANGED
@@ -83,6 +83,13 @@ _csswrk.on('css-ready', function (e) {
83
83
  _vuid[data.key].resolve(data.csses);
84
84
  });
85
85
 
86
+ // V1 started the upload worker at boot (core.js `_upwrk.start()`); V2 never started it, so [up] elements never
87
+ // reported files-added / upload-progress / ... Start it on first use instead of on every page load.
88
+ function _upwrkStarted() {
89
+ if (!_upwrk.isStarted()) _upwrk.start();
90
+ return _upwrk;
91
+ }
92
+
86
93
  _upwrk.on('message', function (e) {
87
94
  let data = e.originalEvent.data;
88
95
  });
@@ -127,7 +134,7 @@ _upwrk.on('queue-empty', function (e) {
127
134
  $.fn.extend({
128
135
  startUpload: function () {
129
136
  if (this.hasAttr('up')) {
130
- _upwrk.trigger('start-upload', {
137
+ _upwrkStarted().trigger('start-upload', {
131
138
  "upid": this.attr('upid')
132
139
  });
133
140
  }
@@ -135,7 +142,7 @@ $.fn.extend({
135
142
  },
136
143
  stopUpload: function () {
137
144
  if (this.hasAttr('up')) {
138
- _upwrk.trigger('stop-upload', {
145
+ _upwrkStarted().trigger('stop-upload', {
139
146
  "upid": this.attr('upid')
140
147
  });
141
148
  }
@@ -143,7 +150,7 @@ $.fn.extend({
143
150
  },
144
151
  removeFile: function (id) {
145
152
  if (this.hasAttr('up')) {
146
- _upwrk.trigger('remove-file', {
153
+ _upwrkStarted().trigger('remove-file', {
147
154
  "upid": this.attr('upid'),
148
155
  "id": id
149
156
  });
@@ -157,7 +164,7 @@ $("body").on("FilesAdded", "[up]", function (e, files) {
157
164
  let t = $(this);
158
165
  var size = t.attr('data-mxs') ? t.attr('data-mxs') : '10mb';
159
166
  //TODO: Filter + Reset File Input
160
- _upwrk.trigger('handle-files', {
167
+ _upwrkStarted().trigger('handle-files', {
161
168
  "upid": t.attr('upid'),
162
169
  "files": files
163
170
  });
@@ -404,6 +411,16 @@ $("body").on("open-modal", "[modal]", function (ev) {
404
411
 
405
412
  modal.data("props", el.data("props"));
406
413
 
414
+ // V1 mounted the modal's view later (globalWatch) with props { modal: <what @modal-open returned> } — the same
415
+ // object, so `view.scope(function (view, props) { props.modal.x = 1 })` is seen by the opener. Mount it only
416
+ // now that @modal-open has run, and hand the props over the same way.
417
+ if (_view != "") {
418
+ let _host = newModal.find("[for-modal]");
419
+ let _mp = modal.data("props");
420
+ _host.data("props", _mp !== undefined ? { modal: _mp } : {});
421
+ mountModalView(_host.get(0), _view);
422
+ }
423
+
407
424
  modal
408
425
  .addClass("modal-open")
409
426
  .delay(10)
@@ -523,8 +540,14 @@ function evalEvAttr(_v, ev, el, n, arg1, arg2, arg3) {
523
540
  // a parameterized attribute like `@click="fn(x)"` already falls
524
541
  // through to the eval() branch below unchanged, exactly as before.
525
542
  let _rawEl = el[0];
526
- let _ownerFns = _rawEl && _rawEl._ownerRe && _rawEl._ownerRe.view && _rawEl._ownerRe.view.fns;
527
- let _ownFn = (_v === _fn && _ownerFns && typeof _ownerFns[_fn] === "function") ? _ownerFns[_fn] : null;
543
+ // Nearest engine up the chain that declares it: a :for row's engine has no functions of its own, its view does.
544
+ let _ownFn = null;
545
+ if (_v === _fn) {
546
+ for (let _e = _rawEl && _rawEl._ownerRe, _n = 0; _e && _e.view && _n < 50; _e = _e.view._pv, _n++) {
547
+ let _fns = _e.view.fns;
548
+ if (_fns && Object.prototype.hasOwnProperty.call(_fns, _fn) && typeof _fns[_fn] === "function") { _ownFn = _fns[_fn]; break; }
549
+ }
550
+ }
528
551
  if (_ownFn || typeof window[_v] === "function") {
529
552
  ev["cType"] = n;
530
553
  let _handler = _ownFn || window[_fn];
@@ -538,7 +561,7 @@ function evalEvAttr(_v, ev, el, n, arg1, arg2, arg3) {
538
561
  // only real global functions/vars ever worked. _rawEl._ownerRe is
539
562
  // the same owner-instance reference the function-lookup branch above
540
563
  // already uses.
541
- let _eva = _evalEventScopedExpr(_rawEl && _rawEl._ownerRe, _v);
564
+ let _eva = _evalEventScopedExpr(_rawEl && _rawEl._ownerRe, _v, { ev: ev, el: el, n: n, arg1: arg1, arg2: arg2, arg3: arg3 });
542
565
  return _eva;
543
566
  }
544
567
  } catch (e) {
@@ -547,7 +570,7 @@ function evalEvAttr(_v, ev, el, n, arg1, arg2, arg3) {
547
570
  }
548
571
 
549
572
  function processEv(ev, el, n, arg1, arg2, arg3) {
550
- if (el.attr("stop")) ev.stopPropagation();
573
+ if (el.hasAttr("stop")) ev.stopPropagation();
551
574
  if (n == "focusin") n = "focus";
552
575
  else if (n == "focusout") n = "blur";
553
576
  if (!el.hasAttr("@" + n)) return;
@@ -748,6 +771,23 @@ $("body").on("drop", "[\\@drop]", function (ev, ui) {
748
771
  processEv(ev, $(this), "drop", ui);
749
772
  });
750
773
 
774
+ // V1's Select2 bridge (core-v1 listeners.js): select2:select/unselect on an [sl] element becomes sl-select /
775
+ // sl-unselect, which runs the element's @sl-select / @sl-unselect handler with (ev, el, data). Missing in V2.
776
+ $("body").on("select2:select", "[sl]", function (e) {
777
+ $(this).trigger("sl-select", [e.params && e.params.data, e]);
778
+ });
779
+ $("body").on("select2:unselect", "[sl]", function (e) {
780
+ $(this).trigger("sl-unselect", [e.params && e.params.data, e]);
781
+ });
782
+ $("body").on("sl-select", "[\\@sl-select]", function (ev, data, e) {
783
+ ev.params = e && e.params;
784
+ processEv(ev, $(this), "sl-select", data);
785
+ });
786
+ $("body").on("sl-unselect", "[\\@sl-unselect]", function (ev, data, e) {
787
+ ev.params = e && e.params;
788
+ processEv(ev, $(this), "sl-unselect", data);
789
+ });
790
+
751
791
  $("body").on("clear", "[sl]", function (ev, ui) {
752
792
  let t = $(this);
753
793
  t.empty().change();
@@ -779,7 +819,7 @@ $("body").on("click touch", "[close-modal]", function (ev) {
779
819
  var element_to_remove = $("#" + id).get(0);
780
820
  var index = $.inArray(element_to_remove, popups.modals);
781
821
  var modalOwner = $("[modal][data-modal=" + id + "]");
782
- if (el.attr("stop")) ev.stopPropagation();
822
+ if (el.hasAttr("stop")) ev.stopPropagation();
783
823
  ev.preventDefault();
784
824
  if (modalOwner.hasAttr("@modal-beforeclose")) {
785
825
  try {
@@ -1240,7 +1280,7 @@ $("body").on("click touch", "[actv]", function (e) {
1240
1280
  let el = $(this);
1241
1281
  if (el.attr("actv") != "") $(el.attr("actv")).removeClass("active");
1242
1282
  el.addClass("active");
1243
- if (el.attr("stop")) e.stopPropagation();
1283
+ if (el.hasAttr("stop")) e.stopPropagation();
1244
1284
  });
1245
1285
 
1246
1286
  $("body").on("click touch", "[actvt]", function (e) {
@@ -1248,7 +1288,7 @@ $("body").on("click touch", "[actvt]", function (e) {
1248
1288
  if (el.attr("actvt") != "") $(el.attr("actvt")).removeClass("active");
1249
1289
  if (el.hasClass("active")) el.removeClass("active");
1250
1290
  else el.addClass("active");
1251
- if (el.attr("stop")) e.stopPropagation();
1291
+ if (el.hasAttr("stop")) e.stopPropagation();
1252
1292
  });
1253
1293
 
1254
1294
  $("body").on("click touch", "[close-notify]", function (e) {
@@ -1256,7 +1296,7 @@ $("body").on("click touch", "[close-notify]", function (e) {
1256
1296
  tis.fadeOut(function () {
1257
1297
  tis.remove();
1258
1298
  });
1259
- if ($(this).attr("stop")) e.stopPropagation();
1299
+ if ($(this).hasAttr("stop")) e.stopPropagation();
1260
1300
  });
1261
1301
 
1262
1302
  let _keyInt;
@@ -0,0 +1,289 @@
1
+ // V1 parity: dynamic `[reactive]` rendering.
2
+ //
3
+ // V1 processed every `[reactive]:not(.binded)` element that appeared in the page, whenever it appeared: it
4
+ // added class `binded` and rendered the element's markup (`:for`, `:if`/`:else`, `{{mustache}}`, `@events`)
5
+ // with its RenderEngine. Code that builds HTML strings at runtime (`$(el).append('<div reactive>...')`, DataTable
6
+ // column renderers, "load more" lists) depends on it. V2 compiles views to a syntax tree on the server, so a
7
+ // runtime-inserted string was never compiled and stayed raw. This file compiles such a host's DOM into the same
8
+ // tree shape the server produces (see `class hst` in packages/cli/lib/fcs.js) and renders it with the normal engine.
9
+ //
10
+ // Rules kept from V1: only elements the engine did NOT create are candidates (static `reactive` markup inside a
11
+ // view is already compiled with it); the host is processed once (class `binded`); a mustache that cannot be
12
+ // resolved renders blank; a broken chunk never throws into the page.
13
+
14
+ var _reactiveEngines = [];
15
+
16
+ var _rxMoustache = /\{\s*\{\s*([\s\S]*?)\s*\}\s*\}/g;
17
+ var _rxVoid = { area: 1, base: 1, basefont: 1, bgsound: 1, br: 1, col: 1, command: 1, embed: 1, frame: 1, hr: 1, image: 1, img: 1, input: 1, isindex: 1, keygen: 1, link: 1, menuitem: 1, meta: 1, nextid: 1, param: 1, source: 1, track: 1, wbr: 1 };
18
+ var _rxSkip = {};
19
+ ("break case catch class const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield await async of static get set null true false undefined NaN Infinity " +
20
+ "Object Function Boolean Symbol Error Number BigInt Math Date String RegExp Array Map Set WeakMap WeakSet Promise Reflect Proxy Intl JSON console window document navigator location localStorage sessionStorage " +
21
+ "fetch setTimeout clearTimeout setInterval clearInterval parseInt parseFloat isFinite isNaN encodeURI decodeURI encodeURIComponent decodeURIComponent escape unescape globalThis").split(" ").forEach(function (w) { _rxSkip[w] = 1; });
22
+ var _rxExprCache = new Map();
23
+
24
+ function _rxKeepOneSpace(t) {
25
+ t = t.replace(/\s\s/gm, " ");
26
+ if (/\s\s/gm.test(t)) return _rxKeepOneSpace(t);
27
+ return t;
28
+ }
29
+ function _rxClean(t) {
30
+ t = t.replace(/(\r?\n|\r)/gm, "");
31
+ t = t.replace(/(\t)/gm, "");
32
+ t = _rxKeepOneSpace(t);
33
+ return t.replace(/^(?:\s*\t*\r*\n*\{*)+|(?:\s*\t*\r*\n*\})+$/g, "").trim();
34
+ }
35
+
36
+ // Names an expression reads (a superset is harmless: a name that resolves nowhere never becomes a parameter of
37
+ // the evaluator, see getVal()). Skips strings, comments, property names after `.`, and object-literal keys.
38
+ function _rxIdents(src, out) {
39
+ var i = 0, n = src.length, prev = "";
40
+ function skipTemplate() {
41
+ i++;
42
+ while (i < n) {
43
+ var c = src[i];
44
+ if (c === "\\") { i += 2; continue; }
45
+ if (c === "`") { i++; return; }
46
+ if (c === "$" && src[i + 1] === "{") {
47
+ i += 2;
48
+ var depth = 1, start = i;
49
+ while (i < n && depth) {
50
+ var d = src[i];
51
+ if (d === "`") { var s = i; skipTemplate(); continue; }
52
+ if (d === "{") depth++;
53
+ else if (d === "}") { depth--; if (!depth) break; }
54
+ else if (d === "'" || d === '"') { var q = d; i++; while (i < n && src[i] !== q) { if (src[i] === "\\") i++; i++; } }
55
+ i++;
56
+ }
57
+ _rxIdents(src.slice(start, i), out);
58
+ i++;
59
+ continue;
60
+ }
61
+ i++;
62
+ }
63
+ }
64
+ while (i < n) {
65
+ var ch = src[i];
66
+ if (ch === "'" || ch === '"') {
67
+ i++;
68
+ while (i < n && src[i] !== ch) { if (src[i] === "\\") i++; i++; }
69
+ i++; prev = "s"; continue;
70
+ }
71
+ if (ch === "`") { skipTemplate(); prev = "s"; continue; }
72
+ if (ch === "/" && src[i + 1] === "/") { while (i < n && src[i] !== "\n") i++; continue; }
73
+ if (ch === "/" && src[i + 1] === "*") { var e = src.indexOf("*/", i + 2); i = e < 0 ? n : e + 2; continue; }
74
+ if (/\s/.test(ch)) { i++; continue; }
75
+ if (/[0-9]/.test(ch)) { while (i < n && /[\w.]/.test(src[i])) i++; prev = "n"; continue; }
76
+ if (/[A-Za-z_$]/.test(ch)) {
77
+ var st = i;
78
+ while (i < n && /[\w$]/.test(src[i])) i++;
79
+ var id = src.slice(st, i);
80
+ var j = i;
81
+ while (j < n && /\s/.test(src[j])) j++;
82
+ var isKey = src[j] === ":" && (prev === "{" || prev === ",");
83
+ if (prev !== "." && !isKey && !_rxSkip[id] && out.indexOf(id) === -1) out.push(id);
84
+ prev = "i"; continue;
85
+ }
86
+ prev = ch; i++;
87
+ }
88
+ return out;
89
+ }
90
+
91
+ function _rxExpr(mux) {
92
+ var hit = _rxExprCache.get(mux);
93
+ if (hit) return hit;
94
+ var rv = null;
95
+ try { new Function(mux); rv = _rxIdents(mux, []); } catch (e) { rv = null; }
96
+ if (_rxExprCache.size > 2000) _rxExprCache.clear();
97
+ _rxExprCache.set(mux, rv);
98
+ return rv;
99
+ }
100
+
101
+ function _rxEscape(s) { return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"); }
102
+
103
+ // text -> { content, mss } exactly like hst._getMs2(); a mustache holding invalid JS is left as literal text.
104
+ function _rxMustaches(text, escapeStatic, rvSet) {
105
+ var found = [], m, last = 0;
106
+ _rxMoustache.lastIndex = 0;
107
+ while ((m = _rxMoustache.exec(text)) != null) {
108
+ var mux = _rxClean(m[0]);
109
+ var rvs = _rxExpr(mux);
110
+ if (rvs) found.push({ index: m.index, len: m[0].length, mux: mux, rvs: rvs });
111
+ }
112
+ if (!found.length) return { content: escapeStatic ? _rxEscape(text) : text, mss: [] };
113
+ var esc = escapeStatic ? _rxEscape : function (s) { return s; };
114
+ var content = "", mss = [];
115
+ for (var k = 0; k < found.length; k++) {
116
+ var f = found[k];
117
+ content += esc(text.substring(last, f.index));
118
+ var start = content.length;
119
+ content += "{{" + f.mux + "}}";
120
+ mss.push({ mus: f.mux, jst: null, rvs: f.rvs.slice(), start: start, end: content.length });
121
+ for (var r = 0; r < f.rvs.length; r++) rvSet[f.rvs[r]] = 1;
122
+ last = f.index + f.len;
123
+ }
124
+ content += esc(text.substring(last));
125
+ return { content: content, mss: mss };
126
+ }
127
+
128
+ function _rxForX(val) {
129
+ var forX = { js: "", as: { k: "", v: "" }, dx: "" };
130
+ val = val.trim();
131
+ if (val.indexOf(";") > -1) { var zxx = val.split(";"); forX.dx = zxx[1].trim(); val = zxx[0].trim(); }
132
+ if (val.indexOf(" as ") > -1) {
133
+ var arr2 = val.split(" as ");
134
+ var arr3 = arr2[1].split(" ").join("").split(",");
135
+ forX.as.k = arr3[0].trim();
136
+ if (arr3.length > 1) forX.as.v = arr3[1].trim();
137
+ val = arr2[0].trim();
138
+ }
139
+ forX.js = val.trim();
140
+ return forX;
141
+ }
142
+
143
+ function _rxCompileNode(n, ptag, rvSet) {
144
+ if (n.nodeType === 3) {
145
+ var t = n.nodeValue;
146
+ var mm = _rxMustaches(t, ptag !== "style", rvSet);
147
+ if (ptag === "textarea" && mm.mss.length) mm = _rxMustaches(t, false, rvSet);
148
+ return { type: "text", content: mm.content, mss: mm.mss, tag: ptag };
149
+ }
150
+ if (n.nodeType !== 1) return null;
151
+ var name = n.localName;
152
+ if (name === "script") return null;
153
+ var res = { type: "tag", name: name, isV: !!_rxVoid[name], attrs: {}, ax: {}, evs: {}, ex: {}, children: [] };
154
+ // The browser already parsed SVG into its namespace; keep that for createEl() (same flag as fcs.js sets).
155
+ if (n.namespaceURI === "http://www.w3.org/2000/svg") res.svg = true;
156
+ var attrs = n.attributes;
157
+ for (var a = 0; a < attrs.length; a++) {
158
+ var an = attrs[a].name, av = attrs[a].value;
159
+ if (an === ":else") { res.type = "section"; res.cond = ""; }
160
+ else if (an === ":if" || an === ":else-if") {
161
+ res.type = "section"; res.cond = av;
162
+ _rxIdents(av, []).forEach(function (id) { rvSet[id] = 1; });
163
+ } else if (an === ":for") {
164
+ res.type = "sections"; res.content = av; res.forX = _rxForX(av);
165
+ if (res.forX.js) _rxIdents(res.forX.js, []).forEach(function (id) { rvSet[id] = 1; });
166
+ }
167
+ // Same "`{{expr}}`" backtick rule as the server compiler (fcs.js), attributes only.
168
+ var ms = _rxMustaches(an.charAt(0) === "@" ? av : av.replace(/`(\{\s*\{[\s\S]*?\}\s*\})`/g, "$1"), false, rvSet);
169
+ if (an.charAt(0) === "@") {
170
+ res.evs[an] = ms.content;
171
+ if (ms.mss.length) res.ex[an] = ms.mss;
172
+ } else {
173
+ res.attrs[an] = ms.content;
174
+ if (ms.mss.length) res.ax[an] = ms.mss;
175
+ }
176
+ }
177
+ _rxOrderIfFor(res);
178
+ if (!res.isV) {
179
+ var kids = n.childNodes;
180
+ for (var c = 0; c < kids.length; c++) {
181
+ var ch = _rxCompileNode(kids[c], name, rvSet);
182
+ if (ch) res.children.push(ch);
183
+ }
184
+ if (name === "style" && !res.children.length) res.children.push({ type: "text", content: "", mss: [], tag: "style" });
185
+ }
186
+ return res;
187
+ }
188
+
189
+ // Same rule as the server compiler (fcs.js hst_orderIfFor): `:if` and `:for` on one element apply in written
190
+ // order — `:if` first gates the whole loop, `:for` first makes the `:if` a per-row condition.
191
+ function _rxOrderIfFor(res) {
192
+ if (!res || !res.attrs || !res.forX || !Object.prototype.hasOwnProperty.call(res.attrs, ":if")) return;
193
+ var keys = Object.keys(res.attrs);
194
+ var cond = String(res.attrs[":if"]);
195
+ if (keys.indexOf(":if") < keys.indexOf(":for")) res.forX.js = "(" + cond + ") ? (" + res.forX.js + ") : []";
196
+ else res.attrs[":for-if"] = res.attrs[":for-if"] ? "(" + res.attrs[":for-if"] + ") && (" + cond + ")" : cond;
197
+ res.type = "sections";
198
+ delete res.cond;
199
+ delete res.attrs[":if"];
200
+ if (res.ax) delete res.ax[":if"];
201
+ }
202
+
203
+ function _rxCompileHost(host) {
204
+ var rvSet = {}, hst = [], kids = host.childNodes;
205
+ for (var i = 0; i < kids.length; i++) {
206
+ var c = _rxCompileNode(kids[i], host.localName, rvSet);
207
+ if (c) hst.push(c);
208
+ }
209
+ return { hst: hst, reactiveVars: Object.keys(rvSet) };
210
+ }
211
+
212
+ async function _rxRender(host) {
213
+ host.classList.add("binded");
214
+ var compiled = _rxCompileHost(host);
215
+ var sub = null;
216
+ for (var p = host.parentNode; p; p = p.parentNode) { if (p.isSub === true) { sub = p; break; } }
217
+ var _re = await renderHST(compiled, "reactive", "section", undefined, null, ["View"], sub ? sub.vars : undefined, sub ? sub.fns : undefined);
218
+ _re._blankUnresolved = true;
219
+
220
+ // `bind="a, b as c"` on the closest ancestor: only the `as` aliases need work, every plain name already resolves
221
+ // through the view/global scope the engine reads from.
222
+ var bindEl = host.closest("[bind]");
223
+ if (bindEl) {
224
+ String(bindEl.getAttribute("bind") || "").split(",").forEach(function (v) {
225
+ var parts = v.trim().split(" as ");
226
+ if (parts.length === 2 && parts[0].trim() && parts[1].trim()) {
227
+ try { _re.vrs[parts[1].trim()] = _re.scopedEval(_re.reactiveVariables, parts[0].trim()); } catch (e) { }
228
+ }
229
+ });
230
+ }
231
+
232
+ host.textContent = "";
233
+ host.append.apply(host, _re._RealDOM);
234
+ _re._rxHost = host;
235
+ _reactiveEngines.push(_re);
236
+ _re.renderAll("section");
237
+ }
238
+
239
+ function _updateReactiveEngines(varName) {
240
+ for (var i = _reactiveEngines.length - 1; i >= 0; i--) {
241
+ var re = _reactiveEngines[i];
242
+ if (!re._rxHost || !re._rxHost.isConnected) { _reactiveEngines.splice(i, 1); continue; }
243
+ try { re.update(varName); } catch (e) { cl(e); }
244
+ }
245
+ }
246
+
247
+ (function () {
248
+ if (typeof MutationObserver === "undefined" || typeof document === "undefined" || !document.documentElement) return;
249
+ var pending = [], running = false;
250
+
251
+ function consider(node) {
252
+ if (!node || node.nodeType !== 1 || node._ownerRe) return;
253
+ if (node.hasAttribute("reactive")) pending.push(node);
254
+ if (node.firstElementChild) {
255
+ var found = node.querySelectorAll("[reactive]");
256
+ for (var i = 0; i < found.length; i++) pending.push(found[i]);
257
+ }
258
+ }
259
+
260
+ async function drain() {
261
+ if (running) return;
262
+ running = true;
263
+ var rendered = 0;
264
+ try {
265
+ while (pending.length) {
266
+ var h = pending.shift();
267
+ if (!h.isConnected || h._ownerRe || h.classList.contains("binded")) continue;
268
+ try { await _rxRender(h); rendered++; } catch (e) { reportLumenError({ stage: "reactive", error: e }); }
269
+ }
270
+ } finally { running = false; }
271
+ // V1 rendered [reactive] chunks inside globalWatch(), so the same pass initialized the plugins in them
272
+ // ([sl], [up], [date], forms, ...). Do one globalWatch() per batch of rendered chunks.
273
+ if (rendered && typeof globalWatch === "function") {
274
+ try { globalWatch(); } catch (e) { reportLumenError({ stage: "reactive", error: e }); }
275
+ }
276
+ }
277
+
278
+ new MutationObserver(function (records) {
279
+ for (var r = 0; r < records.length; r++) {
280
+ var added = records[r].addedNodes;
281
+ for (var k = 0; k < added.length; k++) consider(added[k]);
282
+ }
283
+ if (pending.length) drain();
284
+ }).observe(document.documentElement, { childList: true, subtree: true });
285
+
286
+ function scan() { consider(document.documentElement); if (pending.length) drain(); }
287
+ if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", scan);
288
+ else setTimeout(scan, 0);
289
+ })();
package/src/walk.js CHANGED
@@ -781,6 +781,23 @@ function _fnRegisterStatement(name, targetKey) {
781
781
  };
782
782
  }
783
783
 
784
+ function _windowExportStatement(name) {
785
+ return {
786
+ type: "IfStatement",
787
+ test: { type: "BinaryExpression", operator: "!==", left: { type: "UnaryExpression", operator: "typeof", prefix: true, argument: { type: "Identifier", name: "window" } }, right: { type: "Literal", value: "undefined" } },
788
+ consequent: {
789
+ type: "ExpressionStatement",
790
+ expression: {
791
+ type: "AssignmentExpression",
792
+ operator: "=",
793
+ left: { type: "MemberExpression", computed: true, object: { type: "Identifier", name: "window" }, property: { type: "Literal", value: name } },
794
+ right: { type: "Identifier", name: name }
795
+ }
796
+ },
797
+ alternate: null
798
+ };
799
+ }
800
+
784
801
  // Handles any number of declarators in a single top-level statement, not just
785
802
  // one. `var x = 1, y = 2;` with only `x` reactive becomes two statements:
786
803
  // `_vt.View.vars["x"] = 1;` followed by a real `var y = 2;` for the rest —
@@ -794,6 +811,10 @@ function transformTopLevelDeclarations(AST, reactiveVariables, targetKey = "View
794
811
  if (stmt.type === "FunctionDeclaration" && stmt.id) {
795
812
  newBody.push(stmt);
796
813
  newBody.push(_fnRegisterStatement(stmt.id.name, targetKey));
814
+ // The view script runs inside `try { ... }`. A plain function declared in a block still becomes a
815
+ // global (Annex B), but async and generator ones stay block-scoped — V1 ran scripts unwrapped, so
816
+ // `async function save(){}` was window.save for onclick=, other scripts and @-handlers.
817
+ if (stmt.async || stmt.generator) newBody.push(_windowExportStatement(stmt.id.name));
797
818
  continue;
798
819
  }
799
820
 
@@ -496,11 +496,15 @@ var miniTB = [
496
496
  };
497
497
  })(HTMLFormElement.prototype.submit);
498
498
 
499
- HTMLElement.prototype.setAttributeNative = HTMLElement.prototype.setAttribute;
500
- HTMLElement.prototype.removeAttributeNative = HTMLElement.prototype.removeAttribute;
501
- HTMLElement.prototype.getAttributeNative = HTMLElement.prototype.getAttribute;
502
- (function (setAttribute) {
503
- HTMLElement.prototype.setAttribute = function (prop, val) {
499
+ // `@event` attributes live on el.events, not in the DOM. SVG elements (inline icons, charts) need the same
500
+ // redirection as HTML ones, or `<circle @click="...">` loses its handler.
501
+ [HTMLElement, typeof SVGElement !== "undefined" ? SVGElement : null].forEach(function (Ctor) {
502
+ if (!Ctor) return;
503
+ var P = Ctor.prototype;
504
+ P.setAttributeNative = P.setAttribute;
505
+ P.removeAttributeNative = P.removeAttribute;
506
+ P.getAttributeNative = P.getAttribute;
507
+ P.setAttribute = function (prop, val) {
504
508
  if (prop.substr(0, 1) == "@") {
505
509
  try {
506
510
  this.events[prop] = val;
@@ -511,9 +515,7 @@ HTMLElement.prototype.getAttributeNative = HTMLElement.prototype.getAttribute;
511
515
  this.setAttributeNative(prop, val);
512
516
  }
513
517
  };
514
- })(HTMLElement.prototype.setAttribute);
515
- (function (removeAttribute) {
516
- HTMLElement.prototype.removeAttribute = function (prop, val) {
518
+ P.removeAttribute = function (prop, val) {
517
519
  if (prop.substr(0, 1) == "@") {
518
520
  try {
519
521
  delete this.events[prop];
@@ -524,9 +526,7 @@ HTMLElement.prototype.getAttributeNative = HTMLElement.prototype.getAttribute;
524
526
  this.removeAttributeNative(prop, val);
525
527
  }
526
528
  };
527
- })(HTMLElement.prototype.removeAttribute);
528
- (function (getAttribute) {
529
- HTMLElement.prototype.getAttribute = function (prop, val) {
529
+ P.getAttribute = function (prop, val) {
530
530
  if (prop.substr(0, 1) == "@") {
531
531
  try {
532
532
  return this.events[prop];
@@ -537,7 +537,7 @@ HTMLElement.prototype.getAttributeNative = HTMLElement.prototype.getAttribute;
537
537
  return this.getAttributeNative(prop, val);
538
538
  }
539
539
  };
540
- })(HTMLElement.prototype.getAttribute);
540
+ });
541
541
 
542
542
  /*jolie */
543
543
  // (function(){
@@ -612,6 +612,22 @@ function _onGlobalsDeepChange() {
612
612
  if (typeof _vt !== 'undefined' && _vt.Global && _vt.Global.vars) {
613
613
  _vt.Global.vars.globals = globals;
614
614
  }
615
+ _scheduleGlobalsSave();
616
+ }
617
+ // V1 wrote `globals` to localStorage whenever it changed (its tick compared it with the last saved copy), so it
618
+ // survived reloads and reached other tabs. V2 had that save commented out. Save on change instead of polling;
619
+ // only a real difference is written, which also stops two tabs echoing each other's `storage` events.
620
+ var _globalsSaveQueued = false;
621
+ function _scheduleGlobalsSave() {
622
+ if (_globalsSaveQueued) return;
623
+ _globalsSaveQueued = true;
624
+ setTimeout(function () {
625
+ _globalsSaveQueued = false;
626
+ try {
627
+ var json = JSON.stringify(_globalsBackingValue === undefined ? {} : _globalsBackingValue);
628
+ if (localStorage.getItem("globals") !== json) localStorage.setItem("globals", json);
629
+ } catch (e) { /* storage full, blocked, or a value JSON cannot encode */ }
630
+ }, 0);
615
631
  }
616
632
  globals = clone(JSON.parse(localStorage.getItem("globals")));
617
633
  let _rx = clone(JSON.parse(localStorage.getItem("_rx")));
@@ -624,6 +640,7 @@ var cntrlon = 0;
624
640
  var _gn = 0,
625
641
  _worker;
626
642
  var nodes = [];
643
+ var historyStack = [];
627
644
 
628
645
  var _jsuid = {};
629
646
  // 'use strict';
@@ -738,12 +755,12 @@ function iterateConditions(text) {
738
755
  return results;
739
756
  }
740
757
 
758
+ // Pause / resume rendering only. The loader is the developer's to show (`_loader.show()`), never implied here
759
+ // (decided 2026-10-02; canonical V1 core.js does the same — only a 2023 V1 variant showed it).
741
760
  function wait() {
742
- _loader.show();
743
761
  _initialized = false;
744
762
  }
745
763
  function resume() {
746
- _loader.hide();
747
764
  _initialized = true;
748
765
  }
749
766
 
@@ -1314,6 +1331,14 @@ function getURLNodes() {
1314
1331
  // let authFunc = (appSettings.auth && typeof appSettings.auth === "function") ? appSettings.auth : (typeof Auth === "function" ? Auth : null);
1315
1332
  // if (typeof authFunc === 'function') authFunc();
1316
1333
  if (!_nodes[0]) _nodes[0] = appSettings.defaultView ?? "home";
1334
+
1335
+ if (historyStack[historyStack.length - 1]?.url != window.location.href)
1336
+ historyStack.push({
1337
+ "nodes": _nodes,
1338
+ "params": paramsToObj(window.location.href),
1339
+ "url": window.location.href
1340
+ });
1341
+
1317
1342
  return _nodes;
1318
1343
  }
1319
1344
  var prevNodes = [];
@@ -1944,6 +1969,9 @@ function renderPlugins() {
1944
1969
  t.attr("upid", sl);
1945
1970
  t.prepend(`<input ` + (mxf > 1 ? 'multiple' : '') + ` type="file" ` + "" + ` files style="display:none;" />`);
1946
1971
  _ups.push(t);
1972
+ // Start the upload worker as soon as the page has an uploader (V1 started it at boot), so the first
1973
+ // files-added is not delayed by the worker loading.
1974
+ if (typeof _upwrkStarted === "function") _upwrkStarted();
1947
1975
  }
1948
1976
  });
1949
1977
 
@@ -5052,13 +5080,20 @@ $("body").on("click touch", "[order]", function (ev) {
5052
5080
  pendingSingleTap = null;
5053
5081
  fire(state.target, "doubletap");
5054
5082
  } else {
5055
- pendingSingleTap = {
5083
+ // A tap on a different element settles the previous one now (it was a single tap). Leaving its
5084
+ // timer running let it clear THIS pending tap later, losing this element's double-tap.
5085
+ if (pendingSingleTap) {
5086
+ clearTimeout(pendingSingleTap.timer);
5087
+ fire(pendingSingleTap.target, "singletap");
5088
+ }
5089
+ var pending = {
5056
5090
  target: state.target,
5057
5091
  timer: setTimeout(function () {
5058
- fire(state.target, "singletap");
5059
- pendingSingleTap = null;
5092
+ fire(pending.target, "singletap");
5093
+ if (pendingSingleTap === pending) pendingSingleTap = null;
5060
5094
  }, DOUBLE_TAP_WINDOW_MS),
5061
5095
  };
5096
+ pendingSingleTap = pending;
5062
5097
  }
5063
5098
  }
5064
5099
  return;