tina4js 1.0.9 → 1.0.11
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/core.cjs.js +1 -1
- package/dist/core.es.js +64 -63
- package/package.json +1 -1
- package/readme.md +41 -1
package/dist/core.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./signal.cjs.js"),b=require("./component.cjs.js"),_=new WeakMap,m="t4:";function N(t,...e){let n=_.get(t);if(!n){n=document.createElement("template");let f="";for(let
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./signal.cjs.js"),b=require("./component.cjs.js"),_=new WeakMap,m="t4:";function N(t,...e){let n=_.get(t);if(!n){n=document.createElement("template");let f="";for(let c=0;c<t.length;c++)f+=t[c],c<e.length&&(E(f)?f+=`__t4_${c}__`:f+=`<!--${m}${c}-->`);n.innerHTML=f,_.set(t,n)}const o=n.content.cloneNode(!0),i=y(o);for(const{marker:f,index:c}of i)S(f,e[c]);const r=C(o);for(const f of r)T(f,e);return o}function y(t){const e=[];return p(t,n=>{if(n.nodeType===8){const o=n.data;if(o&&o.startsWith(m)){const i=parseInt(o.slice(m.length),10);e.push({marker:n,index:i})}}}),e}function C(t){const e=[];return p(t,n=>{n.nodeType===1&&e.push(n)}),e}function p(t,e){const n=t.childNodes;for(let o=0;o<n.length;o++){const i=n[o];e(i),p(i,e)}}function S(t,e){const n=t.parentNode;if(n)if(s.isSignal(e)){const o=document.createTextNode("");n.replaceChild(o,t),s.effect(()=>{o.data=String(e.value??"")})}else if(typeof e=="function"){const o=document.createComment("");n.replaceChild(o,t);let i=[],r=[];s.effect(()=>{var g;for(const d of r)d();r=[];const f=[],c=s._getEffectCollector();s._setEffectCollector(f);const a=e();s._setEffectCollector(c),r=f;for(const d of i)(g=d.parentNode)==null||g.removeChild(d);i=[];const l=h(a),u=o.parentNode;if(u)for(const d of l)u.insertBefore(d,o),i.push(d)})}else if(A(e))n.replaceChild(e,t);else if(e instanceof Node)n.replaceChild(e,t);else if(Array.isArray(e)){const o=document.createDocumentFragment();for(const i of e){const r=h(i);for(const f of r)o.appendChild(f)}n.replaceChild(o,t)}else{const o=document.createTextNode(String(e??""));n.replaceChild(o,t)}}function T(t,e){const n=[];for(const o of Array.from(t.attributes)){const i=o.name,r=o.value;if(i.startsWith("@")){const c=i.slice(1),a=r.match(/__t4_(\d+)__/);if(a){const l=e[parseInt(a[1],10)];typeof l=="function"&&t.addEventListener(c,u=>s.batch(()=>l(u)))}n.push(i);continue}if(i.startsWith("?")){const c=i.slice(1),a=r.match(/__t4_(\d+)__/);if(a){const l=e[parseInt(a[1],10)];if(s.isSignal(l)){const u=l;s.effect(()=>{u.value?t.setAttribute(c,""):t.removeAttribute(c)})}else typeof l=="function"?s.effect(()=>{l()?t.setAttribute(c,""):t.removeAttribute(c)}):l&&t.setAttribute(c,"")}n.push(i);continue}if(i.startsWith(".")){const c=i.slice(1),a=r.match(/__t4_(\d+)__/);if(a){const l=e[parseInt(a[1],10)];s.isSignal(l)?s.effect(()=>{t[c]=l.value}):t[c]=l}n.push(i);continue}const f=r.match(/__t4_(\d+)__/);if(f){const c=e[parseInt(f[1],10)];if(s.isSignal(c)){const a=c;s.effect(()=>{t.setAttribute(i,String(a.value??""))})}else typeof c=="function"?s.effect(()=>{t.setAttribute(i,String(c()??""))}):t.setAttribute(i,String(c??""))}}for(const o of n)t.removeAttribute(o)}function h(t){if(t==null||t===!1)return[];if(A(t))return Array.from(t.childNodes);if(t instanceof Node)return[t];if(Array.isArray(t)){const e=[];for(const n of t)e.push(...h(n));return e}return[document.createTextNode(String(t))]}function A(t){return t!=null&&typeof t=="object"&&t.nodeType===11}function E(t){let e=!1,n=!1,o=!1;for(let i=0;i<t.length;i++){const r=t[i];r==="<"&&!e&&!n&&(o=!0),r===">"&&!e&&!n&&(o=!1),o&&(r==='"'&&!e&&(n=!n),r==="'"&&!n&&(e=!e))}return o}exports.batch=s.batch;exports.computed=s.computed;exports.effect=s.effect;exports.isSignal=s.isSignal;exports.signal=s.signal;exports.Tina4Element=b.Tina4Element;exports.html=N;
|
package/dist/core.es.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { i as
|
|
1
|
+
import { i as u, e as d, a as C, d as A, b as y } from "./signal.es.js";
|
|
2
2
|
import { c as M, s as R } from "./signal.es.js";
|
|
3
3
|
import { T as F } from "./component.es.js";
|
|
4
|
-
const N = /* @__PURE__ */ new WeakMap(),
|
|
4
|
+
const N = /* @__PURE__ */ new WeakMap(), p = "t4:";
|
|
5
5
|
function D(t, ...e) {
|
|
6
6
|
let n = N.get(t);
|
|
7
7
|
if (!n) {
|
|
8
8
|
n = document.createElement("template");
|
|
9
|
-
let
|
|
9
|
+
let c = "";
|
|
10
10
|
for (let r = 0; r < t.length; r++)
|
|
11
|
-
|
|
12
|
-
n.innerHTML =
|
|
11
|
+
c += t[r], r < e.length && (I(c) ? c += `__t4_${r}__` : c += `<!--${p}${r}-->`);
|
|
12
|
+
n.innerHTML = c, N.set(t, n);
|
|
13
13
|
}
|
|
14
14
|
const o = n.content.cloneNode(!0), s = T(o);
|
|
15
|
-
for (const { marker:
|
|
16
|
-
E(
|
|
17
|
-
const
|
|
18
|
-
for (const
|
|
19
|
-
S(
|
|
15
|
+
for (const { marker: c, index: r } of s)
|
|
16
|
+
E(c, e[r]);
|
|
17
|
+
const i = x(o);
|
|
18
|
+
for (const c of i)
|
|
19
|
+
S(c, e);
|
|
20
20
|
return o;
|
|
21
21
|
}
|
|
22
22
|
function T(t) {
|
|
@@ -24,8 +24,8 @@ function T(t) {
|
|
|
24
24
|
return _(t, (n) => {
|
|
25
25
|
if (n.nodeType === 8) {
|
|
26
26
|
const o = n.data;
|
|
27
|
-
if (o && o.startsWith(
|
|
28
|
-
const s = parseInt(o.slice(
|
|
27
|
+
if (o && o.startsWith(p)) {
|
|
28
|
+
const s = parseInt(o.slice(p.length), 10);
|
|
29
29
|
e.push({ marker: n, index: s });
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -47,39 +47,39 @@ function _(t, e) {
|
|
|
47
47
|
function E(t, e) {
|
|
48
48
|
const n = t.parentNode;
|
|
49
49
|
if (n)
|
|
50
|
-
if (
|
|
50
|
+
if (u(e)) {
|
|
51
51
|
const o = document.createTextNode("");
|
|
52
|
-
n.replaceChild(o, t),
|
|
52
|
+
n.replaceChild(o, t), d(() => {
|
|
53
53
|
o.data = String(e.value ?? "");
|
|
54
54
|
});
|
|
55
55
|
} else if (typeof e == "function") {
|
|
56
56
|
const o = document.createComment("");
|
|
57
57
|
n.replaceChild(o, t);
|
|
58
|
-
let s = [],
|
|
59
|
-
|
|
58
|
+
let s = [], i = [];
|
|
59
|
+
d(() => {
|
|
60
60
|
var g;
|
|
61
|
-
for (const l of
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
A(
|
|
65
|
-
const
|
|
66
|
-
A(r),
|
|
61
|
+
for (const l of i) l();
|
|
62
|
+
i = [];
|
|
63
|
+
const c = [], r = C();
|
|
64
|
+
A(c);
|
|
65
|
+
const a = e();
|
|
66
|
+
A(r), i = c;
|
|
67
67
|
for (const l of s) (g = l.parentNode) == null || g.removeChild(l);
|
|
68
68
|
s = [];
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
for (const l of
|
|
72
|
-
|
|
69
|
+
const f = h(a), m = o.parentNode;
|
|
70
|
+
if (m)
|
|
71
|
+
for (const l of f)
|
|
72
|
+
m.insertBefore(l, o), s.push(l);
|
|
73
73
|
});
|
|
74
|
-
} else if (
|
|
74
|
+
} else if (b(e))
|
|
75
75
|
n.replaceChild(e, t);
|
|
76
76
|
else if (e instanceof Node)
|
|
77
77
|
n.replaceChild(e, t);
|
|
78
78
|
else if (Array.isArray(e)) {
|
|
79
79
|
const o = document.createDocumentFragment();
|
|
80
80
|
for (const s of e) {
|
|
81
|
-
const
|
|
82
|
-
for (const
|
|
81
|
+
const i = h(s);
|
|
82
|
+
for (const c of i) o.appendChild(c);
|
|
83
83
|
}
|
|
84
84
|
n.replaceChild(o, t);
|
|
85
85
|
} else {
|
|
@@ -90,51 +90,52 @@ function E(t, e) {
|
|
|
90
90
|
function S(t, e) {
|
|
91
91
|
const n = [];
|
|
92
92
|
for (const o of Array.from(t.attributes)) {
|
|
93
|
-
const s = o.name,
|
|
93
|
+
const s = o.name, i = o.value;
|
|
94
94
|
if (s.startsWith("@")) {
|
|
95
|
-
const r = s.slice(1),
|
|
96
|
-
if (
|
|
97
|
-
const
|
|
98
|
-
typeof
|
|
95
|
+
const r = s.slice(1), a = i.match(/__t4_(\d+)__/);
|
|
96
|
+
if (a) {
|
|
97
|
+
const f = e[parseInt(a[1], 10)];
|
|
98
|
+
typeof f == "function" && t.addEventListener(r, (m) => y(() => f(m)));
|
|
99
99
|
}
|
|
100
100
|
n.push(s);
|
|
101
101
|
continue;
|
|
102
102
|
}
|
|
103
103
|
if (s.startsWith("?")) {
|
|
104
|
-
const r = s.slice(1),
|
|
105
|
-
if (
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
const r = s.slice(1), a = i.match(/__t4_(\d+)__/);
|
|
105
|
+
if (a) {
|
|
106
|
+
const f = e[parseInt(a[1], 10)];
|
|
107
|
+
if (u(f)) {
|
|
108
|
+
const m = f;
|
|
109
|
+
d(() => {
|
|
110
|
+
m.value ? t.setAttribute(r, "") : t.removeAttribute(r);
|
|
111
111
|
});
|
|
112
|
-
} else
|
|
113
|
-
|
|
112
|
+
} else typeof f == "function" ? d(() => {
|
|
113
|
+
f() ? t.setAttribute(r, "") : t.removeAttribute(r);
|
|
114
|
+
}) : f && t.setAttribute(r, "");
|
|
114
115
|
}
|
|
115
116
|
n.push(s);
|
|
116
117
|
continue;
|
|
117
118
|
}
|
|
118
119
|
if (s.startsWith(".")) {
|
|
119
|
-
const r = s.slice(1),
|
|
120
|
-
if (
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
t[r] =
|
|
124
|
-
}) : t[r] =
|
|
120
|
+
const r = s.slice(1), a = i.match(/__t4_(\d+)__/);
|
|
121
|
+
if (a) {
|
|
122
|
+
const f = e[parseInt(a[1], 10)];
|
|
123
|
+
u(f) ? d(() => {
|
|
124
|
+
t[r] = f.value;
|
|
125
|
+
}) : t[r] = f;
|
|
125
126
|
}
|
|
126
127
|
n.push(s);
|
|
127
128
|
continue;
|
|
128
129
|
}
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
131
|
-
const r = e[parseInt(
|
|
132
|
-
if (
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
t.setAttribute(s, String(
|
|
130
|
+
const c = i.match(/__t4_(\d+)__/);
|
|
131
|
+
if (c) {
|
|
132
|
+
const r = e[parseInt(c[1], 10)];
|
|
133
|
+
if (u(r)) {
|
|
134
|
+
const a = r;
|
|
135
|
+
d(() => {
|
|
136
|
+
t.setAttribute(s, String(a.value ?? ""));
|
|
136
137
|
});
|
|
137
|
-
} else typeof r == "function" ?
|
|
138
|
+
} else typeof r == "function" ? d(() => {
|
|
138
139
|
t.setAttribute(s, String(r() ?? ""));
|
|
139
140
|
}) : t.setAttribute(s, String(r ?? ""));
|
|
140
141
|
}
|
|
@@ -143,7 +144,7 @@ function S(t, e) {
|
|
|
143
144
|
}
|
|
144
145
|
function h(t) {
|
|
145
146
|
if (t == null || t === !1) return [];
|
|
146
|
-
if (
|
|
147
|
+
if (b(t)) return Array.from(t.childNodes);
|
|
147
148
|
if (t instanceof Node) return [t];
|
|
148
149
|
if (Array.isArray(t)) {
|
|
149
150
|
const e = [];
|
|
@@ -152,14 +153,14 @@ function h(t) {
|
|
|
152
153
|
}
|
|
153
154
|
return [document.createTextNode(String(t))];
|
|
154
155
|
}
|
|
155
|
-
function
|
|
156
|
+
function b(t) {
|
|
156
157
|
return t != null && typeof t == "object" && t.nodeType === 11;
|
|
157
158
|
}
|
|
158
159
|
function I(t) {
|
|
159
160
|
let e = !1, n = !1, o = !1;
|
|
160
161
|
for (let s = 0; s < t.length; s++) {
|
|
161
|
-
const
|
|
162
|
-
|
|
162
|
+
const i = t[s];
|
|
163
|
+
i === "<" && !e && !n && (o = !0), i === ">" && !e && !n && (o = !1), o && (i === '"' && !e && (n = !n), i === "'" && !n && (e = !e));
|
|
163
164
|
}
|
|
164
165
|
return o;
|
|
165
166
|
}
|
|
@@ -167,8 +168,8 @@ export {
|
|
|
167
168
|
F as Tina4Element,
|
|
168
169
|
y as batch,
|
|
169
170
|
M as computed,
|
|
170
|
-
|
|
171
|
+
d as effect,
|
|
171
172
|
D as html,
|
|
172
|
-
|
|
173
|
+
u as isSignal,
|
|
173
174
|
R as signal
|
|
174
175
|
};
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# Tina4-JS
|
|
2
2
|
|
|
3
|
-
Sub-3KB reactive framework — signals, web components, routing, and
|
|
3
|
+
Sub-3KB reactive framework — signals, web components, routing, PWA, WebSocket, and API client.
|
|
4
4
|
|
|
5
5
|
Works standalone or embedded inside [tina4-php](https://github.com/tina4stack/tina4-php) / [tina4-python](https://github.com/tina4stack/tina4-python).
|
|
6
6
|
|
|
7
|
+
**[Live Gallery — 9 real-world examples](https://tina4stack.github.io/tina4-js/examples/gallery/)** · dashboards, CRUD, chat, auth, cart, forms, PWA, data tables, and live search — all self-contained, no build step.
|
|
8
|
+
|
|
7
9
|
## Why?
|
|
8
10
|
|
|
9
11
|
| Feature | React | Preact | Vue | **tina4-js** |
|
|
@@ -193,6 +195,29 @@ pwa.register({
|
|
|
193
195
|
});
|
|
194
196
|
```
|
|
195
197
|
|
|
198
|
+
### WebSocket — Signal-driven real-time
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
import { ws } from 'tina4js/ws';
|
|
202
|
+
|
|
203
|
+
const socket = ws.connect('wss://api.example.com/ws');
|
|
204
|
+
|
|
205
|
+
// Reactive signals — use in html templates
|
|
206
|
+
socket.status.value; // 'connecting' | 'open' | 'closed' | 'reconnecting'
|
|
207
|
+
socket.connected.value; // boolean — true when status is 'open'
|
|
208
|
+
socket.lastMessage.value; // last received message (JSON auto-parsed)
|
|
209
|
+
|
|
210
|
+
// Pipe messages into a signal
|
|
211
|
+
const messages = signal([]);
|
|
212
|
+
socket.pipe(messages, (msg, current) => [...current, msg]);
|
|
213
|
+
|
|
214
|
+
// Send
|
|
215
|
+
socket.send({ type: 'ping' }); // objects auto-JSON serialised
|
|
216
|
+
|
|
217
|
+
// Auto-reconnects with exponential backoff by default
|
|
218
|
+
socket.close(); // intentional close — no reconnect
|
|
219
|
+
```
|
|
220
|
+
|
|
196
221
|
### Debug Overlay
|
|
197
222
|
|
|
198
223
|
A built-in debug overlay that shows live signal values, component tree, route history, and API calls.
|
|
@@ -240,6 +265,21 @@ npm run dev # dev server
|
|
|
240
265
|
|
|
241
266
|
## Changelog
|
|
242
267
|
|
|
268
|
+
### 1.0.9
|
|
269
|
+
- **Fix:** All `@event` handlers are now automatically wrapped in `batch()` — multiple signal writes inside a single handler produce exactly one re-render after the event finishes, preventing mid-event DOM rebuilds and duplicate handler calls on re-rendered elements
|
|
270
|
+
|
|
271
|
+
### 1.0.8
|
|
272
|
+
- Added `--css` flag to `tina4 create` — scaffolds with [tina4-css](https://www.npmjs.com/package/tina4-css) included
|
|
273
|
+
- Added gallery of 9 real-world examples: [live demo](https://tina4stack.github.io/tina4-js/examples/gallery/)
|
|
274
|
+
|
|
275
|
+
### 1.0.7
|
|
276
|
+
- Added WebSocket module (`tina4js/ws`) with signal-driven status, auto-reconnect with exponential backoff, `pipe()` for streaming messages into signals, and JSON auto-parse/serialise
|
|
277
|
+
- Fixed effect error isolation — a throwing effect no longer blocks sibling effects
|
|
278
|
+
- Fixed API request/response correlation for concurrent requests
|
|
279
|
+
- Fixed API tracker always showing empty URL in debug overlay
|
|
280
|
+
- Added per-request `headers` and `params` to all API methods
|
|
281
|
+
- 231 tests across 10 test files
|
|
282
|
+
|
|
243
283
|
### 1.0.5
|
|
244
284
|
- **Fix:** Effects now properly unsubscribe from signals on dispose — prevents stale subscriptions accumulating in signal subscriber sets across navigations
|
|
245
285
|
- **Fix:** Function bindings in `html` templates now dispose inner effects when re-evaluated — fixes duplicate DOM nodes from nested reactive lists and conditionals
|