@lmjs/core 2.2.2 → 2.3.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/bundle.js +1 -0
- package/dist/lumenjs-core.js +8 -6
- package/package.json +1 -1
- package/src/_re.js +368 -149
- package/src/lstnrs.js +47 -7
- package/src/reactive.js +274 -0
- package/src/walk.js +21 -0
- package/vendor/reconnecting-websocket.js +50 -15
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
527
|
-
let _ownFn =
|
|
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) {
|
|
@@ -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();
|
package/src/reactive.js
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
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, "&").replace(/</g, "<").replace(/>/g, ">"); }
|
|
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
|
+
if (!res.isV) {
|
|
178
|
+
var kids = n.childNodes;
|
|
179
|
+
for (var c = 0; c < kids.length; c++) {
|
|
180
|
+
var ch = _rxCompileNode(kids[c], name, rvSet);
|
|
181
|
+
if (ch) res.children.push(ch);
|
|
182
|
+
}
|
|
183
|
+
if (name === "style" && !res.children.length) res.children.push({ type: "text", content: "", mss: [], tag: "style" });
|
|
184
|
+
}
|
|
185
|
+
return res;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function _rxCompileHost(host) {
|
|
189
|
+
var rvSet = {}, hst = [], kids = host.childNodes;
|
|
190
|
+
for (var i = 0; i < kids.length; i++) {
|
|
191
|
+
var c = _rxCompileNode(kids[i], host.localName, rvSet);
|
|
192
|
+
if (c) hst.push(c);
|
|
193
|
+
}
|
|
194
|
+
return { hst: hst, reactiveVars: Object.keys(rvSet) };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async function _rxRender(host) {
|
|
198
|
+
host.classList.add("binded");
|
|
199
|
+
var compiled = _rxCompileHost(host);
|
|
200
|
+
var sub = null;
|
|
201
|
+
for (var p = host.parentNode; p; p = p.parentNode) { if (p.isSub === true) { sub = p; break; } }
|
|
202
|
+
var _re = await renderHST(compiled, "reactive", "section", undefined, null, ["View"], sub ? sub.vars : undefined, sub ? sub.fns : undefined);
|
|
203
|
+
_re._blankUnresolved = true;
|
|
204
|
+
|
|
205
|
+
// `bind="a, b as c"` on the closest ancestor: only the `as` aliases need work, every plain name already resolves
|
|
206
|
+
// through the view/global scope the engine reads from.
|
|
207
|
+
var bindEl = host.closest("[bind]");
|
|
208
|
+
if (bindEl) {
|
|
209
|
+
String(bindEl.getAttribute("bind") || "").split(",").forEach(function (v) {
|
|
210
|
+
var parts = v.trim().split(" as ");
|
|
211
|
+
if (parts.length === 2 && parts[0].trim() && parts[1].trim()) {
|
|
212
|
+
try { _re.vrs[parts[1].trim()] = _re.scopedEval(_re.reactiveVariables, parts[0].trim()); } catch (e) { }
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
host.textContent = "";
|
|
218
|
+
host.append.apply(host, _re._RealDOM);
|
|
219
|
+
_re._rxHost = host;
|
|
220
|
+
_reactiveEngines.push(_re);
|
|
221
|
+
_re.renderAll("section");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function _updateReactiveEngines(varName) {
|
|
225
|
+
for (var i = _reactiveEngines.length - 1; i >= 0; i--) {
|
|
226
|
+
var re = _reactiveEngines[i];
|
|
227
|
+
if (!re._rxHost || !re._rxHost.isConnected) { _reactiveEngines.splice(i, 1); continue; }
|
|
228
|
+
try { re.update(varName); } catch (e) { cl(e); }
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
(function () {
|
|
233
|
+
if (typeof MutationObserver === "undefined" || typeof document === "undefined" || !document.documentElement) return;
|
|
234
|
+
var pending = [], running = false;
|
|
235
|
+
|
|
236
|
+
function consider(node) {
|
|
237
|
+
if (!node || node.nodeType !== 1 || node._ownerRe) return;
|
|
238
|
+
if (node.hasAttribute("reactive")) pending.push(node);
|
|
239
|
+
if (node.firstElementChild) {
|
|
240
|
+
var found = node.querySelectorAll("[reactive]");
|
|
241
|
+
for (var i = 0; i < found.length; i++) pending.push(found[i]);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async function drain() {
|
|
246
|
+
if (running) return;
|
|
247
|
+
running = true;
|
|
248
|
+
var rendered = 0;
|
|
249
|
+
try {
|
|
250
|
+
while (pending.length) {
|
|
251
|
+
var h = pending.shift();
|
|
252
|
+
if (!h.isConnected || h._ownerRe || h.classList.contains("binded")) continue;
|
|
253
|
+
try { await _rxRender(h); rendered++; } catch (e) { reportLumenError({ stage: "reactive", error: e }); }
|
|
254
|
+
}
|
|
255
|
+
} finally { running = false; }
|
|
256
|
+
// V1 rendered [reactive] chunks inside globalWatch(), so the same pass initialized the plugins in them
|
|
257
|
+
// ([sl], [up], [date], forms, ...). Do one globalWatch() per batch of rendered chunks.
|
|
258
|
+
if (rendered && typeof globalWatch === "function") {
|
|
259
|
+
try { globalWatch(); } catch (e) { reportLumenError({ stage: "reactive", error: e }); }
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
new MutationObserver(function (records) {
|
|
264
|
+
for (var r = 0; r < records.length; r++) {
|
|
265
|
+
var added = records[r].addedNodes;
|
|
266
|
+
for (var k = 0; k < added.length; k++) consider(added[k]);
|
|
267
|
+
}
|
|
268
|
+
if (pending.length) drain();
|
|
269
|
+
}).observe(document.documentElement, { childList: true, subtree: true });
|
|
270
|
+
|
|
271
|
+
function scan() { consider(document.documentElement); if (pending.length) drain(); }
|
|
272
|
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", scan);
|
|
273
|
+
else setTimeout(scan, 0);
|
|
274
|
+
})();
|
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
|
-
|
|
500
|
-
|
|
501
|
-
HTMLElement.
|
|
502
|
-
|
|
503
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
})
|
|
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';
|
|
@@ -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
|
-
|
|
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(
|
|
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;
|