@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.
Files changed (75) hide show
  1. package/README.md +4 -4
  2. package/build.zig +49 -23
  3. package/package.json +10 -10
  4. package/packages/core/compile-surface/core.ts +16 -0
  5. package/packages/core/package-lock.json +2 -2
  6. package/packages/core/package.json +1 -1
  7. package/packages/core/sdk/core.d.ts +11 -0
  8. package/packages/core/sdk/core.ts +29 -2
  9. package/packages/core/sdk/events.d.ts +10 -0
  10. package/packages/core/sdk/events.ts +24 -4
  11. package/packages/core/src/checker.ts +1 -1
  12. package/packages/core/src/contract.ts +4 -1
  13. package/packages/core/src/devhost.ts +10 -1
  14. package/packages/core/src/diagnostics.ts +1 -1
  15. package/skill-data/core/SKILL.md +48 -20
  16. package/skill-data/core/references/app-model-runtime.md +2 -2
  17. package/skill-data/core/references/project-anatomy.md +22 -6
  18. package/skill-data/native-ui/SKILL.md +71 -29
  19. package/skill-data/ts-core/SKILL.md +13 -8
  20. package/skill-data/zig/SKILL.md +1 -1
  21. package/skills/native-sdk/SKILL.md +6 -5
  22. package/src/app_runner/ts_core_main.zig +2 -1
  23. package/src/embed/tests.zig +3 -1
  24. package/src/platform/macos/appkit_host.h +4 -4
  25. package/src/platform/macos/appkit_host.m +24 -4
  26. package/src/platform/macos/cef_host.mm +22 -6
  27. package/src/platform/macos/root.zig +2 -2
  28. package/src/primitives/canvas/events.zig +8 -0
  29. package/src/primitives/canvas/markdown.zig +2010 -57
  30. package/src/primitives/canvas/markdown_hostile_tests.zig +40 -0
  31. package/src/primitives/canvas/markdown_tests.zig +778 -3
  32. package/src/primitives/canvas/root.zig +2 -0
  33. package/src/primitives/canvas/test_support.zig +1 -0
  34. package/src/primitives/canvas/ui.zig +53 -8
  35. package/src/primitives/canvas/ui_markup.zig +10 -1
  36. package/src/primitives/canvas/ui_markup_compiled.zig +61 -3
  37. package/src/primitives/canvas/ui_markup_compiled_tests.zig +27 -0
  38. package/src/primitives/canvas/ui_markup_contract.zig +31 -3
  39. package/src/primitives/canvas/ui_markup_reflect.zig +41 -0
  40. package/src/primitives/canvas/ui_markup_view.zig +49 -3
  41. package/src/primitives/canvas/ui_markup_view_tests.zig +61 -2
  42. package/src/primitives/canvas/ui_schema.zig +8 -1
  43. package/src/primitives/canvas/ui_schema_tests.zig +7 -6
  44. package/src/primitives/canvas/ui_tests.zig +14 -0
  45. package/src/primitives/canvas/widget_access.zig +4 -3
  46. package/src/primitives/canvas/widget_invalidation.zig +11 -0
  47. package/src/primitives/canvas/widget_layout.zig +26 -3
  48. package/src/primitives/canvas/widget_metrics.zig +21 -3
  49. package/src/primitives/canvas/widget_render.zig +87 -1
  50. package/src/primitives/canvas/widget_routing.zig +12 -7
  51. package/src/primitives/canvas/widget_runtime_tests.zig +132 -0
  52. package/src/primitives/canvas/widgets.zig +40 -0
  53. package/src/root.zig +1 -0
  54. package/src/runtime/automation_widget_dispatch.zig +19 -0
  55. package/src/runtime/canvas_limits.zig +5 -0
  56. package/src/runtime/canvas_widget_event_tests.zig +424 -8
  57. package/src/runtime/canvas_widget_events.zig +254 -7
  58. package/src/runtime/canvas_widget_state.zig +123 -1
  59. package/src/runtime/core.zig +6 -0
  60. package/src/runtime/effects.zig +36 -1
  61. package/src/runtime/effects_fetch_tests.zig +21 -0
  62. package/src/runtime/effects_notification_tests.zig +65 -0
  63. package/src/runtime/gpu_surface_events.zig +60 -14
  64. package/src/runtime/tests.zig +1 -0
  65. package/src/runtime/ts_core_host.zig +16 -0
  66. package/src/runtime/ts_ui_app.zig +55 -2
  67. package/src/runtime/ui_app.zig +112 -0
  68. package/src/runtime/ui_app_tests.zig +356 -0
  69. package/src/runtime/view.zig +35 -0
  70. package/src/runtime/view_widget_tree.zig +12 -0
  71. package/tools/corewire/core_abi.zig +1 -0
  72. package/tools/corewire/emit.zig +55 -8
  73. package/tools/corewire/emit_facade.zig +63 -2
  74. package/tools/corewire/emit_profile.zig +4 -1
  75. package/tools/corewire/sidecar.zig +36 -6
@@ -152,6 +152,362 @@ test "ui app owns install, dispatch, and rebuild end to end" {
152
152
  try std.testing.expect(try retainedTextExists(&harness.runtime, "Count 0"));
153
153
  }
154
154
 
155
+ // ------------------------------------------------ drag/press arbitration fixture
156
+
157
+ const DragPayload = struct {
158
+ sourceId: u64,
159
+ phase: u32,
160
+ x: f32,
161
+ y: f32,
162
+ viewWidth: f32,
163
+ viewHeight: f32,
164
+ };
165
+
166
+ const DragModel = struct {
167
+ presses: u32 = 0,
168
+ holds: u32 = 0,
169
+ changes: u32 = 0,
170
+ ends: u32 = 0,
171
+ cancels: u32 = 0,
172
+ last_x: f32 = 0,
173
+ unmount_on_drag: bool = false,
174
+ target_mounted: bool = true,
175
+ };
176
+
177
+ const DragMsg = union(enum) {
178
+ pressed,
179
+ held,
180
+ dragged: DragPayload,
181
+ };
182
+
183
+ const DragApp = ui_app_model.UiApp(DragModel, DragMsg);
184
+
185
+ fn dragUpdate(model: *DragModel, msg: DragMsg) void {
186
+ switch (msg) {
187
+ .pressed => model.presses += 1,
188
+ .held => model.holds += 1,
189
+ .dragged => |drag| {
190
+ model.last_x = drag.x;
191
+ switch (drag.phase) {
192
+ 0 => {
193
+ model.changes += 1;
194
+ if (model.unmount_on_drag) model.target_mounted = false;
195
+ },
196
+ 1 => model.ends += 1,
197
+ 2 => model.cancels += 1,
198
+ else => {},
199
+ }
200
+ },
201
+ }
202
+ }
203
+
204
+ fn dragView(ui: *DragApp.Ui, model: *const DragModel) DragApp.Ui.Node {
205
+ if (!model.target_mounted) return ui.column(.{ .padding = 12 }, .{});
206
+ var target = ui.row(.{
207
+ .height = 40,
208
+ .global_key = canvas.uiKey(@as(u64, 7)),
209
+ .on_press = .pressed,
210
+ .on_hold = .held,
211
+ .on_drag = .{ .dragged = .{
212
+ .sourceId = 7,
213
+ .phase = 0,
214
+ .x = 0,
215
+ .y = 0,
216
+ .viewWidth = 0,
217
+ .viewHeight = 0,
218
+ } },
219
+ }, .{ui.text(.{}, "Drag target")});
220
+ target.widget.text = "Drag target";
221
+ return ui.column(.{ .padding = 12 }, .{target});
222
+ }
223
+
224
+ fn dragOptions() DragApp.Options {
225
+ return .{
226
+ .name = "ui-app-drag-press-arbitration",
227
+ .scene = counter_scene,
228
+ .canvas_label = canvas_label,
229
+ .update = dragUpdate,
230
+ .view = dragView,
231
+ };
232
+ }
233
+
234
+ test "ui app keeps clicks below drag slop and suppresses press after a live drag" {
235
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
236
+ defer harness.destroy(std.testing.allocator);
237
+ harness.null_platform.gpu_surfaces = true;
238
+
239
+ const app_state = try std.testing.allocator.create(DragApp);
240
+ defer std.testing.allocator.destroy(app_state);
241
+ app_state.* = DragApp.init(std.heap.page_allocator, .{}, dragOptions());
242
+ defer app_state.deinit();
243
+ const app = app_state.app();
244
+ try harness.start(app);
245
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
246
+ .label = canvas_label,
247
+ .size = geometry.SizeF.init(400, 300),
248
+ .scale_factor = 2,
249
+ .frame_index = 1,
250
+ .timestamp_ns = 1_000_000,
251
+ .nonblank = true,
252
+ } });
253
+
254
+ const target_id = findWidgetIdByText(app_state.tree.?, .row, "Drag target").?;
255
+ const layout = try harness.runtime.canvasWidgetLayout(1, canvas_label);
256
+ const frame = layout.findById(target_id).?.frame.normalized();
257
+ const point = frame.center();
258
+
259
+ // No motion: one ordinary press, no terminal drag, and no latent landing
260
+ // state for the press-driven rebuild to consume.
261
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
262
+ .window_id = 1,
263
+ .label = canvas_label,
264
+ .kind = .pointer_down,
265
+ .x = point.x,
266
+ .y = point.y,
267
+ } });
268
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
269
+ .window_id = 1,
270
+ .label = canvas_label,
271
+ .kind = .pointer_up,
272
+ .x = point.x,
273
+ .y = point.y,
274
+ } });
275
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.presses);
276
+ try std.testing.expectEqual(@as(u32, 0), app_state.model.changes);
277
+ try std.testing.expectEqual(@as(u32, 0), app_state.model.ends);
278
+ try std.testing.expect(!harness.runtime.views[0].canvas_widget_drag_layout_motion_armed);
279
+
280
+ // A little pointer motion is still a click. It remains below the app drag
281
+ // channel's threshold and cannot arm a landing from the default origin.
282
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
283
+ .window_id = 1,
284
+ .label = canvas_label,
285
+ .kind = .pointer_down,
286
+ .x = point.x,
287
+ .y = point.y,
288
+ } });
289
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
290
+ .window_id = 1,
291
+ .label = canvas_label,
292
+ .kind = .pointer_drag,
293
+ .x = point.x + 3,
294
+ .y = point.y,
295
+ } });
296
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
297
+ .window_id = 1,
298
+ .label = canvas_label,
299
+ .kind = .pointer_up,
300
+ .x = point.x + 3,
301
+ .y = point.y,
302
+ } });
303
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.presses);
304
+ try std.testing.expectEqual(@as(u32, 0), app_state.model.changes);
305
+ try std.testing.expectEqual(@as(u32, 0), app_state.model.ends);
306
+ try std.testing.expect(!harness.runtime.views[0].canvas_widget_drag_layout_motion_armed);
307
+ try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_drag_landing_source_id);
308
+
309
+ // Cross the slop, then return near the origin. The below-slop change is
310
+ // filtered, but the terminal event still belongs to the already-live drag;
311
+ // it dispatches once and the captured release cannot also press.
312
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
313
+ .window_id = 1,
314
+ .label = canvas_label,
315
+ .kind = .pointer_down,
316
+ .x = point.x,
317
+ .y = point.y,
318
+ } });
319
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
320
+ .window_id = 1,
321
+ .label = canvas_label,
322
+ .kind = .pointer_drag,
323
+ .x = point.x + 3,
324
+ .y = point.y,
325
+ } });
326
+ try std.testing.expectEqual(@as(u32, 0), app_state.model.changes);
327
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
328
+ .window_id = 1,
329
+ .label = canvas_label,
330
+ .kind = .pointer_drag,
331
+ .x = point.x + 40,
332
+ .y = point.y,
333
+ } });
334
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.changes);
335
+ // Crossing drag slop gives this gesture to on-drag and cancels the
336
+ // on-hold interpretation armed by the same pointer-down. Waiting past
337
+ // the hold deadline therefore cannot dispatch a second Msg mid-drag.
338
+ try std.testing.expect(!harness.null_platform.startedTimer(DragApp.press_hold_timer_id).?.active);
339
+ try std.testing.expect(harness.null_platform.fireTimer(DragApp.press_hold_timer_id, 400_000_000) == null);
340
+ try std.testing.expectEqual(@as(u32, 0), app_state.model.holds);
341
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
342
+ .window_id = 1,
343
+ .label = canvas_label,
344
+ .kind = .pointer_drag,
345
+ .x = point.x + 2,
346
+ .y = point.y,
347
+ } });
348
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
349
+ .window_id = 1,
350
+ .label = canvas_label,
351
+ .kind = .pointer_up,
352
+ .x = point.x + 2,
353
+ .y = point.y,
354
+ } });
355
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.presses);
356
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.changes);
357
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.ends);
358
+ try std.testing.expectEqual(point.x + 2, app_state.model.last_x);
359
+
360
+ // A cancellation before activation is likewise just an abandoned press;
361
+ // it cannot dispatch a cancel Msg or arm a zero-origin landing.
362
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
363
+ .window_id = 1,
364
+ .label = canvas_label,
365
+ .kind = .pointer_down,
366
+ .x = point.x,
367
+ .y = point.y,
368
+ } });
369
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
370
+ .window_id = 1,
371
+ .label = canvas_label,
372
+ .kind = .pointer_cancel,
373
+ .x = point.x,
374
+ .y = point.y,
375
+ } });
376
+ try std.testing.expectEqual(@as(u32, 0), app_state.model.cancels);
377
+ try std.testing.expect(!harness.runtime.views[0].canvas_widget_drag_layout_motion_armed);
378
+ try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_drag_landing_source_id);
379
+
380
+ // A second contact cannot steal or silently erase a live drag. Its whole
381
+ // sequence stays outside the drag channel; the initiating pointer keeps
382
+ // moving the original source and is the only pointer that may end it.
383
+ const owner_pointer = zero_platform.touch_pointer_id_bit | 101;
384
+ const interloper_pointer = zero_platform.touch_pointer_id_bit | 202;
385
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
386
+ .window_id = 1,
387
+ .label = canvas_label,
388
+ .kind = .pointer_down,
389
+ .pointer_id = owner_pointer,
390
+ .x = point.x,
391
+ .y = point.y,
392
+ } });
393
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
394
+ .window_id = 1,
395
+ .label = canvas_label,
396
+ .kind = .pointer_drag,
397
+ .pointer_id = owner_pointer,
398
+ .x = point.x + 40,
399
+ .y = point.y,
400
+ } });
401
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.changes);
402
+ try std.testing.expectEqual(owner_pointer, harness.runtime.views[0].canvas_widget_drag_pointer_id);
403
+
404
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
405
+ .window_id = 1,
406
+ .label = canvas_label,
407
+ .kind = .pointer_down,
408
+ .pointer_id = interloper_pointer,
409
+ .x = point.x + 180,
410
+ .y = point.y + 80,
411
+ } });
412
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
413
+ .window_id = 1,
414
+ .label = canvas_label,
415
+ .kind = .pointer_drag,
416
+ .pointer_id = interloper_pointer,
417
+ .x = point.x + 200,
418
+ .y = point.y + 90,
419
+ } });
420
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
421
+ .window_id = 1,
422
+ .label = canvas_label,
423
+ .kind = .pointer_up,
424
+ .pointer_id = interloper_pointer,
425
+ .x = point.x + 200,
426
+ .y = point.y + 90,
427
+ } });
428
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.changes);
429
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.ends);
430
+ try std.testing.expectEqual(owner_pointer, harness.runtime.views[0].canvas_widget_drag_pointer_id);
431
+ try std.testing.expect(harness.runtime.views[0].canvasWidgetRenderState().drag_preview_id != null);
432
+
433
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
434
+ .window_id = 1,
435
+ .label = canvas_label,
436
+ .kind = .pointer_drag,
437
+ .pointer_id = owner_pointer,
438
+ .x = point.x + 55,
439
+ .y = point.y,
440
+ } });
441
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
442
+ .window_id = 1,
443
+ .label = canvas_label,
444
+ .kind = .pointer_up,
445
+ .pointer_id = owner_pointer,
446
+ .x = point.x + 55,
447
+ .y = point.y,
448
+ } });
449
+ try std.testing.expectEqual(@as(u32, 3), app_state.model.changes);
450
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.ends);
451
+ try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_widget_drag_pointer_id);
452
+ }
453
+
454
+ test "ui app delivers cancel when a drag update unmounts its source" {
455
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
456
+ defer harness.destroy(std.testing.allocator);
457
+ harness.null_platform.gpu_surfaces = true;
458
+
459
+ const app_state = try std.testing.allocator.create(DragApp);
460
+ defer std.testing.allocator.destroy(app_state);
461
+ app_state.* = DragApp.init(std.heap.page_allocator, .{ .unmount_on_drag = true }, dragOptions());
462
+ defer app_state.deinit();
463
+ const app = app_state.app();
464
+ try harness.start(app);
465
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
466
+ .label = canvas_label,
467
+ .size = geometry.SizeF.init(400, 300),
468
+ .scale_factor = 2,
469
+ .frame_index = 1,
470
+ .timestamp_ns = 1_000_000,
471
+ .nonblank = true,
472
+ } });
473
+
474
+ const target_id = findWidgetIdByText(app_state.tree.?, .row, "Drag target").?;
475
+ const layout = try harness.runtime.canvasWidgetLayout(1, canvas_label);
476
+ const point = layout.findById(target_id).?.frame.normalized().center();
477
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
478
+ .window_id = 1,
479
+ .label = canvas_label,
480
+ .kind = .pointer_down,
481
+ .x = point.x,
482
+ .y = point.y,
483
+ } });
484
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
485
+ .window_id = 1,
486
+ .label = canvas_label,
487
+ .kind = .pointer_drag,
488
+ .x = point.x + 40,
489
+ .y = point.y + 4,
490
+ } });
491
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.changes);
492
+ try std.testing.expect(!app_state.model.target_mounted);
493
+ try std.testing.expectEqual(target_id, app_state.drag_msg_source_id);
494
+ try std.testing.expect(harness.runtime.views[0].canvasWidgetRenderState().drag_preview_id == null);
495
+
496
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
497
+ .window_id = 1,
498
+ .label = canvas_label,
499
+ .kind = .pointer_up,
500
+ .x = point.x + 46,
501
+ .y = point.y + 7,
502
+ } });
503
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.changes);
504
+ try std.testing.expectEqual(@as(u32, 0), app_state.model.ends);
505
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.cancels);
506
+ try std.testing.expectEqual(point.x + 46, app_state.model.last_x);
507
+ try std.testing.expectEqual(@as(canvas.ObjectId, 0), app_state.drag_msg_source_id);
508
+ try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_drag_source_id);
509
+ }
510
+
155
511
  // -------------------------------------- context-menu fallback fixture
156
512
 
157
513
  const TaskRowModel = struct {
@@ -324,6 +324,14 @@ pub const RuntimeView = struct {
324
324
  /// and the source-wins reconcile all behave exactly as a drag.
325
325
  canvas_widget_layout_tweens: [canvas_limits.max_canvas_widget_layout_tweens_per_view]CanvasWidgetLayoutTweenState = undefined,
326
326
  canvas_widget_layout_tween_count: usize = 0,
327
+ /// Presentation-only FLIP motion for keyed draggable widgets displaced
328
+ /// by a drag-driven rebuild. The model-owned layout remains at its final
329
+ /// pose; renderer offsets ease to zero on the frame clock.
330
+ canvas_widget_drag_layout_motions: [canvas_limits.max_canvas_widget_drag_layout_motions_per_view]canvas.WidgetLayoutMotion = undefined,
331
+ canvas_widget_drag_layout_motion_count: usize = 0,
332
+ /// Set by a routed drag phase and consumed by the next layout adoption,
333
+ /// so unrelated model rebuilds never acquire implicit motion.
334
+ canvas_widget_drag_layout_motion_armed: bool = false,
327
335
  /// The view's DISCLOSURE tween (accordion open/close reveal):
328
336
  /// armed by `setCanvasWidgetLayout` when a rebuild flips a
329
337
  /// disclosure widget, advanced once per presented frame from the
@@ -567,6 +575,33 @@ pub const RuntimeView = struct {
567
575
  canvas_widget_focus_visible_keyboard: bool = false,
568
576
  canvas_widget_hovered_id: canvas.ObjectId = 0,
569
577
  canvas_widget_pressed_id: canvas.ObjectId = 0,
578
+ /// The resolved draggable ancestor that owns the live pointer gesture.
579
+ /// `pressed_id` deliberately stays the raw text hit for ordinary text
580
+ /// selection; this separate latch lets a draggable card own that drag.
581
+ canvas_widget_drag_source_id: canvas.ObjectId = 0,
582
+ /// Whether that captured source still has an interactive node in the
583
+ /// adopted layout. Capture survives false to deliver cancellation, but
584
+ /// the floating preview must disappear with the source.
585
+ canvas_widget_drag_source_attached: bool = false,
586
+ /// Pointer sequence that owns the drag candidate/live drag. Hosts with
587
+ /// multiple contacts must not let a second finger move, finish, or
588
+ /// silently replace the first finger's model-visible gesture.
589
+ canvas_widget_drag_pointer_id: u64 = 0,
590
+ canvas_widget_drag_start_point: geometry.PointF = .{},
591
+ canvas_widget_drag_source_origin: geometry.PointF = .{},
592
+ canvas_widget_drag_delta: geometry.OffsetF = .{},
593
+ /// Last live drag-source hit and route. A rebuild may remove, hide, or
594
+ /// disable the source before the pointer's terminal edge; retaining this
595
+ /// POD snapshot lets that edge still deliver one truthful `.cancel`
596
+ /// instead of silently forgetting a phase the app already heard begin.
597
+ canvas_widget_drag_source_hit: ?canvas.WidgetHit = null,
598
+ canvas_widget_drag_route_entries: [canvas.max_widget_depth * 2]canvas.WidgetEventRouteEntry = undefined,
599
+ canvas_widget_drag_route_len: usize = 0,
600
+ /// Pointer-up/cancel handoff: the floating card's last presented origin
601
+ /// becomes the real keyed widget's FLIP origin in the next adoption, so
602
+ /// the item under the pointer itself eases into its destination.
603
+ canvas_widget_drag_landing_source_id: canvas.ObjectId = 0,
604
+ canvas_widget_drag_landing_origin: geometry.PointF = .{},
570
605
  /// The STANDING hover-Msg containment chain: every widget on the
571
606
  /// last resolved raw hover hit's ancestor path that listens for
572
607
  /// hover Msgs (`Widget.hover_msgs`), outermost first
@@ -350,6 +350,14 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
350
350
  if (self.canvas_widget_pressed_id != 0 and !canvasWidgetInteractionTargetExists(self.widgetLayoutTree(), self.canvas_widget_pressed_id)) {
351
351
  self.canvas_widget_pressed_id = 0;
352
352
  }
353
+ // Keep live drag capture across a source unmount/disable/hide.
354
+ // Its preview naturally disappears because the fresh layout has
355
+ // no paintable source, while the next motion or terminal pointer
356
+ // edge resolves through the retained route snapshot and emits the
357
+ // cancel owed to consumers that already received `.change`.
358
+ if (self.canvas_widget_drag_source_id != 0) {
359
+ self.canvas_widget_drag_source_attached = canvasWidgetInteractionTargetExists(self.widgetLayoutTree(), self.canvas_widget_drag_source_id);
360
+ }
353
361
  self.pruneCanvasWidgetTextHistory();
354
362
  self.canvas_widget_cursor = self.canvasWidgetCursorForId(self.canvas_widget_hovered_id);
355
363
  self.widget_revision += 1;
@@ -380,6 +388,10 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
380
388
  // the press fall-through so a click anywhere in a
381
389
  // composite row lights the row, matching the hover walk.
382
390
  .pressed_id = if (self.canvas_widget_pressed_id == 0) null else canvasWidgetPressWashTargetId(self, self.canvas_widget_pressed_id),
391
+ .drag_preview_id = if (self.canvas_widget_drag_source_id == 0 or !self.canvas_widget_drag_source_attached) null else self.canvas_widget_drag_source_id,
392
+ .drag_preview_origin = if (self.canvas_widget_drag_source_id == 0 or !self.canvas_widget_drag_source_attached) null else self.canvas_widget_drag_source_origin,
393
+ .drag_preview_offset = self.canvas_widget_drag_delta,
394
+ .layout_motions = self.canvas_widget_drag_layout_motions[0..self.canvas_widget_drag_layout_motion_count],
383
395
  .hover_point = if (self.canvas_widget_hovered_id == 0) null else self.canvas_widget_hover_point,
384
396
  // Closing disclosure widgets keep painting their content
385
397
  // (clipped to the shrinking frame) only while the
@@ -165,5 +165,6 @@ pub fn Bindings(comptime prefix: []const u8) type {
165
165
  pub const frame_msg = Symbol(fn (width: f64, height: f64, timestamp_ms: f64, interval_ms: f64, out: *[*]const u8, out_len: *usize) callconv(.c) void, "frame_msg");
166
166
  pub const key_msg = Symbol(fn (key: [*]const u8, key_len: usize, shift: u8, control: u8, alt: u8, super_mod: u8, out: *[*]const u8, out_len: *usize) callconv(.c) void, "key_msg");
167
167
  pub const pinch_msg = Symbol(fn (window_id: f64, label: [*]const u8, label_len: usize, phase: u32, scale: f64, x: f64, y: f64, out: *[*]const u8, out_len: *usize) callconv(.c) void, "pinch_msg");
168
+ pub const drop_msg = Symbol(fn (event: [*]const u8, event_len: usize, out: *[*]const u8, out_len: *usize) callconv(.c) void, "drop_msg");
168
169
  };
169
170
  }
@@ -266,8 +266,9 @@ const Emitter = struct {
266
266
  // mere type under one of these names would falsely activate
267
267
  // the channel and then fail as a non-function.
268
268
  try reserved.appendSlice(self.arena, &.{
269
- "subscriptions", "commandMsg", "frameMsg", "keyMsg",
270
- "pinchMsg", "appearanceMsg", "chromeMsg", "envMsgs",
269
+ "subscriptions", "commandMsg", "frameMsg", "keyMsg",
270
+ "pinchMsg", "dropMsg", "appearanceMsg", "chromeMsg",
271
+ "envMsgs",
271
272
  });
272
273
  // The wiring aliases (wiringAliases) claim the host layer's
273
274
  // fixed spellings whenever the sidecar's own names differ.
@@ -276,7 +277,7 @@ const Emitter = struct {
276
277
  // Optional glue reserves its name only when it is emitted.
277
278
  if (self.sidecar.model_helpers.len > 0) try reserved.append(self.arena, "callHelper");
278
279
  const chan = self.sidecar.channels;
279
- if (chan.command_msg or chan.frame_msg or chan.key_msg or chan.pinch_msg) {
280
+ if (chan.command_msg or chan.frame_msg or chan.key_msg or chan.pinch_msg or chan.drop_msg) {
280
281
  try reserved.appendSlice(self.arena, &.{ "msgFromEnvelope", "envelope", "header" });
281
282
  }
282
283
  if (self.sidecar.init_returns_cmd) try reserved.append(self.arena, "InitResult");
@@ -284,6 +285,7 @@ const Emitter = struct {
284
285
  if (self.sidecar.channels.frame_msg) try reserved.append(self.arena, "FrameEvent");
285
286
  if (self.sidecar.channels.key_msg) try reserved.append(self.arena, "KeyEvent");
286
287
  if (self.sidecar.channels.pinch_msg) try reserved.appendSlice(self.arena, &.{ "PinchEvent", "PinchPhase" });
288
+ if (self.sidecar.channels.drop_msg) try reserved.appendSlice(self.arena, &.{ "FileDropEvent", "FileDropPoint" });
287
289
 
288
290
  const table_names = try self.allTableNames();
289
291
  for (table_names) |name| {
@@ -989,7 +991,12 @@ const Emitter = struct {
989
991
  if (self.sidecar.update_returns_cmd) {
990
992
  try self.raw(" return .{ .model = snapshotModel(), .cmd = cmd_ptr[0..cmd_len] };\n}\n");
991
993
  } else {
992
- try self.raw(" _ = cmd_ptr;\n _ = cmd_len;\n return snapshotModel();\n}\n");
994
+ // Every dispatch ABI receives these as out-pointers even when
995
+ // the authored update returns only Model. Passing their addresses
996
+ // is already a use; discarding them again is a Zig 0.16 error
997
+ // ("pointless discard of local variable"). The core owns and
998
+ // ignores the empty command envelope in this shape.
999
+ try self.raw(" return snapshotModel();\n}\n");
993
1000
  }
994
1001
 
995
1002
  if (self.sidecar.has_subscriptions) {
@@ -1102,7 +1109,7 @@ const Emitter = struct {
1102
1109
 
1103
1110
  fn channels(self: *Emitter) Error!void {
1104
1111
  const chan = self.sidecar.channels;
1105
- const any_fn_channel = chan.command_msg or chan.frame_msg or chan.key_msg or chan.pinch_msg;
1112
+ const any_fn_channel = chan.command_msg or chan.frame_msg or chan.key_msg or chan.pinch_msg or chan.drop_msg;
1106
1113
 
1107
1114
  if (chan.command_msg) {
1108
1115
  try self.print(
@@ -1188,6 +1195,34 @@ const Emitter = struct {
1188
1195
  \\
1189
1196
  , .{ident(self.sidecar.msg.name)});
1190
1197
  }
1198
+ if (chan.drop_msg) {
1199
+ try self.print(
1200
+ \\
1201
+ \\/// A file drop's optional view-local point.
1202
+ \\pub const FileDropPoint = struct {{
1203
+ \\ x: f64,
1204
+ \\ y: f64,
1205
+ \\}};
1206
+ \\
1207
+ \\/// The file-drop channel's source identity, optional point,
1208
+ \\/// and byte-text path list.
1209
+ \\pub const FileDropEvent = struct {{
1210
+ \\ windowId: f64,
1211
+ \\ viewLabel: []const u8,
1212
+ \\ point: ?FileDropPoint,
1213
+ \\ paths: []const []const u8,
1214
+ \\}};
1215
+ \\
1216
+ \\pub fn dropMsg(drop: FileDropEvent) ?{f} {{
1217
+ \\ const encoded = shim_rt.encodeAlloc(FileDropEvent, drop, shim_rt.frameAllocator());
1218
+ \\ var out_ptr: [*]const u8 = &shim_rt.channel_out_guard;
1219
+ \\ var out_len: usize = 0;
1220
+ \\ abi.drop_msg(encoded.ptr, encoded.len, &out_ptr, &out_len);
1221
+ \\ return msgFromEnvelope(shim_rt.channelEnvelopeBytes(out_ptr, out_len));
1222
+ \\}}
1223
+ \\
1224
+ , .{ident(self.sidecar.msg.name)});
1225
+ }
1191
1226
 
1192
1227
  if (chan.appearance_msg) |arm_name| {
1193
1228
  try self.print("\n/// The arm the host fills with the structural appearance record.\npub const appearanceMsg = \"{f}\";\n", .{std.zig.fmtString(arm_name)});
@@ -1688,7 +1723,7 @@ test "a u64 attestation on chrome geometry refuses at check time" {
1688
1723
  \\ {"name": "chrome_changed", "payload": {"kind": "record", "name": "Msg_chrome_changed"}}
1689
1724
  \\ ], "unbound": []},
1690
1725
  \\ "init_returns_cmd": false, "update_returns_cmd": true, "has_subscriptions": false,
1691
- \\ "channels": {"command_msg": false, "frame_msg": false, "key_msg": false, "pinch_msg": false,
1726
+ \\ "channels": {"command_msg": false, "frame_msg": false, "key_msg": false, "pinch_msg": false, "drop_msg": false,
1692
1727
  \\ "appearance_msg": null, "chrome_msg": "chrome_changed", "env_msgs": []},
1693
1728
  \\ "abi": {"prefix": "nsc_core_", "exports": ["abi_version", "build_id", "set_panic_sink", "init",
1694
1729
  \\ "collect", "frame_reset", "boot_cmd", "dispatch_void", "dispatch_bytes", "dispatch_number",
@@ -1857,7 +1892,7 @@ test "a shared authored type spelling like a synthesized name stays a top-level
1857
1892
  \\ "model": "Model", "model_helpers": [], "model_unbound": [],
1858
1893
  \\ "msg": {"name": "Msg", "arms": [{"name": "bump", "payload": {"kind": "void"}}], "unbound": []},
1859
1894
  \\ "init_returns_cmd": false, "update_returns_cmd": true, "has_subscriptions": false,
1860
- \\ "channels": {"command_msg": false, "frame_msg": false, "key_msg": false, "pinch_msg": false,
1895
+ \\ "channels": {"command_msg": false, "frame_msg": false, "key_msg": false, "pinch_msg": false, "drop_msg": false,
1861
1896
  \\ "appearance_msg": null, "chrome_msg": null, "env_msgs": []},
1862
1897
  \\ "abi": {"prefix": "nsc_core_", "exports": ["abi_version", "build_id", "set_panic_sink", "init",
1863
1898
  \\ "collect", "frame_reset", "boot_cmd", "dispatch_void", "dispatch_bytes", "dispatch_number",
@@ -1957,6 +1992,18 @@ test "UpdateResult reserves only when the cmd-returning update emits it" {
1957
1992
  try testing.expect(std.mem.indexOf(u8, generated, "pub fn update(model: *const Model, msg: Msg) *const Model {") != null);
1958
1993
  }
1959
1994
 
1995
+ test "model-only update does not pointlessly discard command out variables" {
1996
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1997
+ defer arena_state.deinit();
1998
+ const arena = arena_state.allocator();
1999
+ const source = try std.mem.replaceOwned(u8, arena, sidecar_mod.minimal_valid_json, "\"update_returns_cmd\": true", "\"update_returns_cmd\": false");
2000
+ const generated = try emitFromJson(arena, source);
2001
+ try testing.expect(std.mem.indexOf(u8, generated, "pub fn update(model: *const Model, msg: Msg) *const Model {") != null);
2002
+ try testing.expect(std.mem.indexOf(u8, generated, "abi.dispatch_void(0, &cmd_ptr, &cmd_len)") != null);
2003
+ try testing.expect(std.mem.indexOf(u8, generated, "_ = cmd_ptr;") == null);
2004
+ try testing.expect(std.mem.indexOf(u8, generated, "_ = cmd_len;") == null);
2005
+ }
2006
+
1960
2007
  test "a node-stored record as a message arm payload refuses; value-stored passes" {
1961
2008
  var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1962
2009
  defer arena_state.deinit();
@@ -2292,7 +2339,7 @@ test "a chrome arm holding its insets by reference refuses" {
2292
2339
  \\ {"name": "chrome_changed", "payload": {"kind": "record", "name": "Msg_chrome_changed"}}
2293
2340
  \\ ], "unbound": []},
2294
2341
  \\ "init_returns_cmd": false, "update_returns_cmd": true, "has_subscriptions": false,
2295
- \\ "channels": {"command_msg": false, "frame_msg": false, "key_msg": false, "pinch_msg": false,
2342
+ \\ "channels": {"command_msg": false, "frame_msg": false, "key_msg": false, "pinch_msg": false, "drop_msg": false,
2296
2343
  \\ "appearance_msg": null, "chrome_msg": "chrome_changed", "env_msgs": []},
2297
2344
  \\ "abi": {"prefix": "nsc_core_", "exports": ["abi_version", "build_id", "set_panic_sink", "init",
2298
2345
  \\ "collect", "frame_reset", "boot_cmd", "dispatch_void", "dispatch_bytes", "dispatch_number",