tw-framework 2.0.0 → 2.0.2
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/CHANGELOG.md +89 -0
- package/dist/hydration-runtime.js +21 -3
- package/dist/testing.cjs +856 -152
- package/dist/tw-runtime-client.mjs +118 -39
- package/dist/tw-server.mjs +838 -134
- package/dist/tw.mjs +975 -169
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,95 @@ Notable changes to TW Framework. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/), and the project uses
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [2.0.2]
|
|
8
|
+
|
|
9
|
+
A patch release: bug fixes only. No new features, no breaking changes, and no
|
|
10
|
+
public API changes -- 2.0.2 is a drop-in replacement for 2.0.1.
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **Runtime -- store getters over array state.** The documented cart pattern
|
|
15
|
+
(`getters: { count: (state) => state.items.length }` with
|
|
16
|
+
`add(item) { this.items.push(item) }`) returned a stale count: mutating an
|
|
17
|
+
array in place keeps the same identity, so nothing downstream was notified.
|
|
18
|
+
The state proxy now reports in-place mutation (`push`, `pop`, `splice`, `sort`,
|
|
19
|
+
and so on) back to its reactive value, so a getter over it recomputes.
|
|
20
|
+
- **Runtime -- `VirtualList.getFirstVisibleIndex()`.** It was clamped to the item
|
|
21
|
+
count rather than the last index, so a `scrollTop` past the content returned
|
|
22
|
+
`100` for a 100-item list instead of `99`.
|
|
23
|
+
- **Compiler -- the live-list template.** A loop rendered on an interactive page
|
|
24
|
+
carries its template in an attribute, which is decoded once when the page is
|
|
25
|
+
parsed and parsed again by the runtime. Only the quotes were escaped, so an
|
|
26
|
+
expression inside the template (`data-tw-if="it == "b""`) lost its
|
|
27
|
+
value at the first quote and evaluated to `it == `. The template now survives
|
|
28
|
+
that first decode intact.
|
|
29
|
+
- **Compiler -- `TW098`.** The warning fired on a call to an imported helper,
|
|
30
|
+
which the build does resolve and render correctly. Names from the page's own
|
|
31
|
+
imports are now treated as evaluable, so only a genuinely unknown callee is
|
|
32
|
+
flagged.
|
|
33
|
+
- **Runtime -- a conditional inside a live list.** The page-wide conditional
|
|
34
|
+
pass re-evaluated `data-tw-if` / `data-tw-not` inside a live list with the loop
|
|
35
|
+
variable out of scope, overwriting the per-item result and hiding the right
|
|
36
|
+
branch for every item. Elements owned by a list are skipped now; the list
|
|
37
|
+
itself still evaluates them with the variable bound.
|
|
38
|
+
- **Plugins -- `@tw/plugin-sitemap`.** An unconfigured `siteUrl` answered
|
|
39
|
+
`/sitemap.xml` with `500`, which reads as a server fault. It answers `503`
|
|
40
|
+
("not configured") now; the message is unchanged.
|
|
41
|
+
|
|
42
|
+
- **Build — the server-only boundary.** Importing a server module into a page the
|
|
43
|
+
documented way (`import { query } from "../../lib/db"`) was never rejected: the
|
|
44
|
+
walker only recognised the `lib/`-prefixed and `.server.ts` forms, so a
|
|
45
|
+
relative path into `lib/` was treated as an ordinary local module. Such an
|
|
46
|
+
import now fails the build with `TW1007`, and a `.server` module is recognised
|
|
47
|
+
with or without its extension. `lib/` is also copied into the output directory
|
|
48
|
+
only after that check passes, so a rejected build no longer leaves the server
|
|
49
|
+
source there.
|
|
50
|
+
- **Diagnostics — the SSRF lint (`TW117`).** It only matched a request-derived
|
|
51
|
+
name written directly inside `fetch(...)`, so the ordinary shape
|
|
52
|
+
(`const url = query.u; await fetch(url)`) passed silently. Assignments are now
|
|
53
|
+
followed, so a request-derived value stays request-derived through them.
|
|
54
|
+
|
|
55
|
+
## [2.0.1]
|
|
56
|
+
|
|
57
|
+
A patch release: bug fixes only. No new features, no breaking changes, and no
|
|
58
|
+
public API changes -- 2.0.1 is a drop-in replacement for 2.0.0.
|
|
59
|
+
|
|
60
|
+
### Fixed
|
|
61
|
+
|
|
62
|
+
- **Compiler -- expressions.** Grouped and nested expressions, string
|
|
63
|
+
concatenation, method calls, unary operators, `&&` (now yields its operand),
|
|
64
|
+
and `.length` on a string all evaluate the way the docs describe. A call to a
|
|
65
|
+
helper the page imports now works; an unknown callee no longer renders its own
|
|
66
|
+
argument; a `}` inside an expression no longer ends it early.
|
|
67
|
+
- **Compiler -- conditions and loops.** A parenthesised `if` condition takes the
|
|
68
|
+
right branch, and a loop over a computed collection (`.filter`, `.map`,
|
|
69
|
+
`.slice`, `.concat`, `.reverse`) renders its items instead of an empty list.
|
|
70
|
+
- **Compiler -- components and props.** A dynamic prop (`prop={expr}`) binds its
|
|
71
|
+
value; a prop written in the block form reaches the component; two or more
|
|
72
|
+
classes with an `on:` binding no longer merge into one class name; a nested
|
|
73
|
+
component no longer trips the circular check; `{page.description}` resolves and
|
|
74
|
+
the description meta is emitted once.
|
|
75
|
+
- **Compiler -- diagnostics.** An interpolation the build cannot evaluate raises
|
|
76
|
+
a warning (`TW098`) instead of silently rendering its source text.
|
|
77
|
+
- **Server.** Request-time render modes (`ssr`, `stream`) no longer 404 without a
|
|
78
|
+
`cache` block; an unmatched path is answered with the nearest `not-found.tw`
|
|
79
|
+
and the right status code; `error.tw` is rendered when a render fails; a named
|
|
80
|
+
slot is filled after the layout chain is applied; a static resource answers
|
|
81
|
+
only the methods that apply to it; `tw dev` runs a page's server blocks and
|
|
82
|
+
shows the dev error page when one fails.
|
|
83
|
+
- **Runtime.** Store getters and actions follow the documented forms, `subscribe`
|
|
84
|
+
receives the new value, catch-all routes match multiple segments, derived
|
|
85
|
+
values propagate in a consistent order, and two helpers no longer throw on
|
|
86
|
+
edge-case input.
|
|
87
|
+
- **Plugins.** A hook returns the first interception result rather than the last,
|
|
88
|
+
so one plugin no longer disables another's `onRequest`; a command registered by
|
|
89
|
+
a plugin is dispatched.
|
|
90
|
+
- **Tooling and docs.** `tw --help` reports the real version; the image, link and
|
|
91
|
+
head helpers produce the documented output; several documentation corrections.
|
|
92
|
+
- **Security hardening** across token lifetime, upload validation, content-type
|
|
93
|
+
checks, the crypto helpers and the link helpers. The details are intentionally
|
|
94
|
+
not enumerated here -- upgrade if you are on 2.0.0.
|
|
95
|
+
|
|
7
96
|
## [2.0.0]
|
|
8
97
|
|
|
9
98
|
### Added
|
|
@@ -56,9 +56,15 @@
|
|
|
56
56
|
// --- Conditional blocks -----------------------------------------------------
|
|
57
57
|
|
|
58
58
|
function refreshIfs(scope) {
|
|
59
|
+
// A conditional inside a live list belongs to that list: its expression uses
|
|
60
|
+
// the loop variable, which is bound only while the list renders. Evaluating
|
|
61
|
+
// it here (variable out of scope) hid the correct branch for every item, so
|
|
62
|
+
// the whole list showed the else branch.
|
|
63
|
+
var ownedByLoop = function (el) { return !!(el.closest && el.closest("tw-for")); };
|
|
59
64
|
var ifs = (scope || document).querySelectorAll("[data-tw-if]");
|
|
60
65
|
for (var i = 0; i < ifs.length; i++) {
|
|
61
66
|
var el = ifs[i];
|
|
67
|
+
if (ownedByLoop(el)) continue;
|
|
62
68
|
var val = evalExpr(el.getAttribute("data-tw-if"));
|
|
63
69
|
var show = !!val && val !== "false" && val !== "0" && val !== "";
|
|
64
70
|
el.style.display = show ? "" : "none";
|
|
@@ -66,6 +72,7 @@
|
|
|
66
72
|
var nots = (scope || document).querySelectorAll("[data-tw-not]");
|
|
67
73
|
for (var j = 0; j < nots.length; j++) {
|
|
68
74
|
var el2 = nots[j];
|
|
75
|
+
if (ownedByLoop(el2)) continue;
|
|
69
76
|
var val2 = evalExpr(el2.getAttribute("data-tw-not"));
|
|
70
77
|
var hide = !!val2 && val2 !== "false" && val2 !== "0" && val2 !== "";
|
|
71
78
|
el2.style.display = hide ? "none" : "";
|
|
@@ -90,12 +97,16 @@
|
|
|
90
97
|
var ifAttr = el.getAttribute && el.getAttribute("data-tw-if");
|
|
91
98
|
if (ifAttr !== null && ifAttr !== undefined && el.hasAttribute("data-tw-if")) {
|
|
92
99
|
var v1 = evalExpr(ifAttr);
|
|
93
|
-
|
|
100
|
+
// `undefined` means the expression could not be evaluated here (a name
|
|
101
|
+
// out of scope). Forcing "none" then hid a branch the build had already
|
|
102
|
+
// resolved correctly, so the whole list showed the wrong branch. Leave
|
|
103
|
+
// the markup alone when there is no answer.
|
|
104
|
+
if (v1 !== undefined) el.style.display = (v1 && v1 !== "false" && v1 !== "0" && v1 !== "") ? "" : "none";
|
|
94
105
|
}
|
|
95
106
|
var notAttr = el.getAttribute("data-tw-not");
|
|
96
107
|
if (notAttr !== null && notAttr !== undefined && el.hasAttribute("data-tw-not")) {
|
|
97
108
|
var v2 = evalExpr(notAttr);
|
|
98
|
-
el.style.display = (v2 && v2 !== "false" && v2 !== "0" && v2 !== "") ? "none" : "";
|
|
109
|
+
if (v2 !== undefined) el.style.display = (v2 && v2 !== "false" && v2 !== "0" && v2 !== "") ? "none" : "";
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
112
|
|
|
@@ -165,7 +176,14 @@
|
|
|
165
176
|
try { applyActiveClass(); } catch (e) { /* non-DOM context */ }
|
|
166
177
|
try { scanPrefetch(); } catch (e) { /* non-DOM context */ }
|
|
167
178
|
var spans = document.querySelectorAll("[data-tw-i]");
|
|
168
|
-
for (var i = 0; i < spans.length; i++)
|
|
179
|
+
for (var i = 0; i < spans.length; i++) {
|
|
180
|
+
// A span inside a live list belongs to that list: its expression uses the
|
|
181
|
+
// loop variable, which is only bound while the list renders. Evaluating it
|
|
182
|
+
// here (with the variable out of scope) blanked the text the build had
|
|
183
|
+
// already produced correctly.
|
|
184
|
+
if (spans[i].closest && spans[i].closest("tw-for")) continue;
|
|
185
|
+
setSpanText(spans[i], spans[i].getAttribute("data-tw-i"));
|
|
186
|
+
}
|
|
169
187
|
var inputs = document.querySelectorAll("[data-tw-model]");
|
|
170
188
|
for (var j = 0; j < inputs.length; j++) {
|
|
171
189
|
var key = inputs[j].getAttribute("data-tw-model");
|