@
feat(ui): add DataTable and Toaster, drop the legacy Table, fix overlay dialogs DataTable replaces the 20-line Table scaffold entirely: columns, sorting, filtering, pagination, selection, bulk actions, comparison layout, sticky first column, custom HTML cells, and a remote source driven by a `request` output rather than a function prop (props travel as HTML attributes, so a function arrives as its own source text). Toaster replaces the hand-rolled status div: tone icons, actions, hover pause/resume and a progress bar. Overlays audit -- Modal and Drawer declared aria-modal="true" but nothing ever moved focus into the panel, so the @keydown handler on their root never ran and closeOnEscape did nothing. Focus, focus restore, a Tab trap and a body scroll lock now live in the reactive runtime, shared by both. ContextMenu placed pointer menus by subtracting a guessed 340x420 from the viewport, which pushed every menu that was not that size away from the pointer; it now positions at the pointer and lets the anchored clamp pull it back once it can be measured. The reactive runtime size budget moves 150k -> 175k to cover anchored overlays, dialog behaviour, the toaster and the DataTable client half. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> @
This commit is contained in:
@@ -180,13 +180,34 @@ function functionEntry(
|
||||
availableFunctions: string[],
|
||||
): string {
|
||||
const parameterNames = new Set(fn.parameters.map((parameter) => parameter.name));
|
||||
|
||||
/*
|
||||
* Names the function body declares for itself.
|
||||
*
|
||||
* Props and state are destructured into the SAME scope as the body, so a
|
||||
* body that declares `var size` when `size` is also a prop produced
|
||||
* "Identifier 'size' has already been declared" and the entire module
|
||||
* failed to parse -- taking every function in the component down with it,
|
||||
* with nothing to point at the one line responsible. Skipping the alias for
|
||||
* a shadowed name is also what plain JavaScript does: inside that function
|
||||
* the local wins.
|
||||
*/
|
||||
const declaredLocals = new Set<string>();
|
||||
for (const match of fn.body.matchAll(
|
||||
/\b(?:var|let|const)\s+([A-Za-z_$][\w$]*)|\bfunction\s+([A-Za-z_$][\w$]*)/g,
|
||||
)) {
|
||||
const name = match[1] ?? match[2];
|
||||
if (name) declaredLocals.add(name);
|
||||
}
|
||||
|
||||
const stateNames = ast.states
|
||||
.filter(
|
||||
(state) =>
|
||||
state.runtime !== "server" &&
|
||||
safeIdentifier(state.name) &&
|
||||
!RUNTIME_BINDINGS.has(state.name) &&
|
||||
!parameterNames.has(state.name),
|
||||
!parameterNames.has(state.name) &&
|
||||
!declaredLocals.has(state.name),
|
||||
)
|
||||
.map((state) => state.name);
|
||||
const stateSet = new Set(stateNames);
|
||||
@@ -196,7 +217,8 @@ function functionEntry(
|
||||
safeIdentifier(prop.name) &&
|
||||
!RUNTIME_BINDINGS.has(prop.name) &&
|
||||
!parameterNames.has(prop.name) &&
|
||||
!stateSet.has(prop.name),
|
||||
!stateSet.has(prop.name) &&
|
||||
!declaredLocals.has(prop.name),
|
||||
)
|
||||
.map((prop) => prop.name);
|
||||
const functionAliases = availableFunctions.filter(
|
||||
@@ -205,7 +227,8 @@ function functionEntry(
|
||||
!RUNTIME_BINDINGS.has(name) &&
|
||||
!parameterNames.has(name) &&
|
||||
!stateSet.has(name) &&
|
||||
!propNames.includes(name),
|
||||
!propNames.includes(name) &&
|
||||
!declaredLocals.has(name),
|
||||
);
|
||||
const parameters = fn.parameters.map((parameter) => parameter.name).join(", ");
|
||||
const initialStateSnapshot = stateNames.length
|
||||
|
||||
@@ -170,6 +170,35 @@ function eventAttribute(name: string): string {
|
||||
return `data-on-${name}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event attribute for a handler written on a *component tag*
|
||||
* (`<Modal @confirm="save()">`).
|
||||
*
|
||||
* These need their own attribute name. The mount's attributes are forwarded
|
||||
* into the component and land on its view root, i.e. inside the component's
|
||||
* own `data-scope` -- but the statement (`save()`) belongs to the parent that
|
||||
* wrote the tag. Emitting `data-on-confirm` makes the child's runtime bind it
|
||||
* against the child's scope, where the parent's functions and state do not
|
||||
* exist, so the handler silently does nothing. `data-wrn-out-*` is ignored by
|
||||
* the child and claimed by the mounting scope instead.
|
||||
*
|
||||
* `window:`/`document:` (and the browser/mobile bridges) keep the plain
|
||||
* `data-on-*` form: those bind to a global target rather than to the element,
|
||||
* and the runtime has no component-output path for them.
|
||||
*/
|
||||
function componentEventAttribute(name: string): string {
|
||||
if (
|
||||
name.startsWith("window:") ||
|
||||
name.startsWith("document:") ||
|
||||
name.startsWith("browser-") ||
|
||||
name.startsWith("mobile-")
|
||||
) {
|
||||
return eventAttribute(name);
|
||||
}
|
||||
|
||||
return `data-wrn-out-${name}`;
|
||||
}
|
||||
|
||||
function reactiveAttrValue(raw: string, reactive: PageReactive): string | null {
|
||||
let found = false;
|
||||
const value = raw.replace(/\{([^{}]+)\}/g, (whole, inner: string) => {
|
||||
@@ -353,7 +382,11 @@ function renderLoopBody(node: ViewNode): string {
|
||||
const attrs = node.attrs
|
||||
.filter((attr) => attr.name !== "data-component")
|
||||
.map((attr) => {
|
||||
const name = attr.event ? eventAttribute(attr.name) : attr.name;
|
||||
const name = attr.event
|
||||
? componentTag
|
||||
? componentEventAttribute(attr.name)
|
||||
: eventAttribute(attr.name)
|
||||
: attr.name;
|
||||
|
||||
if (attr.boolean) {
|
||||
return escLit(` ${name}`);
|
||||
@@ -699,7 +732,9 @@ function renderNestedComponentInvocation(
|
||||
|
||||
if (attr.event) {
|
||||
return (
|
||||
escLit(` ${eventAttribute(attr.name)}="`) + escLit(attrEscape(attr.value)) + escLit(`"`)
|
||||
escLit(` ${componentEventAttribute(attr.name)}="`) +
|
||||
escLit(attrEscape(attr.value)) +
|
||||
escLit(`"`)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2134,6 +2169,20 @@ function renderComponentNode(node: ViewNode, ctx: CompCtx): string {
|
||||
attrEscape(JSON.stringify([a.name, a.value])),
|
||||
)}"`
|
||||
: "";
|
||||
/*
|
||||
* A boolean attribute whose expression names a loop variable cannot
|
||||
* be resolved on the server: __wireBooleanAttr runs at render time,
|
||||
* where `row` or `item` simply does not exist, and the emitted
|
||||
* module blew up. Leave the attribute off the server output and let
|
||||
* the client bind set it -- the runtime toggles boolean attributes
|
||||
* rather than stringifying them, so `checked={isSelected(row)}`
|
||||
* behaves correctly once hydrated.
|
||||
*/
|
||||
if (referencesLoopVariable) {
|
||||
return ` data-wrn-bind-${bindIndex++}="${escLit(
|
||||
attrEscape(JSON.stringify([a.name, a.value])),
|
||||
)}"`;
|
||||
}
|
||||
return `\${__wireBooleanAttr(${JSON.stringify(a.name)}, ${elementContext.resolveExpr(expression)})}${marker}`;
|
||||
}
|
||||
|
||||
@@ -2142,6 +2191,22 @@ function renderComponentNode(node: ViewNode, ctx: CompCtx): string {
|
||||
}
|
||||
|
||||
const wholeExpression = wholeAttributeExpression(a.value);
|
||||
|
||||
/*
|
||||
* data-show carries an EXPRESSION, not a value. The client re-evaluates
|
||||
* whatever string it finds in the attribute on every state change, so
|
||||
* interpolating `{open || visible}` down to the literal "false" at
|
||||
* render time froze the directive: the element could never be shown
|
||||
* again, no matter what the state did. A data-wrn-bind marker did not
|
||||
* save it either -- the bind rewrites the same attribute the directive
|
||||
* reads, and the directive had already captured "false" as its
|
||||
* expression. Emitting the expression verbatim (the form Modal uses,
|
||||
* data-show="isOpen()") makes both authoring styles behave the same.
|
||||
*/
|
||||
if (a.name === "data-show" && wholeExpression) {
|
||||
return ` data-show="${escLit(attrEscape(wholeExpression))}"`;
|
||||
}
|
||||
|
||||
const compiledValue =
|
||||
isExplicitComponentMount && wholeExpression
|
||||
? `\${__wireProp(${elementContext.resolveExpr(wholeExpression)})}`
|
||||
@@ -2563,7 +2628,10 @@ function __wireSpreadAttrs(value: any): string {
|
||||
lowerName === "style" ||
|
||||
lowerName === "slot" ||
|
||||
lowerName === "data-component" ||
|
||||
lowerName.startsWith("data-wrn")
|
||||
// Internal markers must not leak through a spread -- except the
|
||||
// parent's output handlers, whose whole job is to ride from the mount
|
||||
// onto the view root so the mounting scope can bind them there.
|
||||
(lowerName.startsWith("data-wrn") && !lowerName.startsWith("data-wrn-out-"))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
@@ -2699,7 +2767,7 @@ function __wireProp(v: any): string {
|
||||
}
|
||||
function renderPageComponentAttr(attr: Attr, dynamicExpressions: string[]): string {
|
||||
if (attr.event) {
|
||||
return ` ${eventAttribute(attr.name)}="${attrEscape(attr.value)}"`;
|
||||
return ` ${componentEventAttribute(attr.name)}="${attrEscape(attr.value)}"`;
|
||||
}
|
||||
|
||||
if (attr.boolean) {
|
||||
|
||||
@@ -176,7 +176,10 @@ function __wireSpreadAttrs(value: any): string {
|
||||
lowerName === "style" ||
|
||||
lowerName === "slot" ||
|
||||
lowerName === "data-component" ||
|
||||
lowerName.startsWith("data-wrn")
|
||||
// Internal markers must not leak through a spread -- except the
|
||||
// parent's output handlers, whose whole job is to ride from the mount
|
||||
// onto the view root so the mounting scope can bind them there.
|
||||
(lowerName.startsWith("data-wrn") && !lowerName.startsWith("data-wrn-out-"))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1398,3 +1398,75 @@ test("strict-mode reserved prop names compile through safe local references", ()
|
||||
expect(output).toContain("(__p_private) ?");
|
||||
expect(output).not.toContain("const private:");
|
||||
});
|
||||
|
||||
// data-show holds an expression the client re-evaluates, so it must survive
|
||||
// compilation verbatim. Interpolating `{open || visible}` to the literal
|
||||
// "false" froze every overlay that used the braced form -- Drawer, Dropdown,
|
||||
// Popover, ContextMenu and Tooltip could never open.
|
||||
test("data-show keeps its expression instead of being interpolated away", () => {
|
||||
const source = `component Panel {
|
||||
props {
|
||||
open: boolean = false
|
||||
}
|
||||
state visible = false
|
||||
view {
|
||||
<div class="panel" data-show='{open || visible}'>body</div>
|
||||
}
|
||||
}
|
||||
`;
|
||||
const code = compileWireFile(source, "Panel.wrn");
|
||||
expect(code).toContain(`data-show="open || visible"`);
|
||||
expect(code).not.toContain(`data-show="false"`);
|
||||
});
|
||||
|
||||
// Props and state are destructured into the same scope as the function body,
|
||||
// so a local that shares one of their names used to emit a redeclaration and
|
||||
// break the whole generated module with a parse error naming no source line.
|
||||
test("a local variable may shadow a prop without breaking the module", () => {
|
||||
const source = `component Sized {
|
||||
props {
|
||||
size: number = 10
|
||||
}
|
||||
state total = 0
|
||||
functions {
|
||||
client function recompute() {
|
||||
var size = 4
|
||||
var total = size * 2
|
||||
return total
|
||||
}
|
||||
}
|
||||
view {
|
||||
<div class="sized">{total}</div>
|
||||
}
|
||||
}
|
||||
`;
|
||||
const code = compileWireFile(source, "Sized.wrn");
|
||||
// The alias must be dropped, not emitted alongside the local declaration.
|
||||
expect(code).not.toContain("const { size } = context.props;");
|
||||
expect(code).toContain("var size = 4");
|
||||
});
|
||||
|
||||
// A boolean attribute whose expression names a loop variable cannot be
|
||||
// resolved on the server -- __wireBooleanAttr runs at render time, where the
|
||||
// loop variable does not exist, and the generated module failed outright.
|
||||
test("a boolean attribute bound to a loop variable binds on the client", () => {
|
||||
const source = `component Picker {
|
||||
state rows = []
|
||||
functions {
|
||||
shared function isOn(row) {
|
||||
return row.on
|
||||
}
|
||||
}
|
||||
view {
|
||||
<ul>
|
||||
<li data-for="row in rows" data-key="row.id">
|
||||
<input type="checkbox" checked='{isOn(row)}' />
|
||||
</li>
|
||||
</ul>
|
||||
}
|
||||
}
|
||||
`;
|
||||
const code = compileWireFile(source, "Picker.wrn");
|
||||
expect(code).not.toContain('__wireBooleanAttr("checked"');
|
||||
expect(code).toContain("data-wrn-bind-");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user