@native-sdk/cli 0.8.0 → 0.8.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/README.md +4 -4
- package/build.zig +49 -23
- package/package.json +10 -10
- package/packages/core/compile-surface/core.ts +16 -0
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/core.d.ts +11 -0
- package/packages/core/sdk/core.ts +29 -2
- package/packages/core/sdk/events.d.ts +10 -0
- package/packages/core/sdk/events.ts +24 -4
- package/packages/core/src/checker.ts +1 -1
- package/packages/core/src/contract.ts +4 -1
- package/packages/core/src/devhost.ts +10 -1
- package/packages/core/src/diagnostics.ts +1 -1
- package/skill-data/core/SKILL.md +48 -20
- package/skill-data/core/references/app-model-runtime.md +2 -2
- package/skill-data/core/references/project-anatomy.md +22 -6
- package/skill-data/native-ui/SKILL.md +71 -29
- package/skill-data/ts-core/SKILL.md +13 -8
- package/skill-data/zig/SKILL.md +1 -1
- package/skills/native-sdk/SKILL.md +6 -5
- package/src/app_runner/ts_core_main.zig +2 -1
- package/src/embed/tests.zig +3 -1
- package/src/platform/macos/appkit_host.h +4 -4
- package/src/platform/macos/appkit_host.m +24 -4
- package/src/platform/macos/cef_host.mm +22 -6
- package/src/platform/macos/root.zig +2 -2
- package/src/primitives/canvas/events.zig +8 -0
- package/src/primitives/canvas/markdown.zig +2010 -57
- package/src/primitives/canvas/markdown_hostile_tests.zig +40 -0
- package/src/primitives/canvas/markdown_tests.zig +778 -3
- package/src/primitives/canvas/root.zig +2 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/ui.zig +53 -8
- package/src/primitives/canvas/ui_markup.zig +10 -1
- package/src/primitives/canvas/ui_markup_compiled.zig +61 -3
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +27 -0
- package/src/primitives/canvas/ui_markup_contract.zig +31 -3
- package/src/primitives/canvas/ui_markup_reflect.zig +41 -0
- package/src/primitives/canvas/ui_markup_view.zig +49 -3
- package/src/primitives/canvas/ui_markup_view_tests.zig +61 -2
- package/src/primitives/canvas/ui_schema.zig +8 -1
- package/src/primitives/canvas/ui_schema_tests.zig +7 -6
- package/src/primitives/canvas/ui_tests.zig +14 -0
- package/src/primitives/canvas/widget_access.zig +4 -3
- package/src/primitives/canvas/widget_invalidation.zig +11 -0
- package/src/primitives/canvas/widget_layout.zig +26 -3
- package/src/primitives/canvas/widget_metrics.zig +21 -3
- package/src/primitives/canvas/widget_render.zig +87 -1
- package/src/primitives/canvas/widget_routing.zig +12 -7
- package/src/primitives/canvas/widget_runtime_tests.zig +132 -0
- package/src/primitives/canvas/widgets.zig +40 -0
- package/src/root.zig +1 -0
- package/src/runtime/automation_widget_dispatch.zig +19 -0
- package/src/runtime/canvas_limits.zig +5 -0
- package/src/runtime/canvas_widget_event_tests.zig +424 -8
- package/src/runtime/canvas_widget_events.zig +254 -7
- package/src/runtime/canvas_widget_state.zig +123 -1
- package/src/runtime/core.zig +6 -0
- package/src/runtime/effects.zig +36 -1
- package/src/runtime/effects_fetch_tests.zig +21 -0
- package/src/runtime/effects_notification_tests.zig +65 -0
- package/src/runtime/gpu_surface_events.zig +60 -14
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_core_host.zig +16 -0
- package/src/runtime/ts_ui_app.zig +55 -2
- package/src/runtime/ui_app.zig +112 -0
- package/src/runtime/ui_app_tests.zig +356 -0
- package/src/runtime/view.zig +35 -0
- package/src/runtime/view_widget_tree.zig +12 -0
- package/tools/corewire/core_abi.zig +1 -0
- package/tools/corewire/emit.zig +55 -8
- package/tools/corewire/emit_facade.zig +63 -2
- package/tools/corewire/emit_profile.zig +4 -1
- package/tools/corewire/sidecar.zig +36 -6
|
@@ -425,6 +425,7 @@ pub const DesignTokens = token_model.DesignTokens;
|
|
|
425
425
|
pub const WidgetKind = widget_model.WidgetKind;
|
|
426
426
|
pub const WidgetCursor = widget_model.WidgetCursor;
|
|
427
427
|
pub const WidgetState = widget_model.WidgetState;
|
|
428
|
+
pub const WidgetLayoutMotion = widget_model.WidgetLayoutMotion;
|
|
428
429
|
pub const WidgetRenderState = widget_model.WidgetRenderState;
|
|
429
430
|
pub const WidgetMainAlignment = widget_model.WidgetMainAlignment;
|
|
430
431
|
pub const WidgetCrossAlignment = widget_model.WidgetCrossAlignment;
|
|
@@ -625,6 +626,7 @@ pub const WidgetControlIntentKind = event_model.WidgetControlIntentKind;
|
|
|
625
626
|
pub const WidgetControlIntent = event_model.WidgetControlIntent;
|
|
626
627
|
pub const WidgetSemanticAction = event_model.WidgetSemanticAction;
|
|
627
628
|
pub const WidgetFileDropEvent = event_model.WidgetFileDropEvent;
|
|
629
|
+
pub const WidgetDragPhase = event_model.WidgetDragPhase;
|
|
628
630
|
pub const WidgetDragEvent = event_model.WidgetDragEvent;
|
|
629
631
|
pub const WidgetEventPhase = event_model.WidgetEventPhase;
|
|
630
632
|
pub const WidgetEventRouteEntry = event_model.WidgetEventRouteEntry;
|
|
@@ -227,6 +227,7 @@ pub const DesignTokens = canvas.DesignTokens;
|
|
|
227
227
|
pub const WidgetKind = canvas.WidgetKind;
|
|
228
228
|
pub const WidgetCursor = canvas.WidgetCursor;
|
|
229
229
|
pub const WidgetState = canvas.WidgetState;
|
|
230
|
+
pub const WidgetLayoutMotion = canvas.WidgetLayoutMotion;
|
|
230
231
|
pub const WidgetRenderState = canvas.WidgetRenderState;
|
|
231
232
|
pub const WidgetMainAlignment = canvas.WidgetMainAlignment;
|
|
232
233
|
pub const WidgetCrossAlignment = canvas.WidgetCrossAlignment;
|
|
@@ -312,6 +312,10 @@ pub const UiHandlerEvent = enum {
|
|
|
312
312
|
/// (select, then open/play), the way list selection conventions
|
|
313
313
|
/// expect.
|
|
314
314
|
double_press,
|
|
315
|
+
/// A draggable element moved, ended, or was cancelled. The handler's
|
|
316
|
+
/// sourceId comes from markup; live phase, coordinates, and view size
|
|
317
|
+
/// are injected by `Tree.msgForDrag`.
|
|
318
|
+
drag,
|
|
315
319
|
toggle,
|
|
316
320
|
change,
|
|
317
321
|
submit,
|
|
@@ -618,7 +622,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
618
622
|
min_width: f32 = 0,
|
|
619
623
|
grow: f32 = 0,
|
|
620
624
|
gap: f32 = 0,
|
|
621
|
-
padding: f32 =
|
|
625
|
+
padding: ?f32 = null,
|
|
622
626
|
main: canvas.WidgetMainAlignment = .start,
|
|
623
627
|
cross: canvas.WidgetCrossAlignment = .stretch,
|
|
624
628
|
/// Line policy for `text` leaves. `true`: word-wrap through
|
|
@@ -766,6 +770,12 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
766
770
|
/// the live bottom. Meaningless on every other element.
|
|
767
771
|
scrollback: u32 = 0,
|
|
768
772
|
on_press: ?Msg = null,
|
|
773
|
+
/// Live widget drag message (markup: `on-drag`). Its payload
|
|
774
|
+
/// is the closed `{ sourceId, phase, x, y, viewWidth,
|
|
775
|
+
/// viewHeight }` record: markup supplies `sourceId`, while the
|
|
776
|
+
/// runtime supplies phase (0 change, 1 end, 2 cancel) and the
|
|
777
|
+
/// four geometry fields.
|
|
778
|
+
on_drag: ?Msg = null,
|
|
769
779
|
/// Double-click Msg (markup: `on-double-press`): dispatched
|
|
770
780
|
/// on a release whose click count reached 2, in place of
|
|
771
781
|
/// `on_press` for that release. The FIRST click of the double
|
|
@@ -923,6 +933,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
923
933
|
wrap: ?bool = null,
|
|
924
934
|
style_tokens: StyleTokenRefs = .{},
|
|
925
935
|
on_press: ?Msg = null,
|
|
936
|
+
on_drag: ?Msg = null,
|
|
926
937
|
on_double_press: ?Msg = null,
|
|
927
938
|
on_toggle: ?Msg = null,
|
|
928
939
|
on_change: ?Msg = null,
|
|
@@ -1229,6 +1240,41 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
1229
1240
|
return null;
|
|
1230
1241
|
}
|
|
1231
1242
|
|
|
1243
|
+
/// Build a live drag Msg by copying the handler's authored
|
|
1244
|
+
/// source payload and injecting runtime phase + geometry.
|
|
1245
|
+
pub fn msgForDrag(self: Tree, id: ObjectId, drag: canvas.WidgetDragEvent, view_size: geometry.SizeF) ?Msg {
|
|
1246
|
+
for (self.handlers) |handler| {
|
|
1247
|
+
if (handler.id != id or handler.event != .drag or handler.action != .message) continue;
|
|
1248
|
+
return msgForDragTemplate(handler.action.message, drag, view_size);
|
|
1249
|
+
}
|
|
1250
|
+
return null;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
/// Rehydrate a previously captured drag handler template with the
|
|
1254
|
+
/// terminal phase and geometry. UiApp uses this when the source's
|
|
1255
|
+
/// phase-0 update unmounted the live handler before cancellation.
|
|
1256
|
+
pub fn msgForDragTemplate(template: Msg, drag: canvas.WidgetDragEvent, view_size: geometry.SizeF) ?Msg {
|
|
1257
|
+
return switch (template) {
|
|
1258
|
+
inline else => |payload, tag| if (comptime reflect.declaredWidgetDragDropRecord(@TypeOf(payload))) blk: {
|
|
1259
|
+
var out = payload;
|
|
1260
|
+
out.phase = dragNumber(@FieldType(@TypeOf(payload), "phase"), @floatFromInt(@intFromEnum(drag.phase)));
|
|
1261
|
+
out.x = dragNumber(@FieldType(@TypeOf(payload), "x"), drag.point.x);
|
|
1262
|
+
out.y = dragNumber(@FieldType(@TypeOf(payload), "y"), drag.point.y);
|
|
1263
|
+
out.viewWidth = dragNumber(@FieldType(@TypeOf(payload), "viewWidth"), view_size.width);
|
|
1264
|
+
out.viewHeight = dragNumber(@FieldType(@TypeOf(payload), "viewHeight"), view_size.height);
|
|
1265
|
+
break :blk @unionInit(Msg, @tagName(tag), out);
|
|
1266
|
+
} else null,
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
fn dragNumber(comptime Number: type, value: f32) Number {
|
|
1271
|
+
return switch (@typeInfo(Number)) {
|
|
1272
|
+
.float => @floatCast(value),
|
|
1273
|
+
.int => @intFromFloat(@round(value)),
|
|
1274
|
+
else => unreachable,
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1232
1278
|
/// Typed dispatch for text edits: builds the message through the
|
|
1233
1279
|
/// widget's `on_input` constructor.
|
|
1234
1280
|
pub fn msgForTextEdit(self: Tree, id: ObjectId, edit: canvas.TextInputEvent) ?Msg {
|
|
@@ -1469,6 +1515,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
1469
1515
|
.wrap = options.wrap,
|
|
1470
1516
|
.style_tokens = options.style_tokens,
|
|
1471
1517
|
.on_press = options.on_press,
|
|
1518
|
+
.on_drag = options.on_drag,
|
|
1472
1519
|
.on_double_press = options.on_double_press,
|
|
1473
1520
|
.on_toggle = options.on_toggle,
|
|
1474
1521
|
.on_change = options.on_change,
|
|
@@ -3335,6 +3382,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
3335
3382
|
// Typed handlers imply the matching accessibility actions, the
|
|
3336
3383
|
// same way a stringly `command` does for engine-owned dispatch.
|
|
3337
3384
|
if (node.on_press != null) widget.semantics.actions.press = true;
|
|
3385
|
+
if (node.on_drag != null) widget.semantics.actions.drag = true;
|
|
3338
3386
|
// A double-press handler makes the element pressable too:
|
|
3339
3387
|
// the double-click's first release must land somewhere, and
|
|
3340
3388
|
// an element that acts on double click without claiming
|
|
@@ -3383,6 +3431,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
3383
3431
|
widget.children = child_widgets;
|
|
3384
3432
|
}
|
|
3385
3433
|
appendHandler(handlers, handler_len, widget.id, .press, node.on_press);
|
|
3434
|
+
appendHandler(handlers, handler_len, widget.id, .drag, node.on_drag);
|
|
3386
3435
|
appendHandler(handlers, handler_len, widget.id, .double_press, node.on_double_press);
|
|
3387
3436
|
appendHandler(handlers, handler_len, widget.id, .toggle, node.on_toggle);
|
|
3388
3437
|
appendHandler(handlers, handler_len, widget.id, .change, node.on_change);
|
|
@@ -3534,6 +3583,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
3534
3583
|
fn countHandlers(node: Node) usize {
|
|
3535
3584
|
var total: usize = 0;
|
|
3536
3585
|
if (node.on_press != null) total += 1;
|
|
3586
|
+
if (node.on_drag != null) total += 1;
|
|
3537
3587
|
if (node.on_double_press != null) total += 1;
|
|
3538
3588
|
if (node.on_toggle != null) total += 1;
|
|
3539
3589
|
if (node.on_change != null) total += 1;
|
|
@@ -3614,7 +3664,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
3614
3664
|
/// default gap. Explicit spacing always wins for its own field.
|
|
3615
3665
|
fn applyKindDefaultLayout(kind: WidgetKind, options: ElementOptions, layout: *canvas.WidgetLayoutStyle) void {
|
|
3616
3666
|
const defaults = canvas.widgetKindDefaultLayout(kind, options.size) orelse return;
|
|
3617
|
-
if (options.padding ==
|
|
3667
|
+
if (options.padding == null) {
|
|
3618
3668
|
layout.padding = defaults.padding;
|
|
3619
3669
|
layout.padding_is_kind_default = true;
|
|
3620
3670
|
}
|
|
@@ -3654,12 +3704,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
3654
3704
|
.disabled = options.disabled,
|
|
3655
3705
|
},
|
|
3656
3706
|
.layout = .{
|
|
3657
|
-
.padding = .
|
|
3658
|
-
.top = options.padding,
|
|
3659
|
-
.right = options.padding,
|
|
3660
|
-
.bottom = options.padding,
|
|
3661
|
-
.left = options.padding,
|
|
3662
|
-
},
|
|
3707
|
+
.padding = geometry.InsetsF.all(options.padding orelse 0),
|
|
3663
3708
|
.gap = options.gap,
|
|
3664
3709
|
.grow = options.grow,
|
|
3665
3710
|
.main_alignment = options.main,
|
|
@@ -1122,6 +1122,7 @@ pub const on_scroll_legacy_payload_message = "on-scroll payloads are two-axis no
|
|
|
1122
1122
|
|
|
1123
1123
|
pub const on_resize_element_message = "on-resize is only supported on split - the runtime emits fraction changes for split dividers, so the handler belongs on the split element itself";
|
|
1124
1124
|
pub const on_resize_payload_message = "on-resize takes a bare Msg tag whose payload is the new first-pane fraction (an f32 variant, like sidebar_resized: f32; transpiled cores declare a one-number float arm)";
|
|
1125
|
+
pub const on_drag_payload_message = "on-drag takes a Msg tag plus one integer source binding (for example card_dragged:{card.id}); that Msg arm must be exactly { sourceId, phase, x, y, viewWidth, viewHeight } - sourceId is numeric, phase is numeric and must represent 0..2, and the four live geometry fields are f32/f64 (or wider floats) so captured out-of-view coordinates cannot overflow; markup fills sourceId and the runtime fills the rest";
|
|
1125
1126
|
pub const split_children_message = "split takes exactly two element children (the panes) - put conditional or repeated content inside a pane container, and nest splits for more panes";
|
|
1126
1127
|
|
|
1127
1128
|
/// Elements the runtime's dismissal machinery closes (Escape, click
|
|
@@ -1861,11 +1862,12 @@ pub const arena_scalar_equality_message = "arena-computed bindings cannot be com
|
|
|
1861
1862
|
pub const binding_text_buffer_message = "this binding names a TextBuffer field - the buffer is the edit model, not the text; bind a pub fn returning its text (pub fn draft(model: *const Model) []const u8 { return model.draft_buffer.text(); })";
|
|
1862
1863
|
pub const markdown_source_message = "markdown requires a source attribute with one {binding} naming the markdown text (a []const u8 field or fn - arena fns work)";
|
|
1863
1864
|
pub const markdown_children_message = "markdown takes no children or text content - the source binding provides the markdown";
|
|
1864
|
-
pub const markdown_attr_message = "unknown attribute for markdown - it takes source, on-link, on-details, details-expanded,
|
|
1865
|
+
pub const markdown_attr_message = "unknown attribute for markdown - it takes source, on-link, on-details, details-expanded, issue-link-base, and images";
|
|
1865
1866
|
pub const markdown_issue_link_base_message = "issue-link-base takes a literal URL prefix or one {binding} producing it - '#123' refs become links to base ++ number (like ghissue:// or https://github.com/owner/repo/issues/)";
|
|
1866
1867
|
pub const markdown_on_link_message = "on-link takes a bare Msg tag whose payload is the pressed link URL (a []const u8 variant, like open_url: []const u8)";
|
|
1867
1868
|
pub const markdown_on_details_message = "on-details takes a bare Msg tag whose payload is the details block index (a usize variant, like toggle_details: usize)";
|
|
1868
1869
|
pub const markdown_details_expanded_message = "details-expanded takes one {binding} naming a []const bool iterable (a model field, pub decl, or fn - the same sources for each accepts)";
|
|
1870
|
+
pub const markdown_images_message = "images takes one {binding} naming a []const canvas.markdown.ResolvedImage iterable (source, registered ImageId, width, and height); views never fetch image URLs implicitly";
|
|
1869
1871
|
pub const code_source_message = "code requires a source attribute with one {binding} naming the source text (a []const u8 field or fn - arena fns work)";
|
|
1870
1872
|
pub const code_children_message = "code takes no children or text content - the source binding provides the code";
|
|
1871
1873
|
pub const code_attr_message = "unknown attribute for code - it takes source, language, editable, on-input, line-numbers, added-lines, removed-lines, wrap, width, height, min-width, grow, key, global-key, and label";
|
|
@@ -2208,6 +2210,13 @@ fn validateMarkdown(node: MarkupNode) ?MarkupErrorInfo {
|
|
|
2208
2210
|
}
|
|
2209
2211
|
continue;
|
|
2210
2212
|
}
|
|
2213
|
+
if (std.mem.eql(u8, attribute.name, "images")) {
|
|
2214
|
+
const expression = parseAttrExpression(attribute.value);
|
|
2215
|
+
if (expression == null or expression.? != .binding) {
|
|
2216
|
+
return attrError(node, attribute, markdown_images_message);
|
|
2217
|
+
}
|
|
2218
|
+
continue;
|
|
2219
|
+
}
|
|
2211
2220
|
if (std.mem.eql(u8, attribute.name, "issue-link-base")) {
|
|
2212
2221
|
const expression = parseAttrExpression(attribute.value);
|
|
2213
2222
|
if (expression == null or expression.? == .equals) {
|
|
@@ -738,6 +738,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
738
738
|
if (std.mem.eql(u8, attribute.name, "on-details")) continue;
|
|
739
739
|
if (std.mem.eql(u8, attribute.name, "details-expanded")) continue;
|
|
740
740
|
if (std.mem.eql(u8, attribute.name, "issue-link-base")) continue;
|
|
741
|
+
if (std.mem.eql(u8, attribute.name, "images")) continue;
|
|
741
742
|
fail(node, markup.markdown_attr_message);
|
|
742
743
|
}
|
|
743
744
|
}
|
|
@@ -763,6 +764,9 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
763
764
|
if (comptime (node.attr("details-expanded") != null)) {
|
|
764
765
|
options.details_expanded = detailsExpandedItems(node, entries, comptime node.attr("details-expanded").?, ui, model, scope);
|
|
765
766
|
}
|
|
767
|
+
if (comptime (node.attr("images") != null)) {
|
|
768
|
+
options.images = markdownImageItems(node, entries, comptime node.attr("images").?, ui, model, scope);
|
|
769
|
+
}
|
|
766
770
|
if (comptime (node.attr("issue-link-base") != null)) {
|
|
767
771
|
const raw = comptime node.attr("issue-link-base").?;
|
|
768
772
|
comptime {
|
|
@@ -945,6 +949,31 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
945
949
|
return eachItems(info, ui, model);
|
|
946
950
|
}
|
|
947
951
|
|
|
952
|
+
/// Comptime twin of the interpreter's registered-image iterable
|
|
953
|
+
/// binding. Scope slice arguments shadow model iterables.
|
|
954
|
+
fn markdownImageItems(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime raw: []const u8, ui: *Ui, model: *const ModelT, scope: anytype) []const canvas.markdown.ResolvedImage {
|
|
955
|
+
const path = comptime blk: {
|
|
956
|
+
const expression = markup.parseAttrExpression(raw) orelse fail(node, markup.markdown_images_message);
|
|
957
|
+
if (expression != .binding) fail(node, markup.markdown_images_message);
|
|
958
|
+
break :blk expression.binding;
|
|
959
|
+
};
|
|
960
|
+
const scope_index_opt = comptime scopeIndex(entries, path);
|
|
961
|
+
if (comptime (scope_index_opt != null)) {
|
|
962
|
+
const scope_index = comptime scope_index_opt.?;
|
|
963
|
+
comptime {
|
|
964
|
+
if (entries[scope_index].kind != .slice_arg or entries[scope_index].Item != canvas.markdown.ResolvedImage) {
|
|
965
|
+
fail(node, markup.markdown_images_message);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
return scopePayload(entries, scope_index, scope);
|
|
969
|
+
}
|
|
970
|
+
const info = comptime (eachInfo(path) orelse fail(node, markup.markdown_images_message));
|
|
971
|
+
comptime {
|
|
972
|
+
if (info.Item != canvas.markdown.ResolvedImage) fail(node, markup.markdown_images_message);
|
|
973
|
+
}
|
|
974
|
+
return eachItems(info, ui, model);
|
|
975
|
+
}
|
|
976
|
+
|
|
948
977
|
// ------------------------------------------------ stepper/timeline
|
|
949
978
|
|
|
950
979
|
/// Comptime mirror of the interpreter's `buildStepper`: attrs and
|
|
@@ -2003,9 +2032,18 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2003
2032
|
};
|
|
2004
2033
|
},
|
|
2005
2034
|
.bool => @field(options, zig_field) = evalExpr(node, entries, raw, ui, model, scope).truthy(),
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2035
|
+
.optional => |optional| switch (@typeInfo(optional.child)) {
|
|
2036
|
+
.bool => @field(options, zig_field) = evalExpr(node, entries, raw, ui, model, scope).truthy(),
|
|
2037
|
+
.float => {
|
|
2038
|
+
comptime requireVariant(variant, &.{ .float, .integer }, node, "expected a number");
|
|
2039
|
+
@field(options, zig_field) = switch (evalExpr(node, entries, raw, ui, model, scope)) {
|
|
2040
|
+
.float => |float| float,
|
|
2041
|
+
.integer => |int| @floatFromInt(int),
|
|
2042
|
+
else => runtimeFail(optional.child, ui),
|
|
2043
|
+
};
|
|
2044
|
+
},
|
|
2045
|
+
else => runtimeFail(optional.child, ui),
|
|
2046
|
+
},
|
|
2009
2047
|
.int => {
|
|
2010
2048
|
comptime requireVariant(variant, &.{.integer}, node, "expected a whole number");
|
|
2011
2049
|
// Range-checked against the field's own integer type
|
|
@@ -2116,6 +2154,10 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2116
2154
|
options.on_resize = comptime (resizeConstructor(expression.tag) orelse fail(node, markup.on_resize_payload_message));
|
|
2117
2155
|
return;
|
|
2118
2156
|
}
|
|
2157
|
+
if (comptime std.mem.eql(u8, event, "drag")) {
|
|
2158
|
+
options.on_drag = constructDragMessage(node, expression, entries, ui, model, scope);
|
|
2159
|
+
return;
|
|
2160
|
+
}
|
|
2119
2161
|
// The value-payload change event: a slider's `on-change` with a
|
|
2120
2162
|
// bare tag naming a value-carrying arm dispatches the APPLIED
|
|
2121
2163
|
// value through the `on_value` constructor (the `on-resize`
|
|
@@ -2304,6 +2346,22 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
2304
2346
|
return @unionInit(MsgT, field.name, coerce(field.type, node, variant, ui, value));
|
|
2305
2347
|
}
|
|
2306
2348
|
|
|
2349
|
+
fn constructDragMessage(comptime node: markup.MarkupNode, comptime expression: markup.MessageExpression, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype) MsgT {
|
|
2350
|
+
comptime {
|
|
2351
|
+
if (expression.payload.len == 0) fail(node, markup.on_drag_payload_message);
|
|
2352
|
+
}
|
|
2353
|
+
const tag_index = comptime (msgTagIndex(expression.tag) orelse fail(node, markup.on_drag_payload_message));
|
|
2354
|
+
const field = comptime @typeInfo(MsgT).@"union".fields[tag_index];
|
|
2355
|
+
comptime {
|
|
2356
|
+
if (!interpreter.declaredWidgetDragDropRecord(field.type)) fail(node, markup.on_drag_payload_message);
|
|
2357
|
+
}
|
|
2358
|
+
const variant = comptime pathVariant(node, entries, expression.payload, true);
|
|
2359
|
+
const value = bindingValue(node, entries, expression.payload, ui, model, scope, true);
|
|
2360
|
+
var payload: field.type = std.mem.zeroes(field.type);
|
|
2361
|
+
payload.sourceId = coerce(@FieldType(field.type, "sourceId"), node, variant, ui, value);
|
|
2362
|
+
return @unionInit(MsgT, field.name, payload);
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2307
2365
|
/// Runtime mirror of the interpreter's `coerce`, with the
|
|
2308
2366
|
/// type-determined mismatches promoted to compile errors. Only
|
|
2309
2367
|
/// value-dependent conversions (optional bindings, enum tags from
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
const std = @import("std");
|
|
14
14
|
const canvas = @import("root.zig");
|
|
15
|
+
const geometry = @import("geometry");
|
|
15
16
|
const markup_view = @import("ui_markup_view.zig");
|
|
16
17
|
const fixture = @import("ui_markup_view_tests.zig");
|
|
17
18
|
|
|
@@ -91,6 +92,32 @@ const InboxUi = canvas.Ui(fixture.Msg);
|
|
|
91
92
|
const InboxInterpreter = markup_view.MarkupView(fixture.Model, fixture.Msg);
|
|
92
93
|
const InboxCompiled = canvas.CompiledMarkupView(fixture.Model, fixture.Msg, fixture.inbox_markup_source);
|
|
93
94
|
|
|
95
|
+
const zero_card_padding_markup =
|
|
96
|
+
\\<card padding="0">
|
|
97
|
+
\\ <text>Flush</text>
|
|
98
|
+
\\</card>
|
|
99
|
+
;
|
|
100
|
+
const ZeroCardPaddingCompiled = canvas.CompiledMarkupView(fixture.Model, fixture.Msg, zero_card_padding_markup);
|
|
101
|
+
|
|
102
|
+
test "explicit zero card padding survives interpreted and compiled markup" {
|
|
103
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
104
|
+
defer arena_state.deinit();
|
|
105
|
+
const arena = arena_state.allocator();
|
|
106
|
+
const model = fixture.testModel();
|
|
107
|
+
|
|
108
|
+
var interpreter = try InboxInterpreter.init(arena, zero_card_padding_markup);
|
|
109
|
+
var interpreter_ui = InboxUi.init(arena);
|
|
110
|
+
const interpreted = try interpreter_ui.finalize(try interpreter.build(&interpreter_ui, &model));
|
|
111
|
+
var compiled_ui = InboxUi.init(arena);
|
|
112
|
+
const compiled = try compiled_ui.finalize(ZeroCardPaddingCompiled.build(&compiled_ui, &model));
|
|
113
|
+
|
|
114
|
+
try testing.expectEqual(canvas.WidgetKind.card, interpreted.root.kind);
|
|
115
|
+
try testing.expectEqual(geometry.InsetsF{}, interpreted.root.layout.padding);
|
|
116
|
+
try testing.expect(!interpreted.root.layout.padding_is_kind_default);
|
|
117
|
+
try testing.expectEqualDeep(interpreted.root.layout.padding, compiled.root.layout.padding);
|
|
118
|
+
try testing.expect(!compiled.root.layout.padding_is_kind_default);
|
|
119
|
+
}
|
|
120
|
+
|
|
94
121
|
fn interpretInbox(arena: std.mem.Allocator, model: *const fixture.Model) !InboxUi.Tree {
|
|
95
122
|
var view = try InboxInterpreter.init(arena, fixture.inbox_markup_source);
|
|
96
123
|
var ui = InboxUi.init(arena);
|
|
@@ -54,7 +54,14 @@ pub const ValueKind = expr.ValueKind;
|
|
|
54
54
|
/// gained a bare-tag rule — a format-2 artifact classified a four-field
|
|
55
55
|
/// terminal message as `.unsupported` and would reject valid `<terminal>`
|
|
56
56
|
/// markup, so a stale artifact must force regeneration rather than pass.
|
|
57
|
-
|
|
57
|
+
/// Version 4: `drag_drop` classifies the closed release-geometry record
|
|
58
|
+
/// used by `on-drag`; older artifacts call it unsupported and would reject
|
|
59
|
+
/// a valid binding.
|
|
60
|
+
/// Version 5: that record gained the numeric live `phase` field so apps can
|
|
61
|
+
/// preview insertion/reordering on change and restore on cancellation.
|
|
62
|
+
/// Version 6: live drag geometry requires floating-point fields so captured
|
|
63
|
+
/// out-of-view coordinates cannot trap an integer conversion at dispatch.
|
|
64
|
+
pub const format_version: u32 = 6;
|
|
58
65
|
|
|
59
66
|
/// Where the app's build step writes the artifact, relative to the app
|
|
60
67
|
/// directory (a build product lives under zig-out, not in durable state).
|
|
@@ -139,7 +146,7 @@ pub const Iterable = struct {
|
|
|
139
146
|
/// cannot be built from markup at all. `legacy_scroll_state` is the
|
|
140
147
|
/// RETIRED one-axis scroll record, recognized only so `on-scroll` can
|
|
141
148
|
/// teach the two-axis migration by field name.
|
|
142
|
-
pub const PayloadClass = enum { none, string, integer, float, boolean, enum_tag, text_input, scroll_state, legacy_scroll_state, terminal_state, unsupported };
|
|
149
|
+
pub const PayloadClass = enum { none, string, integer, float, boolean, enum_tag, text_input, scroll_state, legacy_scroll_state, terminal_state, drag_drop, unsupported };
|
|
143
150
|
|
|
144
151
|
pub const MsgTag = struct {
|
|
145
152
|
name: []const u8,
|
|
@@ -348,6 +355,7 @@ fn payloadClassOf(comptime T: type, comptime specials: Specials) PayloadClass {
|
|
|
348
355
|
// binds through on-terminal exactly like the canvas type — same
|
|
349
356
|
// resolution as both engines' terminalConstructor.
|
|
350
357
|
if (reflect.declaredTerminalStateRecord(T)) return .terminal_state;
|
|
358
|
+
if (reflect.declaredWidgetDragDropRecord(T)) return .drag_drop;
|
|
351
359
|
return switch (@typeInfo(T)) {
|
|
352
360
|
.int => .integer,
|
|
353
361
|
.float => .float,
|
|
@@ -904,6 +912,15 @@ const Checker = struct {
|
|
|
904
912
|
}
|
|
905
913
|
return;
|
|
906
914
|
}
|
|
915
|
+
if (std.mem.eql(u8, event, "drag")) {
|
|
916
|
+
const found = tag orelse return self.failAttr(node, attribute, markup.on_drag_payload_message);
|
|
917
|
+
if (found.payload != .drag_drop or expression.payload.len == 0) {
|
|
918
|
+
return self.failAttr(node, attribute, markup.on_drag_payload_message);
|
|
919
|
+
}
|
|
920
|
+
const resolved = try self.resolveBinding(node, expression.payload, true);
|
|
921
|
+
try self.requirePayloadKind(node, attribute, resolved, &.{.integer}, found);
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
907
924
|
// The value-payload change event (engine parity): a slider's
|
|
908
925
|
// on-change with a bare tag naming a value-carrying arm — f32 (the
|
|
909
926
|
// canvas-native shape) or the transpiled one-number float arm
|
|
@@ -931,7 +948,7 @@ const Checker = struct {
|
|
|
931
948
|
.boolean => {},
|
|
932
949
|
// These payloads cannot be constructed from a markup binding
|
|
933
950
|
// (input/scroll payloads bind through their own events).
|
|
934
|
-
.text_input, .scroll_state, .legacy_scroll_state, .terminal_state, .unsupported => return self.failPayloadType(node, attribute, resolved, found),
|
|
951
|
+
.text_input, .scroll_state, .legacy_scroll_state, .terminal_state, .drag_drop, .unsupported => return self.failPayloadType(node, attribute, resolved, found),
|
|
935
952
|
.none => unreachable,
|
|
936
953
|
}
|
|
937
954
|
}
|
|
@@ -1332,6 +1349,17 @@ const Checker = struct {
|
|
|
1332
1349
|
}
|
|
1333
1350
|
continue;
|
|
1334
1351
|
}
|
|
1352
|
+
if (std.mem.eql(u8, attribute.name, "images")) {
|
|
1353
|
+
const expression = markup.parseAttrExpression(attribute.value) orelse continue;
|
|
1354
|
+
if (expression != .binding) continue;
|
|
1355
|
+
const item = try self.resolveIterable(node, expression.binding, markup.markdown_images_message);
|
|
1356
|
+
if (!std.mem.eql(u8, item.type_name, "ResolvedImage") and
|
|
1357
|
+
!std.mem.endsWith(u8, item.type_name, ".ResolvedImage"))
|
|
1358
|
+
{
|
|
1359
|
+
return self.failAttr(node, attribute, markup.markdown_images_message);
|
|
1360
|
+
}
|
|
1361
|
+
continue;
|
|
1362
|
+
}
|
|
1335
1363
|
if (std.mem.eql(u8, attribute.name, "issue-link-base")) {
|
|
1336
1364
|
const kind = try self.attrKind(node, attribute, attribute.value);
|
|
1337
1365
|
try self.requireAttrKind(node, attribute, kind, &.{.string}, markup.markdown_issue_link_base_message);
|
|
@@ -256,6 +256,47 @@ pub fn declaredTerminalStateRecord(comptime T: type) bool {
|
|
|
256
256
|
return declaredRecordMatchesVocabulary(T, &terminal_state_field_names, &terminal_state_field_names);
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
+
/// A markup `on-drag` Msg payload. `sourceId` is filled from the authored
|
|
260
|
+
/// binding (`on-drag="card_dropped:{card.id}"`); the runtime fills the
|
|
261
|
+
/// drag phase, point, and receiving view size. Keeping this as one closed
|
|
262
|
+
/// record makes the event usable from transpiled cores without type
|
|
263
|
+
/// identity crossing the generated-module boundary.
|
|
264
|
+
pub fn declaredWidgetDragDropRecord(comptime T: type) bool {
|
|
265
|
+
const info = switch (@typeInfo(T)) {
|
|
266
|
+
.@"struct" => |s| s,
|
|
267
|
+
else => return false,
|
|
268
|
+
};
|
|
269
|
+
if (info.fields.len != 6) return false;
|
|
270
|
+
if (!@hasField(T, "sourceId") or !@hasField(T, "phase") or !@hasField(T, "x") or !@hasField(T, "y") or
|
|
271
|
+
!@hasField(T, "viewWidth") or !@hasField(T, "viewHeight")) return false;
|
|
272
|
+
if (!isNumeric(@FieldType(T, "sourceId"))) return false;
|
|
273
|
+
if (!isDragPhaseNumber(@FieldType(T, "phase"))) return false;
|
|
274
|
+
inline for (.{ "x", "y", "viewWidth", "viewHeight" }) |name| {
|
|
275
|
+
if (!isDragGeometryNumber(@FieldType(T, name))) return false;
|
|
276
|
+
}
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/// Live geometry starts as f32 and can be negative while pointer capture
|
|
281
|
+
/// carries a drag outside the view. Require a float at least as wide as the
|
|
282
|
+
/// source so every accepted record is injectable without a range trap.
|
|
283
|
+
fn isDragGeometryNumber(comptime T: type) bool {
|
|
284
|
+
return switch (@typeInfo(T)) {
|
|
285
|
+
.float => |info| info.bits >= 32,
|
|
286
|
+
else => false,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/// Phase injection needs to represent all three wire values (0, 1, 2).
|
|
291
|
+
/// Floats do so exactly; integer records need an honest upper bound.
|
|
292
|
+
fn isDragPhaseNumber(comptime T: type) bool {
|
|
293
|
+
return switch (@typeInfo(T)) {
|
|
294
|
+
.float => true,
|
|
295
|
+
.int => std.math.maxInt(T) >= 2,
|
|
296
|
+
else => false,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
259
300
|
/// A mirror of the RETIRED one-axis scroll state — `{offset, velocity,
|
|
260
301
|
/// viewport_extent, content_extent}` in either spelling. Recognized only
|
|
261
302
|
/// to fail with a teaching that names the new per-axis fields, so an app
|
|
@@ -782,6 +782,12 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
782
782
|
options.details_expanded = try self.boolItems(ui, scope, node, typed.binding);
|
|
783
783
|
continue;
|
|
784
784
|
}
|
|
785
|
+
if (std.mem.eql(u8, attribute.name, "images")) {
|
|
786
|
+
const typed = markup.attrTyped(attribute);
|
|
787
|
+
if (typed != .binding) return self.failNode(node, markup.markdown_images_message);
|
|
788
|
+
options.images = try self.markdownImageItems(ui, scope, node, typed.binding);
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
785
791
|
if (std.mem.eql(u8, attribute.name, "issue-link-base")) {
|
|
786
792
|
const typed = markup.attrTyped(attribute);
|
|
787
793
|
if (typed == .equals or typed == .invalid) {
|
|
@@ -1489,6 +1495,20 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1489
1495
|
return self.failText(node, markup.markdown_details_expanded_message);
|
|
1490
1496
|
}
|
|
1491
1497
|
|
|
1498
|
+
/// Resolve Markdown's registered source-to-image mapping through the
|
|
1499
|
+
/// same bounded iterable reflection used by `for each`.
|
|
1500
|
+
fn markdownImageItems(self: *Self, ui: *Ui, scope: *Scope, node: markup.MarkupNode, path: []const u8) BuildError![]const canvas.markdown.ResolvedImage {
|
|
1501
|
+
@setEvalBranchQuota(scan_quota);
|
|
1502
|
+
inline for (item_types, 0..) |Item, type_index| {
|
|
1503
|
+
if (comptime (Item == canvas.markdown.ResolvedImage)) {
|
|
1504
|
+
if (try self.iterateItems(ui, Item, type_index, scope, path)) |items| {
|
|
1505
|
+
return items;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
return self.failText(node, markup.markdown_images_message);
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1492
1512
|
// ------------------------------------------------------ templates
|
|
1493
1513
|
|
|
1494
1514
|
/// A hard cap on template expansion nesting. Legit documents are
|
|
@@ -1966,9 +1986,15 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1966
1986
|
else => return self.failVoid(node, "expected a number"),
|
|
1967
1987
|
},
|
|
1968
1988
|
.bool => @field(options, field) = value.truthy(),
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1989
|
+
.optional => |optional| switch (@typeInfo(optional.child)) {
|
|
1990
|
+
.bool => @field(options, field) = value.truthy(),
|
|
1991
|
+
.float => @field(options, field) = switch (value) {
|
|
1992
|
+
.float => |float| float,
|
|
1993
|
+
.integer => |int| @floatFromInt(int),
|
|
1994
|
+
else => return self.failVoid(node, "expected a number"),
|
|
1995
|
+
},
|
|
1996
|
+
else => return self.failVoid(node, "attribute is not settable from markup"),
|
|
1997
|
+
},
|
|
1972
1998
|
// Range-checked against the FIELD's own integer type
|
|
1973
1999
|
// before the cast (the grid-lines teaching, generalized):
|
|
1974
2000
|
// expression values are i64, so a literal or model
|
|
@@ -2062,6 +2088,10 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2062
2088
|
};
|
|
2063
2089
|
return;
|
|
2064
2090
|
}
|
|
2091
|
+
if (std.mem.eql(u8, event, "drag")) {
|
|
2092
|
+
options.on_drag = try self.constructDragMessage(scope, node, expression);
|
|
2093
|
+
return;
|
|
2094
|
+
}
|
|
2065
2095
|
// The value-payload change event: a slider's `on-change` with a
|
|
2066
2096
|
// bare tag naming a value-carrying arm dispatches the APPLIED
|
|
2067
2097
|
// value through the `on_value` constructor (the `on-resize`
|
|
@@ -2136,6 +2166,21 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
2136
2166
|
return self.failMsg(node, "unknown message tag");
|
|
2137
2167
|
}
|
|
2138
2168
|
|
|
2169
|
+
fn constructDragMessage(self: *Self, scope: *Scope, node: markup.MarkupNode, expression: markup.MessageExpression) BuildError!MsgT {
|
|
2170
|
+
if (expression.payload.len == 0) return self.failMsg(node, markup.on_drag_payload_message);
|
|
2171
|
+
@setEvalBranchQuota(scan_quota);
|
|
2172
|
+
inline for (@typeInfo(MsgT).@"union".fields) |field| {
|
|
2173
|
+
if (std.mem.eql(u8, field.name, expression.tag)) {
|
|
2174
|
+
if (comptime !reflect.declaredWidgetDragDropRecord(field.type)) return self.failMsg(node, markup.on_drag_payload_message);
|
|
2175
|
+
const value = try self.evalBinding(scope, node, expression.payload, true);
|
|
2176
|
+
var payload: field.type = std.mem.zeroes(field.type);
|
|
2177
|
+
payload.sourceId = try self.coerce(@FieldType(field.type, "sourceId"), node, value);
|
|
2178
|
+
return @unionInit(MsgT, field.name, payload);
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
return self.failMsg(node, markup.on_drag_payload_message);
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2139
2184
|
fn coerce(self: *Self, comptime T: type, node: markup.MarkupNode, value: Value) BuildError!T {
|
|
2140
2185
|
return switch (@typeInfo(T)) {
|
|
2141
2186
|
// Range-checked against the payload's own integer type
|
|
@@ -2592,6 +2637,7 @@ pub const declaredTextInputUnion = reflect.declaredTextInputUnion;
|
|
|
2592
2637
|
pub const declaredScrollStateRecord = reflect.declaredScrollStateRecord;
|
|
2593
2638
|
pub const declaredTerminalStateRecord = reflect.declaredTerminalStateRecord;
|
|
2594
2639
|
pub const declaredLegacyScrollStateRecord = reflect.declaredLegacyScrollStateRecord;
|
|
2640
|
+
pub const declaredWidgetDragDropRecord = reflect.declaredWidgetDragDropRecord;
|
|
2595
2641
|
pub const valueArmClass = reflect.valueArmClass;
|
|
2596
2642
|
pub const sliceElement = reflect.sliceElement;
|
|
2597
2643
|
pub const isItemFn = reflect.isItemFn;
|