@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
|
@@ -69,6 +69,10 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
69
69
|
// so accordion reveals replay frame for frame exactly
|
|
70
70
|
// like split fractions do.
|
|
71
71
|
try self.advanceCanvasWidgetDisclosureTweenForFrame(index, frame_event.timestamp_ns);
|
|
72
|
+
// Drag-reflow FLIP offsets share the recorded clock. They
|
|
73
|
+
// move only presentation transforms; the retained layout is
|
|
74
|
+
// already the exact drop result used by hit testing.
|
|
75
|
+
try self.advanceCanvasWidgetDragLayoutMotionForFrame(index, frame_event.timestamp_ns);
|
|
72
76
|
// The anchored-tooltip hover-intent delay fires on the
|
|
73
77
|
// same recorded clock: a dwell past the delay shows its
|
|
74
78
|
// tooltip on a deterministic frame, replayed exactly.
|
|
@@ -296,6 +300,30 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
296
300
|
=> null,
|
|
297
301
|
else => return err,
|
|
298
302
|
};
|
|
303
|
+
// Resolve a draggable ancestor BEFORE the interaction pass can
|
|
304
|
+
// clear the raw pressed text id on release. A live widget drag
|
|
305
|
+
// owns text motion, so the text-selection pass below stands
|
|
306
|
+
// down instead of selecting the card label.
|
|
307
|
+
var widget_drag_event = CanvasWidgetEventMethods().routeCanvasWidgetDragInput(self, input_event, &self.widget_drag_event_route_entries) catch |err| switch (err) {
|
|
308
|
+
error.WindowNotFound,
|
|
309
|
+
error.ViewNotFound,
|
|
310
|
+
error.InvalidViewOptions,
|
|
311
|
+
=> null,
|
|
312
|
+
else => return err,
|
|
313
|
+
};
|
|
314
|
+
// A terminal drag event exists only after the gesture crossed the
|
|
315
|
+
// runtime's drag slop. Pointer capture also routes this release to
|
|
316
|
+
// the original press target, so retire its click now: otherwise an
|
|
317
|
+
// element with both on_press and on_drag would activate before its
|
|
318
|
+
// drop Msg. A sub-slop release produces no drag event and keeps the
|
|
319
|
+
// ordinary press path intact.
|
|
320
|
+
const widget_drag_terminal = if (widget_drag_event) |drag_event|
|
|
321
|
+
drag_event.drag.phase == .end or drag_event.drag.phase == .cancel
|
|
322
|
+
else
|
|
323
|
+
false;
|
|
324
|
+
if (widget_drag_terminal) {
|
|
325
|
+
if (widget_pointer_event) |*pointer_event| pointer_event.press_target = null;
|
|
326
|
+
}
|
|
299
327
|
var dismissed_surface_id: canvas.ObjectId = 0;
|
|
300
328
|
var window_drag_started = false;
|
|
301
329
|
if (widget_pointer_event) |*pointer_event| {
|
|
@@ -324,22 +352,21 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
324
352
|
// pointer really went down.
|
|
325
353
|
try CanvasWidgetEventMethods().reconcileCanvasTooltipIntentForConsumedPointerInput(self, input_event);
|
|
326
354
|
} else {
|
|
327
|
-
|
|
355
|
+
// The same click-vs-drag arbitration covers runtime-owned
|
|
356
|
+
// activation (checkbox/toggle state), not only app Msgs and
|
|
357
|
+
// commands. Geometry controls applied their live resize on
|
|
358
|
+
// move; a terminal drag owes no release mutation.
|
|
359
|
+
if (!widget_drag_terminal) try CanvasWidgetEventMethods().updateCanvasWidgetControlFromPointer(self, pointer_event.*);
|
|
328
360
|
try CanvasWidgetEventMethods().updateCanvasWidgetInteractionFromPointer(self, pointer_event.*);
|
|
329
361
|
// The text pass may stamp a caret/selection or clear
|
|
330
362
|
// edit onto the event for the app dispatch below.
|
|
331
|
-
|
|
363
|
+
if (widget_drag_event == null) {
|
|
364
|
+
try CanvasWidgetEventMethods().updateCanvasWidgetTextFromPointer(self, pointer_event);
|
|
365
|
+
}
|
|
332
366
|
try CanvasWidgetEventMethods().updateCanvasWidgetScrollFromPointer(self, pointer_event.*);
|
|
333
367
|
try CanvasWidgetEventMethods().updateCanvasWidgetFocusFromPointer(self, pointer_event.*);
|
|
334
368
|
}
|
|
335
369
|
}
|
|
336
|
-
const widget_drag_event = CanvasWidgetEventMethods().routeCanvasWidgetDragInput(self, input_event, &self.widget_event_route_entries) catch |err| switch (err) {
|
|
337
|
-
error.WindowNotFound,
|
|
338
|
-
error.ViewNotFound,
|
|
339
|
-
error.InvalidViewOptions,
|
|
340
|
-
=> null,
|
|
341
|
-
else => return err,
|
|
342
|
-
};
|
|
343
370
|
// A live target-less composition owns its surface's
|
|
344
371
|
// UNCHORDED keys wholesale, and it owns them BEFORE any
|
|
345
372
|
// widget pass runs: on hosts that surface the key ahead of
|
|
@@ -372,17 +399,36 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
372
399
|
CanvasWidgetEventMethods().consumeCanvasWidgetTerminalPasteKeyLifetime(self, input_event);
|
|
373
400
|
const widget_key_lifetime_suppressed =
|
|
374
401
|
tab_input_focus_entry_suppressed or terminal_paste_release_suppressed;
|
|
375
|
-
|
|
402
|
+
// Once an actual drag is live, plain Escape is its cancellation
|
|
403
|
+
// gesture. Resolve it after the input-method ownership test, but
|
|
404
|
+
// before dismissal/focus/widget-key routing, so one Escape has
|
|
405
|
+
// exactly one meaning and the app receives phase 2.
|
|
406
|
+
const widget_drag_escape_cancelled = drag_cancelled: {
|
|
407
|
+
if (targetless_composition_owns_keys or widget_key_lifetime_suppressed) break :drag_cancelled false;
|
|
408
|
+
const drag_cancel = CanvasWidgetEventMethods().routeCanvasWidgetDragCancelFromKeyboardInput(self, input_event, &self.widget_drag_event_route_entries) catch |err| switch (err) {
|
|
409
|
+
error.WindowNotFound,
|
|
410
|
+
error.ViewNotFound,
|
|
411
|
+
error.InvalidViewOptions,
|
|
412
|
+
=> null,
|
|
413
|
+
else => return err,
|
|
414
|
+
};
|
|
415
|
+
if (drag_cancel) |event| {
|
|
416
|
+
widget_drag_event = event;
|
|
417
|
+
break :drag_cancelled true;
|
|
418
|
+
}
|
|
419
|
+
break :drag_cancelled false;
|
|
420
|
+
};
|
|
421
|
+
const keyboard_dismissed_id = if (targetless_composition_owns_keys or widget_key_lifetime_suppressed or widget_drag_escape_cancelled)
|
|
376
422
|
0
|
|
377
423
|
else
|
|
378
424
|
try CanvasWidgetEventMethods().dismissCanvasWidgetSurfaceFromKeyboardInput(self, input_event);
|
|
379
425
|
if (keyboard_dismissed_id != 0) dismissed_surface_id = keyboard_dismissed_id;
|
|
380
426
|
const widget_surface_dismissed = keyboard_dismissed_id != 0;
|
|
381
|
-
const widget_focus_moved = if (widget_surface_dismissed or targetless_composition_owns_keys or widget_key_lifetime_suppressed)
|
|
427
|
+
const widget_focus_moved = if (widget_surface_dismissed or targetless_composition_owns_keys or widget_key_lifetime_suppressed or widget_drag_escape_cancelled)
|
|
382
428
|
false
|
|
383
429
|
else
|
|
384
430
|
try CanvasWidgetEventMethods().updateCanvasWidgetFocusFromKeyboardInput(self, input_event);
|
|
385
|
-
var widget_keyboard_event = if (widget_surface_dismissed or targetless_composition_owns_keys or widget_key_lifetime_suppressed)
|
|
431
|
+
var widget_keyboard_event = if (widget_surface_dismissed or targetless_composition_owns_keys or widget_key_lifetime_suppressed or widget_drag_escape_cancelled)
|
|
386
432
|
null
|
|
387
433
|
else
|
|
388
434
|
CanvasWidgetEventMethods().routeCanvasWidgetKeyboardInput(self, input_event, &self.widget_event_route_entries) catch |err| switch (err) {
|
|
@@ -403,7 +449,7 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
403
449
|
// may stamp a paste/cut edit onto the routed keyboard event;
|
|
404
450
|
// the pasted bytes live in this frame until dispatch returns.
|
|
405
451
|
var clipboard_paste_buffer: [platform.max_clipboard_data_bytes]u8 = undefined;
|
|
406
|
-
if (!widget_surface_dismissed) {
|
|
452
|
+
if (!widget_surface_dismissed and !widget_drag_escape_cancelled) {
|
|
407
453
|
try CanvasWidgetEventMethods().applyCanvasWidgetClipboardShortcut(
|
|
408
454
|
self,
|
|
409
455
|
input_event,
|
|
@@ -682,7 +728,7 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
682
728
|
try self.dispatchEvent(app, .{ .canvas_widget_keyboard = followup });
|
|
683
729
|
}
|
|
684
730
|
} else if ((input_event.kind == .key_down or input_event.kind == .key_up) and
|
|
685
|
-
!widget_surface_dismissed and !widget_key_lifetime_suppressed)
|
|
731
|
+
!widget_surface_dismissed and !widget_key_lifetime_suppressed and !widget_drag_escape_cancelled)
|
|
686
732
|
{
|
|
687
733
|
// No focused widget routed this key (nothing is
|
|
688
734
|
// focused, or the focused id is gone from the tree): the
|
package/src/runtime/tests.zig
CHANGED
|
@@ -20,6 +20,7 @@ test {
|
|
|
20
20
|
_ = @import("effects_fetch_tests.zig");
|
|
21
21
|
_ = @import("effects_file_tests.zig");
|
|
22
22
|
_ = @import("effects_clipboard_tests.zig");
|
|
23
|
+
_ = @import("effects_notification_tests.zig");
|
|
23
24
|
_ = @import("effects_audio_tests.zig");
|
|
24
25
|
_ = @import("effects_video_tests.zig");
|
|
25
26
|
_ = @import("effects_image_tests.zig");
|
|
@@ -287,6 +287,9 @@
|
|
|
287
287
|
//! frame event carries the state.
|
|
288
288
|
//! quit_app -> `fx.quitApp()` — the graceful terminate through the
|
|
289
289
|
//! same shutdown path a last-window close takes.
|
|
290
|
+
//! show_notification -> `fx.showNotification` fire-and-forget; invalid or
|
|
291
|
+
//! unavailable requests fail closed, and replay suppresses
|
|
292
|
+
//! the external user-visible side effect.
|
|
290
293
|
//! cancel -> by wire key, first match wins in this order: the
|
|
291
294
|
//! request table (`fx.cancelHostRequest`, silent), the
|
|
292
295
|
//! named-op table (the entry is marked dropped and
|
|
@@ -1217,6 +1220,19 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
1217
1220
|
// retiring the entry in ptyEventMsg.
|
|
1218
1221
|
if (findPty(key)) |index| fx.ptyKill(pty_key_base + index);
|
|
1219
1222
|
},
|
|
1223
|
+
// show_notification [op][title_len u32 LE][title]
|
|
1224
|
+
// [subtitle_len u32 LE][subtitle]
|
|
1225
|
+
// [body_len u32 LE][body]
|
|
1226
|
+
0x1D => {
|
|
1227
|
+
const title = takeLongBytes(cmd, &at);
|
|
1228
|
+
const subtitle = takeLongBytes(cmd, &at);
|
|
1229
|
+
const body = takeLongBytes(cmd, &at);
|
|
1230
|
+
fx.showNotification(.{
|
|
1231
|
+
.title = title,
|
|
1232
|
+
.subtitle = subtitle,
|
|
1233
|
+
.body = body,
|
|
1234
|
+
});
|
|
1235
|
+
},
|
|
1220
1236
|
else => @panic("ts core host: unknown command wire record - the core and this runtime disagree on cmd_format_version"),
|
|
1221
1237
|
}
|
|
1222
1238
|
}
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
//! THE HOST-EVENT CHANNELS are the core's own, comptime-detected from
|
|
29
29
|
//! its exports (export exists -> wired; a wiring that also sets the
|
|
30
30
|
//! seam is a teaching panic): `frameMsg(model, frame)` -> `on_frame`,
|
|
31
|
-
//! `keyMsg(key)` -> `on_key`, and the arm
|
|
32
|
-
//! `chromeMsg` -> `on_appearance`/`on_chrome`, each host event built
|
|
31
|
+
//! `keyMsg(key)` -> `on_key`, `dropMsg(drop)` -> `on_drop`, and the arm
|
|
32
|
+
//! exports `appearanceMsg` / `chromeMsg` -> `on_appearance`/`on_chrome`, each host event built
|
|
33
33
|
//! structurally by field name from the core's declared records (the
|
|
34
34
|
//! effects-routing rule applied to the app shell; every shape mismatch
|
|
35
35
|
//! is a teaching compile error re-deriving the frontend's NS1033).
|
|
@@ -206,6 +206,12 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
206
206
|
}
|
|
207
207
|
stamped.on_pinch = pinchMsgAdapter;
|
|
208
208
|
}
|
|
209
|
+
if (comptime @hasDecl(core, "dropMsg")) {
|
|
210
|
+
if (options.on_drop != null) {
|
|
211
|
+
@panic("TsUiApp wires on_drop from the core's dropMsg export - remove the wiring's on_drop");
|
|
212
|
+
}
|
|
213
|
+
stamped.on_drop = dropMsgAdapter;
|
|
214
|
+
}
|
|
209
215
|
if (comptime @hasDecl(core, "appearanceMsg")) {
|
|
210
216
|
if (options.on_appearance != null) {
|
|
211
217
|
@panic("TsUiApp wires on_appearance from the core's appearanceMsg export - remove the wiring's on_appearance");
|
|
@@ -423,6 +429,33 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
423
429
|
return core.pinchMsg(arg);
|
|
424
430
|
}
|
|
425
431
|
|
|
432
|
+
/// `Options.on_drop` over the core's `dropMsg(drop)` export: the
|
|
433
|
+
/// emitted FileDropEvent record carries the source window/view,
|
|
434
|
+
/// optional view-local point, and every path as byte text. The
|
|
435
|
+
/// slices stay borrowed through the channel call; a Msg that keeps
|
|
436
|
+
/// one is committed through the ordinary core dispatch immediately
|
|
437
|
+
/// after this mapper returns.
|
|
438
|
+
fn dropMsgAdapter(drop: platform.FileDropEvent) ?Msg {
|
|
439
|
+
const params = @typeInfo(@TypeOf(core.dropMsg)).@"fn".params;
|
|
440
|
+
if (comptime params.len != 1) {
|
|
441
|
+
@compileError("TsUiApp: dropMsg must take one FileDropEvent parameter - regenerate the core");
|
|
442
|
+
}
|
|
443
|
+
const DropArg = params[0].type.?;
|
|
444
|
+
comptime validateDropEvent(DropArg);
|
|
445
|
+
const PointArg = @typeInfo(@FieldType(DropArg, "point")).optional.child;
|
|
446
|
+
var arg: DropArg = undefined;
|
|
447
|
+
arg.windowId = channelNum(@FieldType(DropArg, "windowId"), @floatFromInt(drop.window_id));
|
|
448
|
+
arg.viewLabel = drop.view_label;
|
|
449
|
+
arg.point = if (drop.point) |point| blk: {
|
|
450
|
+
var out: PointArg = undefined;
|
|
451
|
+
out.x = channelNum(@FieldType(PointArg, "x"), point.x);
|
|
452
|
+
out.y = channelNum(@FieldType(PointArg, "y"), point.y);
|
|
453
|
+
break :blk out;
|
|
454
|
+
} else null;
|
|
455
|
+
arg.paths = drop.paths;
|
|
456
|
+
return core.dropMsg(arg);
|
|
457
|
+
}
|
|
458
|
+
|
|
426
459
|
/// `Options.on_appearance` over the core's `appearanceMsg` arm
|
|
427
460
|
/// export: the appearance record — `colorScheme` (a declared
|
|
428
461
|
/// light/dark enum, matched by member name), `reduceMotion`,
|
|
@@ -509,6 +542,26 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
509
542
|
}
|
|
510
543
|
}
|
|
511
544
|
|
|
545
|
+
fn validateDropEvent(comptime T: type) void {
|
|
546
|
+
const teaching = "TsUiApp: dropMsg's FileDropEvent must be exactly { windowId: number; viewLabel: string; point: { x: number; y: number } | null; paths: readonly Uint8Array[] }";
|
|
547
|
+
const info = @typeInfo(T);
|
|
548
|
+
if (info != .@"struct" or info.@"struct".fields.len != 4) @compileError(teaching);
|
|
549
|
+
if (!@hasField(T, "windowId") or !@hasField(T, "viewLabel") or !@hasField(T, "point") or !@hasField(T, "paths")) @compileError(teaching);
|
|
550
|
+
validateChannelRecord(struct { windowId: @FieldType(T, "windowId") }, &.{"windowId"}, "dropMsg's FileDropEvent", &.{});
|
|
551
|
+
if (@FieldType(T, "viewLabel") != []const u8) @compileError(teaching);
|
|
552
|
+
|
|
553
|
+
const Point = switch (@typeInfo(@FieldType(T, "point"))) {
|
|
554
|
+
.optional => |optional| optional.child,
|
|
555
|
+
else => @compileError(teaching),
|
|
556
|
+
};
|
|
557
|
+
validateChannelRecord(Point, &.{ "x", "y" }, "dropMsg's FileDropEvent.point", &.{ "x", "y" });
|
|
558
|
+
|
|
559
|
+
const paths = @typeInfo(@FieldType(T, "paths"));
|
|
560
|
+
if (paths != .pointer or paths.pointer.size != .slice) @compileError(teaching);
|
|
561
|
+
const path = @typeInfo(paths.pointer.child);
|
|
562
|
+
if (path != .pointer or path.pointer.size != .slice or path.pointer.child != u8 or !path.pointer.is_const) @compileError(teaching);
|
|
563
|
+
}
|
|
564
|
+
|
|
512
565
|
fn validateAppearanceArm(comptime T: type) void {
|
|
513
566
|
const teaching = "TsUiApp: appearanceMsg's arm must carry exactly { colorScheme: a named light/dark alias; reduceMotion: boolean; highContrast: boolean }";
|
|
514
567
|
const info = @typeInfo(T);
|
package/src/runtime/ui_app.zig
CHANGED
|
@@ -36,6 +36,7 @@ const platform = @import("../platform/root.zig");
|
|
|
36
36
|
const core = @import("core.zig");
|
|
37
37
|
const canvas_frame = @import("canvas_frame.zig");
|
|
38
38
|
const canvas_limits = @import("canvas_limits.zig");
|
|
39
|
+
const canvas_widget_events = @import("canvas_widget_events.zig");
|
|
39
40
|
const launch_timing = @import("launch_timing.zig");
|
|
40
41
|
const runtime_effects = @import("effects.zig");
|
|
41
42
|
const terminal_session = @import("terminal_session.zig");
|
|
@@ -617,6 +618,13 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
617
618
|
/// also declare canvas scroll regions should leave this
|
|
618
619
|
/// null (regions consume wheel input themselves).
|
|
619
620
|
on_wheel: ?*const fn (wheel: platform.WheelEvent) ?MsgT = null,
|
|
621
|
+
/// Optional mapping from an OS file drop into a message. This
|
|
622
|
+
/// app-level channel receives every drop after any targeted
|
|
623
|
+
/// canvas widget handler, with the source window/view, optional
|
|
624
|
+
/// view-local point, and the complete path list intact. The
|
|
625
|
+
/// paths are borrowed for the callback; dispatch copies any
|
|
626
|
+
/// bytes the model retains through the ordinary update path.
|
|
627
|
+
on_drop: ?*const fn (drop: platform.FileDropEvent) ?MsgT = null,
|
|
620
628
|
/// Optional mapping from runtime timer events (started via
|
|
621
629
|
/// `runtime.startTimer`) into messages. Framework-reserved timer
|
|
622
630
|
/// ids (>= `platform.reserved_timer_id_base`) are handled
|
|
@@ -987,6 +995,17 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
987
995
|
/// payload of any size can be owned — a fixed budget would turn
|
|
988
996
|
/// a large `ui.fmt` payload into a silently unpaired leave.
|
|
989
997
|
hover_msg_leave_arenas: [hover_msg_slot_count]std.heap.ArenaAllocator = undefined,
|
|
998
|
+
/// The authored `on-drag` Msg captured while the source is live.
|
|
999
|
+
/// A phase-0 update is allowed to unmount its own widget; the owned
|
|
1000
|
+
/// template preserves that handler until the runtime delivers the
|
|
1001
|
+
/// paired cancel through its retained drag-route snapshot.
|
|
1002
|
+
drag_msg_window_id: platform.WindowId = 1,
|
|
1003
|
+
drag_msg_view_label_storage: [app_manifest.max_view_label_bytes]u8 = undefined,
|
|
1004
|
+
drag_msg_view_label_len: usize = 0,
|
|
1005
|
+
drag_msg_source_id: canvas.ObjectId = 0,
|
|
1006
|
+
drag_msg_view_size: geometry.SizeF = .{},
|
|
1007
|
+
drag_msg_template: ?MsgT = null,
|
|
1008
|
+
drag_msg_template_arena: std.heap.ArenaAllocator,
|
|
990
1009
|
/// Re-entrancy guard for `drainHoverMsgs`: the drain's own
|
|
991
1010
|
/// dispatches must not drain recursively through `dispatch`'s
|
|
992
1011
|
/// tail.
|
|
@@ -1208,6 +1227,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1208
1227
|
.window_slots = windowSlotsInit(backing),
|
|
1209
1228
|
.markup_fragment_slots = if (comptime fragment_watch_enabled) markupFragmentSlotsInit(backing) else {},
|
|
1210
1229
|
.hover_msg_leave_arenas = hoverMsgLeaveArenasInit(backing),
|
|
1230
|
+
.drag_msg_template_arena = std.heap.ArenaAllocator.init(backing),
|
|
1211
1231
|
.effects = Effects.init(backing),
|
|
1212
1232
|
.terminal_sessions = terminal_session.TerminalSessions.init(backing),
|
|
1213
1233
|
};
|
|
@@ -1273,6 +1293,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1273
1293
|
.window_slots = windowSlotsInit(backing),
|
|
1274
1294
|
.markup_fragment_slots = if (comptime fragment_watch_enabled) markupFragmentSlotsInit(backing) else {},
|
|
1275
1295
|
.hover_msg_leave_arenas = hoverMsgLeaveArenasInit(backing),
|
|
1296
|
+
.drag_msg_template_arena = std.heap.ArenaAllocator.init(backing),
|
|
1276
1297
|
.effects = Effects.init(backing),
|
|
1277
1298
|
.terminal_sessions = terminal_session.TerminalSessions.init(backing),
|
|
1278
1299
|
};
|
|
@@ -1311,6 +1332,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1311
1332
|
slot.arenas[1].deinit();
|
|
1312
1333
|
}
|
|
1313
1334
|
for (&self.hover_msg_leave_arenas) |*arena| arena.deinit();
|
|
1335
|
+
self.drag_msg_template_arena.deinit();
|
|
1314
1336
|
if (self.pixel_buffer.len > 0) self.backing.free(self.pixel_buffer);
|
|
1315
1337
|
if (self.pixel_scratch.len > 0) self.backing.free(self.pixel_scratch);
|
|
1316
1338
|
self.pixel_buffer = &.{};
|
|
@@ -3985,9 +4007,14 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
3985
4007
|
try self.rebuildVideoChrome(runtime);
|
|
3986
4008
|
},
|
|
3987
4009
|
.effects_wake => try self.drainEffects(runtime),
|
|
4010
|
+
.files_dropped => |drop| {
|
|
4011
|
+
const map = self.options.on_drop orelse return;
|
|
4012
|
+
if (map(drop)) |msg| try self.dispatch(runtime, drop.window_id, msg);
|
|
4013
|
+
},
|
|
3988
4014
|
.gpu_surface_frame => |frame_event| try self.handleFrame(runtime, frame_event),
|
|
3989
4015
|
.gpu_surface_resized => |resize_event| try self.handleResize(runtime, resize_event),
|
|
3990
4016
|
.canvas_widget_pointer => |pointer_event| try self.handlePointer(runtime, pointer_event),
|
|
4017
|
+
.canvas_widget_drag => |drag_event| try self.handleWidgetDrag(runtime, drag_event),
|
|
3991
4018
|
.canvas_widget_keyboard => |keyboard_event| try self.handleKeyboard(runtime, keyboard_event),
|
|
3992
4019
|
.canvas_widget_scroll => |scroll_event| try self.handleScroll(runtime, scroll_event),
|
|
3993
4020
|
.canvas_widget_context_menu => |menu_event| try self.handleContextMenu(runtime, menu_event),
|
|
@@ -5648,6 +5675,91 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
5648
5675
|
}
|
|
5649
5676
|
}
|
|
5650
5677
|
|
|
5678
|
+
/// A markup `on-drag` dispatches live motion, release, and
|
|
5679
|
+
/// cancellation. Motion remains runtime-owned for capture and the
|
|
5680
|
+
/// floating preview; the model receives the source binding, phase,
|
|
5681
|
+
/// point, and view dimensions so it can preview a semantic insertion
|
|
5682
|
+
/// during motion, commit it on release, or restore it on cancel.
|
|
5683
|
+
fn handleWidgetDrag(self: *Self, runtime: *Runtime, drag_event: core.CanvasWidgetDragEvent) anyerror!void {
|
|
5684
|
+
// The runtime promotes a source only after this slop, so terminal
|
|
5685
|
+
// phases are always real drags and must dispatch even when the
|
|
5686
|
+
// pointer returned near its origin before release. Change events
|
|
5687
|
+
// below slop remain on the low-level channel to own text motion,
|
|
5688
|
+
// but declarative apps do not hear them.
|
|
5689
|
+
if (drag_event.drag.phase == .change and
|
|
5690
|
+
!canvas_widget_events.canvasWidgetDragCrossedSlop(drag_event.drag.delta)) return;
|
|
5691
|
+
const source = drag_event.source orelse return;
|
|
5692
|
+
// Once drag wins the pointer gesture it also owns its delayed
|
|
5693
|
+
// interpretation. An element may declare both on-hold and on-drag;
|
|
5694
|
+
// leaving the down-armed timer live would dispatch the hold Msg in
|
|
5695
|
+
// the middle of a stationary drag and then dispatch drag end too.
|
|
5696
|
+
if (drag_event.drag.phase == .change) self.disarmHold(runtime);
|
|
5697
|
+
const tree = self.treeForViewLabel(drag_event.view_label);
|
|
5698
|
+
const live_template = if (tree) |value| value.msgFor(source.id, .drag) else null;
|
|
5699
|
+
const layout: ?canvas.WidgetLayoutTree = runtime.canvasWidgetLayout(drag_event.window_id, drag_event.view_label) catch null;
|
|
5700
|
+
const live_view_size: ?geometry.SizeF = if (layout) |value| if (value.nodes.len > 0) blk: {
|
|
5701
|
+
const root = value.nodes[0].frame.normalized();
|
|
5702
|
+
break :blk geometry.SizeF.init(root.width, root.height);
|
|
5703
|
+
} else null else null;
|
|
5704
|
+
|
|
5705
|
+
if (drag_event.drag.phase == .change) {
|
|
5706
|
+
const template = live_template orelse return;
|
|
5707
|
+
const view_size = live_view_size orelse return;
|
|
5708
|
+
const msg = Ui.Tree.msgForDragTemplate(template, drag_event.drag, view_size) orelse return;
|
|
5709
|
+
// Capture before dispatch: this very Msg may rebuild the tree
|
|
5710
|
+
// without its source or handler.
|
|
5711
|
+
try self.captureWidgetDragMsg(drag_event, template, view_size);
|
|
5712
|
+
try self.dispatch(runtime, drag_event.window_id, msg);
|
|
5713
|
+
return;
|
|
5714
|
+
}
|
|
5715
|
+
|
|
5716
|
+
const captured = self.widgetDragCaptureMatches(drag_event.window_id, drag_event.view_label, source.id);
|
|
5717
|
+
const maybe_template: ?MsgT = live_template orelse if (captured) self.drag_msg_template else null;
|
|
5718
|
+
const template = maybe_template orelse {
|
|
5719
|
+
if (captured) self.clearWidgetDragMsgCapture();
|
|
5720
|
+
return;
|
|
5721
|
+
};
|
|
5722
|
+
const view_size = live_view_size orelse if (captured) self.drag_msg_view_size else return;
|
|
5723
|
+
const msg = Ui.Tree.msgForDragTemplate(template, drag_event.drag, view_size) orelse {
|
|
5724
|
+
if (captured) self.clearWidgetDragMsgCapture();
|
|
5725
|
+
return;
|
|
5726
|
+
};
|
|
5727
|
+
defer if (captured) self.clearWidgetDragMsgCapture();
|
|
5728
|
+
try self.dispatch(runtime, drag_event.window_id, msg);
|
|
5729
|
+
}
|
|
5730
|
+
|
|
5731
|
+
fn captureWidgetDragMsg(self: *Self, drag_event: core.CanvasWidgetDragEvent, template: MsgT, view_size: geometry.SizeF) anyerror!void {
|
|
5732
|
+
_ = self.drag_msg_template_arena.reset(.free_all);
|
|
5733
|
+
self.drag_msg_template = deepCopyMsgValue(MsgT, template, self.drag_msg_template_arena.allocator(), 0) catch |err| {
|
|
5734
|
+
self.drag_msg_template = null;
|
|
5735
|
+
self.drag_msg_source_id = 0;
|
|
5736
|
+
_ = self.drag_msg_template_arena.reset(.free_all);
|
|
5737
|
+
ui_app_log.warn("on-drag terminal capture failed: {t}", .{err});
|
|
5738
|
+
return err;
|
|
5739
|
+
};
|
|
5740
|
+
self.drag_msg_window_id = drag_event.window_id;
|
|
5741
|
+
const label_len = @min(drag_event.view_label.len, self.drag_msg_view_label_storage.len);
|
|
5742
|
+
@memcpy(self.drag_msg_view_label_storage[0..label_len], drag_event.view_label[0..label_len]);
|
|
5743
|
+
self.drag_msg_view_label_len = label_len;
|
|
5744
|
+
self.drag_msg_source_id = drag_event.drag.source_id;
|
|
5745
|
+
self.drag_msg_view_size = view_size;
|
|
5746
|
+
}
|
|
5747
|
+
|
|
5748
|
+
fn widgetDragCaptureMatches(self: *const Self, window_id: platform.WindowId, view_label: []const u8, source_id: canvas.ObjectId) bool {
|
|
5749
|
+
return self.drag_msg_template != null and
|
|
5750
|
+
self.drag_msg_window_id == window_id and
|
|
5751
|
+
self.drag_msg_source_id == source_id and
|
|
5752
|
+
std.mem.eql(u8, self.drag_msg_view_label_storage[0..self.drag_msg_view_label_len], view_label);
|
|
5753
|
+
}
|
|
5754
|
+
|
|
5755
|
+
fn clearWidgetDragMsgCapture(self: *Self) void {
|
|
5756
|
+
self.drag_msg_template = null;
|
|
5757
|
+
self.drag_msg_source_id = 0;
|
|
5758
|
+
self.drag_msg_view_label_len = 0;
|
|
5759
|
+
self.drag_msg_view_size = .{};
|
|
5760
|
+
_ = self.drag_msg_template_arena.reset(.free_all);
|
|
5761
|
+
}
|
|
5762
|
+
|
|
5651
5763
|
/// Slider value changes from pointer gestures (rail click, scrub
|
|
5652
5764
|
/// drag) route through the slider's `on_value`/`on_change`
|
|
5653
5765
|
/// handler. The payload is the value the runtime already applied
|