@native-sdk/cli 0.8.0 → 0.8.1

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.
@@ -1861,11 +1861,12 @@ pub const arena_scalar_equality_message = "arena-computed bindings cannot be com
1861
1861
  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
1862
  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
1863
  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, and issue-link-base";
1864
+ pub const markdown_attr_message = "unknown attribute for markdown - it takes source, on-link, on-details, details-expanded, issue-link-base, and images";
1865
1865
  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
1866
  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
1867
  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
1868
  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)";
1869
+ 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
1870
  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
1871
  pub const code_children_message = "code takes no children or text content - the source binding provides the code";
1871
1872
  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 +2209,13 @@ fn validateMarkdown(node: MarkupNode) ?MarkupErrorInfo {
2208
2209
  }
2209
2210
  continue;
2210
2211
  }
2212
+ if (std.mem.eql(u8, attribute.name, "images")) {
2213
+ const expression = parseAttrExpression(attribute.value);
2214
+ if (expression == null or expression.? != .binding) {
2215
+ return attrError(node, attribute, markdown_images_message);
2216
+ }
2217
+ continue;
2218
+ }
2211
2219
  if (std.mem.eql(u8, attribute.name, "issue-link-base")) {
2212
2220
  const expression = parseAttrExpression(attribute.value);
2213
2221
  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
@@ -1332,6 +1332,17 @@ const Checker = struct {
1332
1332
  }
1333
1333
  continue;
1334
1334
  }
1335
+ if (std.mem.eql(u8, attribute.name, "images")) {
1336
+ const expression = markup.parseAttrExpression(attribute.value) orelse continue;
1337
+ if (expression != .binding) continue;
1338
+ const item = try self.resolveIterable(node, expression.binding, markup.markdown_images_message);
1339
+ if (!std.mem.eql(u8, item.type_name, "ResolvedImage") and
1340
+ !std.mem.endsWith(u8, item.type_name, ".ResolvedImage"))
1341
+ {
1342
+ return self.failAttr(node, attribute, markup.markdown_images_message);
1343
+ }
1344
+ continue;
1345
+ }
1335
1346
  if (std.mem.eql(u8, attribute.name, "issue-link-base")) {
1336
1347
  const kind = try self.attrKind(node, attribute, attribute.value);
1337
1348
  try self.requireAttrKind(node, attribute, kind, &.{.string}, markup.markdown_issue_link_base_message);
@@ -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
@@ -1711,6 +1711,10 @@ pub const doc_body_source =
1711
1711
  \\
1712
1712
  \\Tracked in #12, see https://status.example.com.
1713
1713
  \\
1714
+ \\| State |
1715
+ \\| --- |
1716
+ \\| ![Ready](https://status.example.com/ready.png) Ready |
1717
+ \\
1714
1718
  \\<details>
1715
1719
  \\<summary>Rollout</summary>
1716
1720
  \\
@@ -1724,6 +1728,12 @@ pub const DocModel = struct {
1724
1728
  details_expanded: [2]bool = .{ false, false },
1725
1729
  opened_count: usize = 0,
1726
1730
  issue_base: []const u8 = "ghissue://",
1731
+ images: [1]canvas.markdown.ResolvedImage = .{.{
1732
+ .source = "https://status.example.com/ready.png",
1733
+ .image = 71,
1734
+ .width = 10,
1735
+ .height = 10,
1736
+ }},
1727
1737
 
1728
1738
  /// Arena scalar as a markdown source: composed at view time.
1729
1739
  pub fn banner(model: *const DocModel, arena: std.mem.Allocator) []const u8 {
@@ -1733,7 +1743,7 @@ pub const DocModel = struct {
1733
1743
 
1734
1744
  pub const doc_markup_source =
1735
1745
  \\<column gap="8">
1736
- \\ <markdown source="{body}" on-link="open_url" on-details="toggle_details" details-expanded="{details_expanded}" issue-link-base="{issue_base}" />
1746
+ \\ <markdown source="{body}" on-link="open_url" on-details="toggle_details" details-expanded="{details_expanded}" issue-link-base="{issue_base}" images="{images}" />
1737
1747
  \\ <markdown source="{banner}" />
1738
1748
  \\</column>
1739
1749
  ;
@@ -1750,6 +1760,7 @@ pub fn handDocView(ui: *DocUi, model: *const DocModel) DocUi.Node {
1750
1760
  .on_details = DocMd.detailsMsg(.toggle_details),
1751
1761
  .details_expanded = &model.details_expanded,
1752
1762
  .issue_link_base = model.issue_base,
1763
+ .images = &model.images,
1753
1764
  }),
1754
1765
  DocMd.view(ui, model.banner(ui.arena), .{}),
1755
1766
  });
@@ -1807,6 +1818,7 @@ test "the markdown element builds the hand-written Md.view tree and dispatches l
1807
1818
  // URLs autolink (trailing punctuation trimmed).
1808
1819
  try testing.expectEqualStrings("ghissue://12", findSpanLink(markup_tree.root, "#12").?);
1809
1820
  try testing.expectEqualStrings("https://status.example.com", findSpanLink(markup_tree.root, "https://status.example.com").?);
1821
+ try testing.expectEqual(@as(canvas.ImageId, 71), findByKind(markup_tree.root, .image).?.image_id);
1810
1822
 
1811
1823
  // Details summary dispatches on-details with the block index; the body
1812
1824
  // is hidden while the caller-owned flag is false.
@@ -576,6 +576,9 @@ pub const attrs = [_]AttrInfo{
576
576
  // can state compact runs (`2-4, 7`) without putting +/- bytes in source.
577
577
  .{ .code = 94, .name = "added-lines", .class = .text, .group = .composite },
578
578
  .{ .code = 95, .name = "removed-lines", .class = .text, .group = .composite },
579
+ // Markdown's caller-owned source -> registered ImageId mapping. The
580
+ // markdown rule hook scopes and type-checks the iterable binding.
581
+ .{ .code = 96, .name = "images", .class = .binding_only, .group = .composite },
579
582
  };
580
583
 
581
584
  // ----------------------------------------------------------------- events
@@ -22,7 +22,7 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
22
22
  // the new fingerprint ONLY for additions; renames/renumbers are
23
23
  // schema-version-bump events, not silent edits.
24
24
  try testing.expectEqual(@as(usize, 70), schema.elements.len);
25
- try testing.expectEqual(@as(usize, 95), schema.attrs.len);
25
+ try testing.expectEqual(@as(usize, 96), schema.attrs.len);
26
26
  try testing.expectEqual(@as(usize, 14), schema.events.len);
27
27
  // The element table runs through the span composite (64), the
28
28
  // bubble-reactions composite (65), the media surface (66), the
@@ -45,9 +45,10 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
45
45
  // attributes pty (88) and scrollback (89), and the code language
46
46
  // (90), line-numbers (91), and editable-code (92) declarations,
47
47
  // the flat disclosure-tree hierarchy level tree-level (93), and the
48
- // code-diff line sets added-lines (94) and removed-lines (95).
48
+ // code-diff line sets added-lines (94) and removed-lines (95), and
49
+ // Markdown's registered-image iterable binding images (96).
49
50
  try testing.expectEqual(
50
- @as(u64, 0xf16fa9fd1d3e7f25),
51
+ @as(u64, 0xc0ab8db72d6e2110),
51
52
  tableFingerprint(schema.AttrInfo, &schema.attrs),
52
53
  );
53
54
  // The event table runs through the pointer-hover containment pair
@@ -150,8 +150,13 @@ pub fn layoutWidgetDepth(
150
150
  }
151
151
  },
152
152
  // Span paragraphs and span-carrying table cells share the link
153
- // hotspot child convention (no spans or no children is a no-op).
154
- .text, .data_cell => try layoutTextSpanLinkChildren(widget, content, index, depth, output, len, tokens),
153
+ // hotspot child convention. A span-less table cell may instead be
154
+ // a composed inline row (Markdown's resolved image + text shape).
155
+ .text => try layoutTextSpanLinkChildren(widget, content, index, depth, output, len, tokens),
156
+ .data_cell => if (widget.spans.len > 0)
157
+ try layoutTextSpanLinkChildren(widget, content, index, depth, output, len, tokens)
158
+ else
159
+ try layoutAxisChildren(widget.children, content, .horizontal, index, depth, output, len, widget.layout, tokens),
155
160
  .icon, .image, .avatar, .badge, .button, .toggle_button, .icon_button, .select, .input, .text_field, .search_field, .combobox, .textarea, .tooltip, .menu_item, .status_bar, .segmented_control, .checkbox, .radio, .switch_control, .toggle, .slider, .progress, .separator, .skeleton, .spinner, .chart, .split_divider, .media_surface, .terminal => {},
156
161
  }
157
162
 
@@ -824,10 +829,25 @@ fn wrappedVerticalExtentForWidth(widget: Widget, width: f32, tokens: DesignToken
824
829
  const padding = widget.layout.padding;
825
830
  const inner_width = @max(0, width - padding.left - padding.right);
826
831
  const content_height: f32 = switch (widget.kind) {
827
- .text, .data_cell => if (widget.spans.len > 0)
832
+ .text => if (widget.spans.len > 0)
828
833
  spanParagraphHeight(widget, inner_width, tokens)
829
834
  else
830
835
  return preferredMainExtent(widget, .vertical, tokens),
836
+ .data_cell => if (widget.spans.len > 0)
837
+ spanParagraphHeight(widget, inner_width, tokens)
838
+ else if (widget.children.len > 0) blk: {
839
+ var max_height: f32 = 0;
840
+ for (widget.children, 0..) |child, index| {
841
+ if (child.layout.anchor != null) continue;
842
+ max_height = @max(max_height, wrappedVerticalExtentForWidth(
843
+ child,
844
+ rowChildWidth(widget, inner_width, index, tokens),
845
+ tokens,
846
+ depth + 1,
847
+ ));
848
+ }
849
+ break :blk max_height;
850
+ } else return preferredMainExtent(widget, .vertical, tokens),
831
851
  .column, .list, .data_grid, .table, .menu_surface, .dropdown_menu => blk: {
832
852
  if (widget.layout.virtualized) return preferredMainExtent(widget, .vertical, tokens);
833
853
  var sum: f32 = 0;
@@ -1021,6 +1041,7 @@ fn layoutTextSpanLinkChildren(
1021
1041
  content.x += gutter;
1022
1042
  content.width -= gutter;
1023
1043
  }
1044
+ content = widget_metrics.widgetTextSpanAlignedContentFrame(widget, content, tokens);
1024
1045
 
1025
1046
  var runs: [text_spans_model.max_text_span_runs_per_paragraph]text_spans_model.TextSpanRun = undefined;
1026
1047
  const layout = text_spans_model.layoutTextSpans(
@@ -1806,6 +1827,8 @@ fn intrinsicWidgetSizeDepth(widget: Widget, tokens: DesignTokens, depth: usize)
1806
1827
  // span paragraph; classic cells keep the single-line row metric.
1807
1828
  .data_cell => if (widget.spans.len > 0)
1808
1829
  paddedIntrinsicSize(widget, intrinsicTextWidgetSize(widget, tokens, widgetBodyTextSize(widget, tokens)))
1830
+ else if (widget.children.len > 0)
1831
+ intrinsicAxisChildrenSize(widget, tokens, .horizontal, depth)
1809
1832
  else
1810
1833
  intrinsicRowTextWidgetSize(widget, tokens),
1811
1834
  // Table rows sit taller than list rows: the comfortable row
@@ -138,15 +138,33 @@ pub fn widgetCodeLineNumberGutterWidth(widget: Widget, tokens: DesignTokens) f32
138
138
  ) + 12;
139
139
  }
140
140
 
141
+ /// Vertically align a span paragraph inside a table cell's padded content.
142
+ /// Rows share the tallest cell's height; centering the laid-out text block
143
+ /// keeps a short text-only cell aligned with image-bearing or wrapped peers.
144
+ /// Other paragraph kinds keep their normal top-aligned document flow.
145
+ pub fn widgetTextSpanAlignedContentFrame(widget: Widget, content_in: geometry.RectF, tokens: DesignTokens) geometry.RectF {
146
+ if (widget.kind != .data_cell or widget.spans.len == 0 or content_in.height <= 0) return content_in;
147
+ var runs: [text_spans_model.max_text_span_runs_per_paragraph]text_spans_model.TextSpanRun = undefined;
148
+ const layout = text_spans_model.layoutTextSpans(
149
+ widget.spans,
150
+ widgetTextSpanLayoutOptions(widget, tokens, content_in.width),
151
+ &runs,
152
+ );
153
+ var content = content_in;
154
+ content.y += @max(0, (content.height - layout.size.height) * 0.5);
155
+ return content;
156
+ }
157
+
141
158
  /// Span paragraph content after authored padding and the engine-owned code
142
- /// gutter. Layout, painting, hit mapping, and selection all use this exact
143
- /// frame so numbered source stays one coherent text model.
159
+ /// gutter, plus table-cell vertical alignment. Layout, painting, hit mapping,
160
+ /// and selection all use this exact frame so numbered source and cell links
161
+ /// stay one coherent text model.
144
162
  pub fn widgetTextSpanContentFrame(widget: Widget, tokens: DesignTokens) geometry.RectF {
145
163
  var content = widget.frame.inset(widget.layout.padding);
146
164
  const gutter = @min(content.width, widgetCodeLineNumberGutterWidth(widget, tokens));
147
165
  content.x += gutter;
148
166
  content.width -= gutter;
149
- return content;
167
+ return widgetTextSpanAlignedContentFrame(widget, content, tokens);
150
168
  }
151
169
 
152
170
  /// The ONE control height register — buttons, inputs, and select
@@ -351,7 +351,12 @@ fn emitWidgetDepthContent(builder: *Builder, widget: Widget, tokens: DesignToken
351
351
  // inside the flat wash chrome.
352
352
  try emitWidgetClippedChildren(builder, paint_widget, tokens, depth);
353
353
  },
354
- .data_cell => try emitDataCellContent(builder, paint_widget, tokens),
354
+ .data_cell => {
355
+ try emitDataCellContent(builder, paint_widget, tokens);
356
+ if (paint_widget.spans.len == 0 and paint_widget.children.len > 0) {
357
+ try emitWidgetClippedChildren(builder, paint_widget, tokens, depth);
358
+ }
359
+ },
355
360
  .status_bar => try emitStatusBarWidget(builder, paint_widget, tokens),
356
361
  .segmented_control => try widget_render_controls.emitSegmentedControlWidget(builder, paint_widget, tokens),
357
362
  .checkbox => try widget_render_controls.emitCheckboxWidget(builder, paint_widget, tokens),
@@ -12860,6 +12860,15 @@ pub fn Effects(comptime Msg: type) type {
12860
12860
  try body.writer.writeAll(slot.fetchPayload());
12861
12861
  try body.end();
12862
12862
  try request.connection.?.flush();
12863
+ } else if (slot.method.requestHasBody()) {
12864
+ // POST, PUT and PATCH carry a body by definition, so
12865
+ // `sendBodiless` asserts against them. A payload-free
12866
+ // request of one of those methods is still valid HTTP;
12867
+ // send an explicit zero-length body instead.
12868
+ request.transfer_encoding = .{ .content_length = 0 };
12869
+ var body = try request.sendBodyUnflushed(&.{});
12870
+ try body.end();
12871
+ try request.connection.?.flush();
12863
12872
  } else {
12864
12873
  try request.sendBodiless();
12865
12874
  }
@@ -923,6 +923,27 @@ test "real fetch round-trips a POST payload through the echo route" {
923
923
  try std.testing.expectEqualStrings("the payload rides in the fetch buffer", h.app_state.model.body());
924
924
  }
925
925
 
926
+ test "real fetch sends a payload-free POST as an explicit zero-length body" {
927
+ var h = try Harness.create();
928
+ defer h.destroy();
929
+ const fixture = try Fixture.start(std.testing.allocator);
930
+ defer fixture.stop();
931
+
932
+ var url_buffer: [128]u8 = undefined;
933
+ test_url = fixture.url(&url_buffer, "/echo");
934
+ test_method = .POST;
935
+ test_headers = &.{};
936
+ test_payload = null;
937
+ test_timeout_ms = effects_mod.default_effect_fetch_timeout_ms;
938
+ try h.app_state.dispatch(&h.harness.runtime, 1, .start);
939
+ try waitForResponse(&h);
940
+
941
+ try std.testing.expectEqual(effects_mod.EffectFetchOutcome.ok, h.app_state.model.outcome.?);
942
+ try std.testing.expectEqual(@as(u16, 200), h.app_state.model.status);
943
+ try std.testing.expectEqual(@as(usize, 0), h.app_state.model.body_len);
944
+ try std.testing.expect(fixture.headContains("content-length: 0"));
945
+ }
946
+
926
947
  test "real fetch preserves binary bodies byte for byte" {
927
948
  var h = try Harness.create();
928
949
  defer h.destroy();