@native-sdk/cli 0.8.3 → 0.9.0
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/build/app.zig +905 -61
- package/build.zig +674 -373
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +6 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +455 -3
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/compiler_typecheck.mjs +116 -15
- package/packages/core/scripts/gen_service_surface.mjs +268 -0
- package/packages/core/scripts/npm_static_spike.mjs +64 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +77 -6
- package/packages/core/scripts/run_external_service_compiler.mjs +240 -0
- package/packages/core/scripts/stage_external_core.mjs +9 -1
- package/packages/core/scripts/stage_external_services.mjs +172 -0
- package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
- package/packages/core/scripts/vendor_service_packages.mjs +189 -0
- package/packages/core/sdk/core.d.ts +214 -2
- package/packages/core/sdk/core.ts +715 -42
- package/packages/core/sdk/events.d.ts +50 -0
- package/packages/core/sdk/events.ts +75 -0
- package/packages/core/src/checker.ts +528 -15
- package/packages/core/src/cli.ts +143 -3
- package/packages/core/src/contract.ts +26 -5
- package/packages/core/src/devhost.ts +1849 -18
- package/packages/core/src/devhost_journal.mjs +181 -0
- package/packages/core/src/devhost_resolver.mjs +17 -1
- package/packages/core/src/devhost_service_worker.mjs +90 -0
- package/packages/core/src/diagnostics.ts +84 -18
- package/packages/core/src/frontend.ts +204 -34
- package/packages/core/src/modules.ts +129 -80
- package/packages/core/src/service_contract.ts +597 -0
- package/packages/core/src/sqlite_cli.ts +93 -0
- package/packages/core/src/sqlite_codegen.ts +806 -0
- package/packages/core/src/sqlite_runtime_policy.ts +364 -0
- package/packages/core/src/typed_ast.ts +36 -8
- package/skill-data/core/SKILL.md +4 -2
- package/skill-data/core/references/project-anatomy.md +3 -2
- package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
- package/skill-data/native-ui/SKILL.md +55 -8
- package/skill-data/ts-core/SKILL.md +92 -40
- package/skill-data/ts-services/SKILL.md +126 -0
- package/skill-data/ts-services/references/service-surface.md +603 -0
- package/skill-data/zig/SKILL.md +1 -1
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/no_migrations.zig +3 -0
- package/src/app_runner/no_services.zig +20 -0
- package/src/app_runner/root.zig +104 -4
- package/src/app_runner/ts_core_main.zig +268 -4
- package/src/automation/snapshot.zig +23 -5
- package/src/embed/app_exports.zig +11 -1
- package/src/embed/c_api.zig +48 -2
- package/src/embed/conversions.zig +4 -5
- package/src/embed/host.zig +115 -1
- package/src/embed/root.zig +7 -0
- package/src/embed/tests.zig +213 -0
- package/src/embed/types.zig +51 -0
- package/src/embed/ui_host.zig +121 -5
- package/src/platform/android/NativeSdkActivity.java +131 -0
- package/src/platform/android/android_host.c +182 -1
- package/src/platform/android/native_sdk_app.h +17 -0
- package/src/platform/ios/native_sdk_app.h +17 -0
- package/src/platform/ios/uikit_host.m +115 -0
- package/src/platform/linux/cef_host.cpp +1 -1
- package/src/platform/linux/gtk_host.c +89 -17
- package/src/platform/linux/gtk_host.h +3 -0
- package/src/platform/linux/root.zig +41 -18
- package/src/platform/macos/appkit_host.h +26 -3
- package/src/platform/macos/appkit_host.m +1051 -129
- package/src/platform/macos/capture_info_plist.c +25 -0
- package/src/platform/macos/cef_host.mm +270 -36
- package/src/platform/macos/root.zig +312 -34
- package/src/platform/null_platform.zig +281 -19
- package/src/platform/null_platform_tests.zig +74 -0
- package/src/platform/root.zig +16 -0
- package/src/platform/types.zig +279 -15
- package/src/platform/windows/root.zig +243 -21
- package/src/platform/windows/webview2_host.cpp +464 -46
- package/src/primitives/app_manifest/comptime_scene.zig +2 -0
- package/src/primitives/app_manifest/root.zig +4 -0
- package/src/primitives/app_manifest/tests.zig +3 -0
- package/src/primitives/app_manifest/types.zig +34 -0
- package/src/primitives/app_manifest/validation.zig +19 -1
- package/src/primitives/canvas/code_tests.zig +9 -9
- package/src/primitives/canvas/events.zig +12 -11
- package/src/primitives/canvas/frame.zig +44 -9
- package/src/primitives/canvas/icons/mic.svg +1 -0
- package/src/primitives/canvas/icons.zig +2 -0
- package/src/primitives/canvas/root.zig +8 -0
- package/src/primitives/canvas/text_span_tests.zig +39 -0
- package/src/primitives/canvas/ui.zig +23 -4
- package/src/primitives/canvas/ui_markup.zig +15 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
- package/src/primitives/canvas/ui_markup_tests.zig +5 -0
- package/src/primitives/canvas/ui_markup_view.zig +9 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
- package/src/primitives/canvas/ui_schema.zig +19 -10
- package/src/primitives/canvas/ui_schema_tests.zig +5 -3
- package/src/primitives/canvas/ui_tests.zig +18 -4
- package/src/primitives/canvas/widget_invalidation.zig +9 -2
- package/src/primitives/canvas/widget_render.zig +296 -114
- package/src/primitives/canvas/widget_runtime_tests.zig +133 -0
- package/src/primitives/canvas/widget_text_input.zig +10 -10
- package/src/primitives/canvas/widget_tree.zig +1 -1
- package/src/primitives/canvas/widgets.zig +29 -5
- package/src/root.zig +56 -0
- package/src/runtime/api.zig +11 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/automation_widget_dispatch.zig +1 -0
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/bridge_permission_tests.zig +23 -2
- package/src/runtime/bridge_responses.zig +3 -1
- package/src/runtime/canvas_frame.zig +31 -13
- package/src/runtime/canvas_frame_animation_tests.zig +4 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
- package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
- package/src/runtime/canvas_widget_events.zig +69 -24
- package/src/runtime/canvas_widget_runtime.zig +101 -6
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
- package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
- package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
- package/src/runtime/canvas_widget_state.zig +6 -1
- package/src/runtime/canvas_widget_text_tests.zig +112 -3
- package/src/runtime/clock.zig +13 -1
- package/src/runtime/core.zig +133 -1
- package/src/runtime/credentials_store.zig +115 -0
- package/src/runtime/effects.zig +2568 -75
- package/src/runtime/effects_audio_capture_tests.zig +251 -0
- package/src/runtime/effects_credentials_tests.zig +332 -0
- package/src/runtime/effects_host_tests.zig +208 -1
- package/src/runtime/effects_relational_tests.zig +314 -0
- package/src/runtime/effects_store_tests.zig +211 -0
- package/src/runtime/flow.zig +14 -1
- package/src/runtime/gpu_surface_events.zig +6 -1
- package/src/runtime/native_command_event_tests.zig +42 -0
- package/src/runtime/persist_store.zig +666 -0
- package/src/runtime/record_store.zig +788 -0
- package/src/runtime/relational_store.zig +854 -0
- package/src/runtime/root.zig +52 -0
- package/src/runtime/runtime_event_tests.zig +70 -0
- package/src/runtime/service_host.zig +711 -0
- package/src/runtime/service_pool.zig +1314 -0
- package/src/runtime/session_blobs.zig +1 -1
- package/src/runtime/session_journal.zig +102 -0
- package/src/runtime/session_record.zig +177 -0
- package/src/runtime/session_replay.zig +109 -4
- package/src/runtime/shell_layout.zig +1 -0
- package/src/runtime/shell_layout_tests.zig +120 -0
- package/src/runtime/sqlite_engine.zig +474 -0
- package/src/runtime/state.zig +6 -0
- package/src/runtime/system_services.zig +49 -10
- package/src/runtime/tests.zig +5 -0
- package/src/runtime/ts_core_host.zig +1189 -118
- package/src/runtime/ts_core_host_tests.zig +638 -11
- package/src/runtime/ts_ui_app.zig +537 -1
- package/src/runtime/ui_app.zig +160 -19
- package/src/runtime/ui_app_tests.zig +203 -5
- package/src/runtime/validation.zig +22 -0
- package/src/runtime/view.zig +11 -0
- package/src/runtime/view_widget_scroll.zig +56 -5
- package/src/runtime/view_widget_text.zig +24 -5
- package/src/runtime/view_widget_tree.zig +1 -1
- package/src/runtime/window_storage.zig +1 -0
- package/src/runtime/window_view_runtime.zig +2 -3
- package/src/runtime/window_views.zig +19 -0
- package/src/tooling/android.zig +21 -16
- package/src/tooling/db.zig +160 -0
- package/src/tooling/ios.zig +7 -1
- package/src/tooling/manifest.zig +1248 -2
- package/src/tooling/package.zig +953 -6
- package/src/tooling/raw_manifest.zig +65 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +216 -4
- package/src/tooling/ts_core.zig +283 -17
- package/src/tooling/verbs.zig +7 -0
- package/third_party/sqlite/README.md +13 -0
- package/third_party/sqlite/sqlite3.c +269649 -0
- package/third_party/sqlite/sqlite3.h +14349 -0
- package/tools/corewire/core_abi.zig +14 -2
- package/tools/corewire/emit.zig +98 -29
- package/tools/corewire/emit_facade.zig +414 -23
- package/tools/corewire/emit_profile.zig +6 -2
- package/tools/corewire/emit_service.zig +924 -0
- package/tools/corewire/main.zig +122 -0
- package/tools/corewire/service_contract.zig +250 -0
- package/tools/corewire/sidecar.zig +26 -15
|
@@ -85,6 +85,8 @@ fn shellWindowFrom(comptime window: anytype) types.ShellWindow {
|
|
|
85
85
|
if (@hasField(@TypeOf(window), "always_on_top")) out.always_on_top = window.always_on_top;
|
|
86
86
|
if (@hasField(@TypeOf(window), "click_through")) out.click_through = window.click_through;
|
|
87
87
|
if (@hasField(@TypeOf(window), "activate_on_show")) out.activate_on_show = window.activate_on_show;
|
|
88
|
+
if (@hasField(@TypeOf(window), "initially_hidden")) out.initially_hidden = window.initially_hidden;
|
|
89
|
+
if (@hasField(@TypeOf(window), "allows_fullscreen")) out.allows_fullscreen = window.allows_fullscreen;
|
|
88
90
|
if (@hasField(@TypeOf(window), "min_width")) out.min_width = window.min_width;
|
|
89
91
|
if (@hasField(@TypeOf(window), "min_height")) out.min_height = window.min_height;
|
|
90
92
|
if (@hasField(@TypeOf(window), "close_policy")) {
|
|
@@ -9,6 +9,7 @@ pub const web_layer = @import("web_layer.zig");
|
|
|
9
9
|
pub const ValidationError = types.ValidationError;
|
|
10
10
|
pub const max_shortcuts = types.max_shortcuts;
|
|
11
11
|
pub const max_shortcut_id_bytes = types.max_shortcut_id_bytes;
|
|
12
|
+
pub const max_app_id_bytes = types.max_app_id_bytes;
|
|
12
13
|
pub const max_shortcut_key_bytes = types.max_shortcut_key_bytes;
|
|
13
14
|
pub const max_shell_windows = types.max_shell_windows;
|
|
14
15
|
pub const max_shell_views_per_window = types.max_shell_views_per_window;
|
|
@@ -38,6 +39,8 @@ pub const PermissionKind = types.PermissionKind;
|
|
|
38
39
|
pub const Permission = types.Permission;
|
|
39
40
|
pub const CapabilityKind = types.CapabilityKind;
|
|
40
41
|
pub const Capability = types.Capability;
|
|
42
|
+
pub const PersistRestore = types.PersistRestore;
|
|
43
|
+
pub const PersistConfig = types.PersistConfig;
|
|
41
44
|
pub const AppIdentity = types.AppIdentity;
|
|
42
45
|
pub const Version = types.Version;
|
|
43
46
|
pub const Icon = types.Icon;
|
|
@@ -102,6 +105,7 @@ pub const validateUrl = validation.validateUrl;
|
|
|
102
105
|
pub const validateIcons = validation.validateIcons;
|
|
103
106
|
pub const validatePermissions = validation.validatePermissions;
|
|
104
107
|
pub const validateCapabilities = validation.validateCapabilities;
|
|
108
|
+
pub const validatePersist = validation.validatePersist;
|
|
105
109
|
pub const validateBridge = validation.validateBridge;
|
|
106
110
|
pub const validateFrontend = validation.validateFrontend;
|
|
107
111
|
pub const validateBridgeOrigin = validation.validateBridgeOrigin;
|
|
@@ -617,7 +617,10 @@ test "app id validation" {
|
|
|
617
617
|
try validateAppId("com.example.app", .reverse_dns);
|
|
618
618
|
try validateAppId("my-tool", .simple);
|
|
619
619
|
|
|
620
|
+
const oversized_id = [_]u8{'a'} ** (types.max_app_id_bytes + 1);
|
|
621
|
+
|
|
620
622
|
try std.testing.expectError(error.InvalidId, validateAppId("", .reverse_dns));
|
|
623
|
+
try std.testing.expectError(error.InvalidId, validateAppId(&oversized_id, .simple));
|
|
621
624
|
try std.testing.expectError(error.InvalidId, validateAppId("example", .reverse_dns));
|
|
622
625
|
try std.testing.expectError(error.InvalidId, validateAppId("Com.example.app", .reverse_dns));
|
|
623
626
|
try std.testing.expectError(error.InvalidId, validateAppId("com/example/app", .reverse_dns));
|
|
@@ -32,6 +32,9 @@ pub const ValidationError = error{
|
|
|
32
32
|
|
|
33
33
|
pub const max_shortcuts: usize = 64;
|
|
34
34
|
pub const max_shortcut_id_bytes: usize = 64;
|
|
35
|
+
/// App identities double as the credential-manager service namespace, whose
|
|
36
|
+
/// cross-platform ABI is bounded to this size.
|
|
37
|
+
pub const max_app_id_bytes: usize = 128;
|
|
35
38
|
pub const max_shortcut_key_bytes: usize = 32;
|
|
36
39
|
pub const max_shell_windows: usize = 16;
|
|
37
40
|
pub const max_shell_views_per_window: usize = 128;
|
|
@@ -113,6 +116,7 @@ pub const PermissionKind = enum {
|
|
|
113
116
|
filesystem,
|
|
114
117
|
camera,
|
|
115
118
|
microphone,
|
|
119
|
+
system_audio,
|
|
116
120
|
location,
|
|
117
121
|
notifications,
|
|
118
122
|
clipboard,
|
|
@@ -129,6 +133,7 @@ pub const Permission = union(PermissionKind) {
|
|
|
129
133
|
filesystem: void,
|
|
130
134
|
camera: void,
|
|
131
135
|
microphone: void,
|
|
136
|
+
system_audio: void,
|
|
132
137
|
location: void,
|
|
133
138
|
notifications: void,
|
|
134
139
|
clipboard: void,
|
|
@@ -159,6 +164,9 @@ pub const CapabilityKind = enum {
|
|
|
159
164
|
dialog,
|
|
160
165
|
clipboard,
|
|
161
166
|
credentials,
|
|
167
|
+
persist,
|
|
168
|
+
store,
|
|
169
|
+
sqlite,
|
|
162
170
|
open_url,
|
|
163
171
|
reveal_path,
|
|
164
172
|
recent_documents,
|
|
@@ -184,6 +192,9 @@ pub const Capability = union(CapabilityKind) {
|
|
|
184
192
|
dialog: void,
|
|
185
193
|
clipboard: void,
|
|
186
194
|
credentials: void,
|
|
195
|
+
persist: void,
|
|
196
|
+
store: void,
|
|
197
|
+
sqlite: void,
|
|
187
198
|
open_url: void,
|
|
188
199
|
reveal_path: void,
|
|
189
200
|
recent_documents: void,
|
|
@@ -361,6 +372,8 @@ pub const Window = struct {
|
|
|
361
372
|
/// Show without activating the app or taking keyboard focus when
|
|
362
373
|
/// false. An explicit focus action can still activate the window.
|
|
363
374
|
activate_on_show: bool = true,
|
|
375
|
+
initially_hidden: bool = false,
|
|
376
|
+
allows_fullscreen: bool = true,
|
|
364
377
|
/// Content min-size floor the window itself enforces (macOS
|
|
365
378
|
/// `contentMinSize`): the resize stops at the floor instead of the
|
|
366
379
|
/// layout clamping/clipping panes below it. 0 = no floor.
|
|
@@ -494,6 +507,14 @@ pub const ShellWindow = struct {
|
|
|
494
507
|
always_on_top: bool = false,
|
|
495
508
|
click_through: bool = false,
|
|
496
509
|
activate_on_show: bool = true,
|
|
510
|
+
/// Create the native window ordered out and keep it hidden until an
|
|
511
|
+
/// explicit show/focus request. Intended for retained menu-bar app
|
|
512
|
+
/// host windows that must never flash during launch.
|
|
513
|
+
initially_hidden: bool = false,
|
|
514
|
+
/// Whether macOS exposes native fullscreen for this window. False
|
|
515
|
+
/// keeps ordinary resizing but disables the green fullscreen button
|
|
516
|
+
/// and the fullscreen command.
|
|
517
|
+
allows_fullscreen: bool = true,
|
|
497
518
|
/// Content min-size floor the window itself enforces (macOS
|
|
498
519
|
/// `contentMinSize`): the resize stops at the floor instead of the
|
|
499
520
|
/// layout clamping/clipping panes below it. 0 = no floor. Like
|
|
@@ -625,12 +646,25 @@ pub const UpdateConfig = struct {
|
|
|
625
646
|
check_on_start: bool = false,
|
|
626
647
|
};
|
|
627
648
|
|
|
649
|
+
pub const PersistRestore = struct {
|
|
650
|
+
ok: []const u8,
|
|
651
|
+
none: []const u8,
|
|
652
|
+
err: []const u8,
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
pub const PersistConfig = struct {
|
|
656
|
+
version: u64,
|
|
657
|
+
debounce_ms: u32 = 500,
|
|
658
|
+
restore: PersistRestore,
|
|
659
|
+
};
|
|
660
|
+
|
|
628
661
|
pub const Manifest = struct {
|
|
629
662
|
identity: AppIdentity,
|
|
630
663
|
version: Version,
|
|
631
664
|
icons: []const Icon = &.{},
|
|
632
665
|
permissions: []const Permission = &.{},
|
|
633
666
|
capabilities: []const Capability = &.{},
|
|
667
|
+
persist: ?PersistConfig = null,
|
|
634
668
|
bridge: BridgeConfig = .{},
|
|
635
669
|
frontend: ?FrontendConfig = null,
|
|
636
670
|
security: SecurityConfig = .{},
|
|
@@ -74,6 +74,7 @@ pub fn validateManifest(manifest: Manifest) ValidationError!void {
|
|
|
74
74
|
try validateIcons(manifest.icons);
|
|
75
75
|
try validatePermissions(manifest.permissions);
|
|
76
76
|
try validateCapabilities(manifest.capabilities);
|
|
77
|
+
try validatePersist(manifest.persist, manifest.capabilities);
|
|
77
78
|
try validateBridge(manifest.bridge);
|
|
78
79
|
if (manifest.frontend) |frontend| try validateFrontend(frontend);
|
|
79
80
|
try validateSecurity(manifest.security);
|
|
@@ -403,7 +404,7 @@ pub const AppIdMode = enum {
|
|
|
403
404
|
};
|
|
404
405
|
|
|
405
406
|
pub fn validateAppId(id: []const u8, mode: AppIdMode) ValidationError!void {
|
|
406
|
-
if (id.len == 0) return error.InvalidId;
|
|
407
|
+
if (id.len == 0 or id.len > types.max_app_id_bytes) return error.InvalidId;
|
|
407
408
|
if (id[0] == '.' or id[id.len - 1] == '.') return error.InvalidId;
|
|
408
409
|
|
|
409
410
|
var segments: usize = 0;
|
|
@@ -543,6 +544,23 @@ pub fn validateCapabilities(capabilities: []const Capability) ValidationError!vo
|
|
|
543
544
|
}
|
|
544
545
|
}
|
|
545
546
|
|
|
547
|
+
pub fn validatePersist(config: ?types.PersistConfig, capabilities: []const Capability) ValidationError!void {
|
|
548
|
+
var declared = false;
|
|
549
|
+
for (capabilities) |capability| {
|
|
550
|
+
if (capability == .persist) declared = true;
|
|
551
|
+
}
|
|
552
|
+
if (declared != (config != null)) return error.MissingRequiredField;
|
|
553
|
+
const persist = config orelse return;
|
|
554
|
+
if (persist.version == 0 or persist.version > 9_007_199_254_740_991) return error.InvalidVersion;
|
|
555
|
+
if (persist.debounce_ms > 60_000) return error.InvalidTimeout;
|
|
556
|
+
try validateName(persist.restore.ok);
|
|
557
|
+
try validateName(persist.restore.none);
|
|
558
|
+
try validateName(persist.restore.err);
|
|
559
|
+
if (std.mem.eql(u8, persist.restore.ok, persist.restore.none) or
|
|
560
|
+
std.mem.eql(u8, persist.restore.ok, persist.restore.err) or
|
|
561
|
+
std.mem.eql(u8, persist.restore.none, persist.restore.err)) return error.InvalidName;
|
|
562
|
+
}
|
|
563
|
+
|
|
546
564
|
pub fn validateBridge(bridge: BridgeConfig) ValidationError!void {
|
|
547
565
|
for (bridge.commands, 0..) |command, i| {
|
|
548
566
|
try validateName(command.name);
|
|
@@ -147,7 +147,7 @@ fn allTextSpansHaveColor(widget: canvas.Widget, color: canvas.TextSpanColor) boo
|
|
|
147
147
|
fn expectCodeTabInsertion(source: []const u8, expected: []const u8) !void {
|
|
148
148
|
const edit = canvas.widgetCodeTabTextEditEvent(.{
|
|
149
149
|
.kind = .textarea,
|
|
150
|
-
.code_editor = true,
|
|
150
|
+
.runtime_flags = .{ .code_editor = true },
|
|
151
151
|
.text = source,
|
|
152
152
|
}, .{
|
|
153
153
|
.phase = .key_down,
|
|
@@ -958,7 +958,7 @@ test "line number gutter reserves at least three marker columns" {
|
|
|
958
958
|
const tokens = canvas.DesignTokens{};
|
|
959
959
|
var numbered = canvas.Widget{
|
|
960
960
|
.kind = .textarea,
|
|
961
|
-
.code_editor = true,
|
|
961
|
+
.runtime_flags = .{ .code_editor = true },
|
|
962
962
|
.code_line_number_digits = 1,
|
|
963
963
|
};
|
|
964
964
|
const one_digit_width = widget_metrics.widgetCodeLineNumberGutterWidth(numbered, tokens);
|
|
@@ -1259,7 +1259,7 @@ test "numbered editable code does not invent trailing horizontal overflow" {
|
|
|
1259
1259
|
const tokens = canvas.DesignTokens{};
|
|
1260
1260
|
var editor = canvas.Widget{
|
|
1261
1261
|
.kind = .textarea,
|
|
1262
|
-
.code_editor = true,
|
|
1262
|
+
.runtime_flags = .{ .code_editor = true },
|
|
1263
1263
|
.code_line_number_digits = 2,
|
|
1264
1264
|
.text_no_wrap = true,
|
|
1265
1265
|
.text = source,
|
|
@@ -1301,7 +1301,7 @@ test "editable code caches one batched longest-line measurement across geometry
|
|
|
1301
1301
|
const tokens = canvas.DesignTokens{ .text_measure = &provider };
|
|
1302
1302
|
var editor = canvas.Widget{
|
|
1303
1303
|
.kind = .textarea,
|
|
1304
|
-
.code_editor = true,
|
|
1304
|
+
.runtime_flags = .{ .code_editor = true },
|
|
1305
1305
|
.text_no_wrap = true,
|
|
1306
1306
|
.text = source.items,
|
|
1307
1307
|
.frame = geometry.RectF.init(0, 0, 240, 80),
|
|
@@ -1445,7 +1445,7 @@ test "editable code Tab infers the file indentation and falls back to two spaces
|
|
|
1445
1445
|
}) == null);
|
|
1446
1446
|
try testing.expect(canvas.widgetCodeTabTextEditEvent(.{
|
|
1447
1447
|
.kind = .textarea,
|
|
1448
|
-
.code_editor = true,
|
|
1448
|
+
.runtime_flags = .{ .code_editor = true },
|
|
1449
1449
|
.text = "code",
|
|
1450
1450
|
}, .{
|
|
1451
1451
|
.phase = .key_down,
|
|
@@ -1454,7 +1454,7 @@ test "editable code Tab infers the file indentation and falls back to two spaces
|
|
|
1454
1454
|
}) == null);
|
|
1455
1455
|
try testing.expect(canvas.widgetCodeTabTextEditEvent(.{
|
|
1456
1456
|
.kind = .textarea,
|
|
1457
|
-
.code_editor = true,
|
|
1457
|
+
.runtime_flags = .{ .code_editor = true },
|
|
1458
1458
|
.text = "code",
|
|
1459
1459
|
}, .{
|
|
1460
1460
|
.phase = .key_down,
|
|
@@ -1642,7 +1642,7 @@ test "direct tree code emission honors scroll viewports and later layout pages"
|
|
|
1642
1642
|
.id = 1,
|
|
1643
1643
|
.kind = .scroll_view,
|
|
1644
1644
|
.frame = geometry.RectF.init(0, 0, 320, 80),
|
|
1645
|
-
.native_scroll = true,
|
|
1645
|
+
.runtime_flags = .{ .native_scroll = true },
|
|
1646
1646
|
.children = &horizontal_children,
|
|
1647
1647
|
};
|
|
1648
1648
|
var horizontal_commands: [64]canvas.CanvasCommand = undefined;
|
|
@@ -1669,7 +1669,7 @@ test "direct tree code emission honors scroll viewports and later layout pages"
|
|
|
1669
1669
|
.id = 3,
|
|
1670
1670
|
.kind = .scroll_view,
|
|
1671
1671
|
.frame = geometry.RectF.init(0, 0, 100, 100),
|
|
1672
|
-
.native_scroll = true,
|
|
1672
|
+
.runtime_flags = .{ .native_scroll = true },
|
|
1673
1673
|
.children = &vertical_children,
|
|
1674
1674
|
};
|
|
1675
1675
|
var vertical_commands: [64]canvas.CanvasCommand = undefined;
|
|
@@ -1709,7 +1709,7 @@ test "editable code highlights the visible tail of a ten-thousand-line source" {
|
|
|
1709
1709
|
.height = 100,
|
|
1710
1710
|
}, source.items));
|
|
1711
1711
|
var editor = findByText(view.root, source.items).?;
|
|
1712
|
-
try testing.expect(editor.code_editor);
|
|
1712
|
+
try testing.expect(editor.runtime_flags.code_editor);
|
|
1713
1713
|
try testing.expectEqual(code_model.Language.css, editor.code_language);
|
|
1714
1714
|
try testing.expectEqual(@as(usize, 1), editor.spans.len);
|
|
1715
1715
|
try testing.expectEqual(@as(u8, 5), editor.code_line_number_digits);
|
|
@@ -118,19 +118,20 @@ pub const WidgetKeyboardEvent = struct {
|
|
|
118
118
|
}
|
|
119
119
|
};
|
|
120
120
|
|
|
121
|
-
/// Enter in a multi-line editor EDITS instead of submitting
|
|
122
|
-
///
|
|
123
|
-
///
|
|
124
|
-
/// primary-modifier chord (cmd/ctrl+Enter) is deliberately
|
|
125
|
-
///
|
|
126
|
-
/// app shortcuts. Single-line kinds return null here and
|
|
127
|
-
/// enter-to-submit. Shared by the runtime edit path and the app
|
|
128
|
-
/// dispatch so
|
|
129
|
-
pub fn widgetKeyboardNewlineTextEditEvent(
|
|
130
|
-
if (kind != .textarea) return null;
|
|
121
|
+
/// Enter in a multi-line editor normally EDITS instead of submitting.
|
|
122
|
+
/// A textarea with `submit_on_enter` reverses only the plain gesture:
|
|
123
|
+
/// Enter is left for its submit handler while Shift+Enter stays a
|
|
124
|
+
/// newline. The primary-modifier chord (cmd/ctrl+Enter) is deliberately
|
|
125
|
+
/// excluded — it is always a textarea submit chord — as is alt+Enter,
|
|
126
|
+
/// left free for app shortcuts. Single-line kinds return null here and
|
|
127
|
+
/// keep enter-to-submit. Shared by the runtime edit path and the app
|
|
128
|
+
/// `on_input` dispatch so retained text and the model hear the same edit.
|
|
129
|
+
pub fn widgetKeyboardNewlineTextEditEvent(widget: Widget, event: WidgetKeyboardEvent) ?TextInputEvent {
|
|
130
|
+
if (widget.kind != .textarea) return null;
|
|
131
131
|
if (event.phase != .key_down or event.text.len != 0) return null;
|
|
132
132
|
if (event.modifiers.control or event.modifiers.alt or event.modifiers.super) return null;
|
|
133
133
|
if (!std.ascii.eqlIgnoreCase(event.key, "enter") and !std.ascii.eqlIgnoreCase(event.key, "return")) return null;
|
|
134
|
+
if (widget.submit_on_enter and !event.modifiers.shift) return null;
|
|
134
135
|
return .{ .insert_text = "\n" };
|
|
135
136
|
}
|
|
136
137
|
|
|
@@ -140,7 +141,7 @@ pub fn widgetKeyboardNewlineTextEditEvent(kind: WidgetKind, event: WidgetKeyboar
|
|
|
140
141
|
/// wider width winning exact ties (4-space files also divide by 2).
|
|
141
142
|
/// Ambiguous or unindented source falls back to two spaces.
|
|
142
143
|
pub fn widgetCodeTabTextEditEvent(widget: Widget, event: WidgetKeyboardEvent) ?TextInputEvent {
|
|
143
|
-
if (widget.kind != .textarea or !widget.code_editor or widget.state.disabled) return null;
|
|
144
|
+
if (widget.kind != .textarea or !widget.runtime_flags.code_editor or widget.state.disabled) return null;
|
|
144
145
|
if (event.phase != .key_down or event.focus_moved or event.text.len != 0) return null;
|
|
145
146
|
if (event.modifiers.shift or event.modifiers.hasNavigationModifier()) return null;
|
|
146
147
|
if (!std.ascii.eqlIgnoreCase(event.key, "tab")) return null;
|
|
@@ -457,6 +457,11 @@ pub const CanvasFrameOptions = struct {
|
|
|
457
457
|
timestamp_ns: u64 = 0,
|
|
458
458
|
surface_size: geometry.SizeF = .{},
|
|
459
459
|
scale: f32 = 1,
|
|
460
|
+
/// Renderer-specific read support relative to `Blur.radius`. The
|
|
461
|
+
/// reference and Windows renderers consume one radius; AppKit's
|
|
462
|
+
/// three-box Gaussian consumes at most three. Runtime-owned frame
|
|
463
|
+
/// planning sets this from the active platform.
|
|
464
|
+
backdrop_blur_sample_extent_multiplier: f32 = 1,
|
|
460
465
|
full_repaint: bool = false,
|
|
461
466
|
budget: CanvasFrameBudget = .{},
|
|
462
467
|
previous_pipeline_cache: []const RenderPipelineCacheEntry = &.{},
|
|
@@ -615,7 +620,11 @@ pub fn buildCanvasFrame(previous: ?DisplayList, next: DisplayList, options: Canv
|
|
|
615
620
|
// pixels so a fractional dirty edge cannot erase an unchanged
|
|
616
621
|
// neighbor's boundary-pixel coverage without redrawing it.
|
|
617
622
|
dirty_bounds = bleedAlignedDirtyBounds(unionOptionalBounds(dirtyBoundsFromChanges(changes), render_override_dirty_bounds), options.scale, 1, options.surface_size);
|
|
618
|
-
if (
|
|
623
|
+
if (incrementalDamageIntersectsBackdropBlurWithSampleExtent(
|
|
624
|
+
render_plan.commands,
|
|
625
|
+
dirty_bounds,
|
|
626
|
+
options.backdrop_blur_sample_extent_multiplier,
|
|
627
|
+
)) {
|
|
619
628
|
// A backdrop blur reads pixels around its output from the
|
|
620
629
|
// destination as it existed at this point in draw order.
|
|
621
630
|
// Retained pixels outside an incremental scissor already
|
|
@@ -666,8 +675,23 @@ pub fn buildCanvasFrame(previous: ?DisplayList, next: DisplayList, options: Canv
|
|
|
666
675
|
/// outside the scissor hold the previous fully composited frame rather
|
|
667
676
|
/// than the backdrop at the blur command's position in draw order.
|
|
668
677
|
pub fn incrementalDamageIntersectsBackdropBlur(commands: []const RenderCommand, dirty_bounds: ?geometry.RectF) bool {
|
|
678
|
+
return incrementalDamageIntersectsBackdropBlurWithSampleExtent(commands, dirty_bounds, 1);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/// Backend-aware form of `incrementalDamageIntersectsBackdropBlur`. Values
|
|
682
|
+
/// below one are normalized to the shared one-radius floor; wider renderers
|
|
683
|
+
/// pass their conservative maximum sampling support.
|
|
684
|
+
pub fn incrementalDamageIntersectsBackdropBlurWithSampleExtent(
|
|
685
|
+
commands: []const RenderCommand,
|
|
686
|
+
dirty_bounds: ?geometry.RectF,
|
|
687
|
+
requested_sample_extent_multiplier: f32,
|
|
688
|
+
) bool {
|
|
669
689
|
const dirty = dirty_bounds orelse return false;
|
|
670
690
|
const normalized_dirty = dirty.normalized();
|
|
691
|
+
const sample_extent_multiplier = if (std.math.isFinite(requested_sample_extent_multiplier))
|
|
692
|
+
@max(1, requested_sample_extent_multiplier)
|
|
693
|
+
else
|
|
694
|
+
1;
|
|
671
695
|
for (commands) |command| {
|
|
672
696
|
switch (command.command) {
|
|
673
697
|
.blur => |blur| {
|
|
@@ -677,14 +701,25 @@ pub fn incrementalDamageIntersectsBackdropBlur(commands: []const RenderCommand,
|
|
|
677
701
|
if (output.isEmpty()) continue;
|
|
678
702
|
|
|
679
703
|
// Do not use `command.bounds` here: the render planner
|
|
680
|
-
// intersects that inflated bound with the output
|
|
681
|
-
// while a clipped output pixel still samples backdrop
|
|
682
|
-
//
|
|
683
|
-
//
|
|
684
|
-
//
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
704
|
+
// intersects that radius-inflated bound with the output
|
|
705
|
+
// clip, while a clipped output pixel still samples backdrop
|
|
706
|
+
// outside the clip. Preserve the established local-radius
|
|
707
|
+
// footprint for one-radius renderers. Wider renderers operate
|
|
708
|
+
// on the transformed output with an isotropic device-space
|
|
709
|
+
// kernel, so scale their support by the transform's largest
|
|
710
|
+
// axis before inflating that output.
|
|
711
|
+
const read_footprint = if (sample_extent_multiplier == 1)
|
|
712
|
+
command.transform.transformRect(
|
|
713
|
+
blur.rect.normalized().inflate(geometry.InsetsF.all(@max(0, blur.radius))),
|
|
714
|
+
).normalized()
|
|
715
|
+
else extended: {
|
|
716
|
+
const transform = command.transform;
|
|
717
|
+
const x_scale = @sqrt(transform.a * transform.a + transform.b * transform.b);
|
|
718
|
+
const y_scale = @sqrt(transform.c * transform.c + transform.d * transform.d);
|
|
719
|
+
const transform_scale = @max(0.0001, @max(x_scale, y_scale));
|
|
720
|
+
const sample_extent = @max(0, blur.radius) * transform_scale * sample_extent_multiplier;
|
|
721
|
+
break :extended output.normalized().inflate(geometry.InsetsF.all(sample_extent));
|
|
722
|
+
};
|
|
688
723
|
if (read_footprint.intersects(normalized_dirty)) return true;
|
|
689
724
|
},
|
|
690
725
|
else => {},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z"/><path d="M19 10v2a7 7 0 0 1-14 0v-2"/><line x1="12" y1="19" x2="12" y2="22"/><line x1="8" y1="22" x2="16" y2="22"/></svg>
|
|
@@ -67,6 +67,7 @@ const git_merge = builtin("git-merge");
|
|
|
67
67
|
const git_pull_request = builtin("git-pull-request");
|
|
68
68
|
const info = builtin("info");
|
|
69
69
|
const menu = builtin("menu");
|
|
70
|
+
const mic = builtin("mic");
|
|
70
71
|
const moon = builtin("moon");
|
|
71
72
|
const music = builtin("music");
|
|
72
73
|
const panel_left = builtin("panel-left");
|
|
@@ -121,6 +122,7 @@ pub const entries = [_]Entry{
|
|
|
121
122
|
.{ .name = "git-pull-request", .icon = &git_pull_request },
|
|
122
123
|
.{ .name = "info", .icon = &info },
|
|
123
124
|
.{ .name = "menu", .icon = &menu },
|
|
125
|
+
.{ .name = "mic", .icon = &mic },
|
|
124
126
|
.{ .name = "moon", .icon = &moon },
|
|
125
127
|
.{ .name = "music", .icon = &music },
|
|
126
128
|
.{ .name = "panel-left", .icon = &panel_left },
|
|
@@ -299,6 +299,7 @@ pub const CanvasFrame = frame_model.CanvasFrame;
|
|
|
299
299
|
pub const max_canvas_frame_dirty_rects = frame_model.max_canvas_frame_dirty_rects;
|
|
300
300
|
pub const buildCanvasFrame = frame_model.buildCanvasFrame;
|
|
301
301
|
pub const incrementalDamageIntersectsBackdropBlur = frame_model.incrementalDamageIntersectsBackdropBlur;
|
|
302
|
+
pub const incrementalDamageIntersectsBackdropBlurWithSampleExtent = frame_model.incrementalDamageIntersectsBackdropBlurWithSampleExtent;
|
|
302
303
|
|
|
303
304
|
// Canvas GPU packet and encoder data live in `gpu.zig`; root keeps the public API stable.
|
|
304
305
|
pub const CanvasRenderPassLoadAction = gpu_model.CanvasRenderPassLoadAction;
|
|
@@ -425,6 +426,7 @@ pub const DesignTokens = token_model.DesignTokens;
|
|
|
425
426
|
pub const WidgetKind = widget_model.WidgetKind;
|
|
426
427
|
pub const WidgetCursor = widget_model.WidgetCursor;
|
|
427
428
|
pub const WidgetState = widget_model.WidgetState;
|
|
429
|
+
pub const WidgetRuntimeFlags = widget_model.WidgetRuntimeFlags;
|
|
428
430
|
pub const WidgetLayoutMotion = widget_model.WidgetLayoutMotion;
|
|
429
431
|
pub const WidgetRenderState = widget_model.WidgetRenderState;
|
|
430
432
|
pub const WidgetMainAlignment = widget_model.WidgetMainAlignment;
|
|
@@ -740,6 +742,12 @@ pub const cursorForWidgetTarget = widget_runtime.cursorForWidgetTarget;
|
|
|
740
742
|
/// widget-level predicate is `widgetIsHitTarget`, which also admits any
|
|
741
743
|
/// widget carrying a bound press/toggle handler.
|
|
742
744
|
pub const widgetKindHitTarget = @import("widget_access.zig").widgetKindHitTarget;
|
|
745
|
+
/// Widget-level keyboard focusability without geometry/ancestor-clip
|
|
746
|
+
/// filtering. Runtime roving-focus groups use this to identify a logical
|
|
747
|
+
/// offscreen successor before scrolling it into view; ordinary focus
|
|
748
|
+
/// traversal still goes through `WidgetLayoutTree.focusTarget*`, which
|
|
749
|
+
/// rejects clipped targets.
|
|
750
|
+
pub const widgetIsFocusable = @import("widget_access.zig").isFocusable;
|
|
743
751
|
/// Widget-level hit-target-ness: kind-level `widgetKindHitTarget` plus
|
|
744
752
|
/// any widget with a bound press/toggle handler (stamped into
|
|
745
753
|
/// `semantics.actions` by the builder and both markup engines).
|
|
@@ -247,6 +247,45 @@ test "a later visual-line page retains an over-capacity wrapped paragraph" {
|
|
|
247
247
|
try testing.expect(!later.truncated);
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
+
test "ordinary span paragraphs paint a visible page after the line cap" {
|
|
251
|
+
const source = ("x\n" ** 139) ++ "TAIL_SENTINEL";
|
|
252
|
+
const spans = [_]TextSpan{.{ .text = source }};
|
|
253
|
+
const tokens = canvas.DesignTokens{};
|
|
254
|
+
const line_height = tokens.typography.body_size * 1.25;
|
|
255
|
+
const children = [_]canvas.Widget{.{
|
|
256
|
+
.id = 2,
|
|
257
|
+
.kind = .text,
|
|
258
|
+
// Put the final visual lines inside the scroll viewport while the
|
|
259
|
+
// first 128-line storage page is far above it.
|
|
260
|
+
.frame = geometry.RectF.init(0, -(139 * line_height) + 20, 100, 140 * line_height),
|
|
261
|
+
.text = source,
|
|
262
|
+
.spans = &spans,
|
|
263
|
+
}};
|
|
264
|
+
const root = canvas.Widget{
|
|
265
|
+
.id = 1,
|
|
266
|
+
.kind = .scroll_view,
|
|
267
|
+
.frame = geometry.RectF.init(0, 0, 100, 100),
|
|
268
|
+
.runtime_flags = .{ .native_scroll = true },
|
|
269
|
+
.children = &children,
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
var commands: [256]canvas.CanvasCommand = undefined;
|
|
273
|
+
var builder = canvas.Builder.init(&commands);
|
|
274
|
+
try canvas.emitWidgetTree(&builder, root, tokens);
|
|
275
|
+
|
|
276
|
+
var saw_tail = false;
|
|
277
|
+
var text_commands: usize = 0;
|
|
278
|
+
for (builder.displayList().commands) |command| {
|
|
279
|
+
if (command != .draw_text) continue;
|
|
280
|
+
text_commands += 1;
|
|
281
|
+
if (std.mem.indexOf(u8, command.draw_text.text, "TAIL_") != null) saw_tail = true;
|
|
282
|
+
}
|
|
283
|
+
try testing.expect(saw_tail);
|
|
284
|
+
// Viewport paging should not charge the 128 offscreen runs to the
|
|
285
|
+
// display list merely to reach the tail.
|
|
286
|
+
try testing.expect(text_commands < 16);
|
|
287
|
+
}
|
|
288
|
+
|
|
250
289
|
const VariableClusterMeasure = struct {
|
|
251
290
|
fn advance(text: []const u8) f32 {
|
|
252
291
|
return switch (text[0]) {
|
|
@@ -605,6 +605,12 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
605
605
|
/// re-steals focus from the user. Only focusable widgets
|
|
606
606
|
/// (interactive controls) can take it.
|
|
607
607
|
autofocus: bool = false,
|
|
608
|
+
/// Textarea Enter policy (markup `submit-on-enter`): plain
|
|
609
|
+
/// Enter submits through `on_submit`, while Shift+Enter
|
|
610
|
+
/// keeps the multiline newline path. False preserves the
|
|
611
|
+
/// default textarea contract (Enter inserts; primary+Enter
|
|
612
|
+
/// submits). Meaningless on every other element.
|
|
613
|
+
submit_on_enter: bool = false,
|
|
608
614
|
variant: canvas.WidgetVariant = .default,
|
|
609
615
|
size: canvas.WidgetSize = .default,
|
|
610
616
|
/// Definite width: the widget is exactly this wide (the value
|
|
@@ -620,6 +626,11 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
620
626
|
/// Split panes use it to constrain the divider drag (the
|
|
621
627
|
/// clamp band derives from both panes' floors).
|
|
622
628
|
min_width: f32 = 0,
|
|
629
|
+
/// Width ceiling WITHOUT the definite-min side of `width`:
|
|
630
|
+
/// the widget fills or hugs normally until this bound, then
|
|
631
|
+
/// stops growing. Pair with a centered flex parent for a
|
|
632
|
+
/// responsive content column.
|
|
633
|
+
max_width: f32 = 0,
|
|
623
634
|
grow: f32 = 0,
|
|
624
635
|
gap: f32 = 0,
|
|
625
636
|
padding: ?f32 = null,
|
|
@@ -1469,7 +1480,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
1469
1480
|
if (self.msgForTextEdit(target_id, stamped)) |msg| return msg;
|
|
1470
1481
|
} else {
|
|
1471
1482
|
const locally_derived = canvas.widgetCodeTabTextEditEvent(widget, keyboard) orelse
|
|
1472
|
-
canvas.widgetKeyboardNewlineTextEditEvent(widget
|
|
1483
|
+
canvas.widgetKeyboardNewlineTextEditEvent(widget, keyboard) orelse
|
|
1473
1484
|
keyboard.textEditEvent();
|
|
1474
1485
|
if (locally_derived) |text_edit| {
|
|
1475
1486
|
// Direct Tree consumers still sanitize locally:
|
|
@@ -2456,7 +2467,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2456
2467
|
else
|
|
2457
2468
|
0;
|
|
2458
2469
|
if (diff_lines) |lines| editor.widget.setCodeDiffLines(lines);
|
|
2459
|
-
editor.widget.code_editor = true;
|
|
2470
|
+
editor.widget.runtime_flags.code_editor = true;
|
|
2460
2471
|
editor.widget.code_language = options.language;
|
|
2461
2472
|
editor.widget.layout.clip_content = true;
|
|
2462
2473
|
return editor;
|
|
@@ -3690,6 +3701,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
3690
3701
|
.text_alignment = options.text_alignment,
|
|
3691
3702
|
.text_overflow = options.overflow,
|
|
3692
3703
|
.autofocus = options.autofocus,
|
|
3704
|
+
.submit_on_enter = options.submit_on_enter,
|
|
3693
3705
|
.image_id = options.image,
|
|
3694
3706
|
.value = options.value,
|
|
3695
3707
|
.value_x = options.value_x,
|
|
@@ -3728,7 +3740,10 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
3728
3740
|
// is the exception: width documents the initial width
|
|
3729
3741
|
// and the engine's drag handle keeps writing larger
|
|
3730
3742
|
// frames past it.
|
|
3731
|
-
.max_size = if (kind == .resizable) .{} else .{
|
|
3743
|
+
.max_size = if (kind == .resizable) .{} else .{
|
|
3744
|
+
.width = if (options.width > 0) options.width else options.max_width,
|
|
3745
|
+
.height = options.height,
|
|
3746
|
+
},
|
|
3732
3747
|
},
|
|
3733
3748
|
.style = options.style,
|
|
3734
3749
|
.semantics = options.semantics,
|
|
@@ -3825,7 +3840,11 @@ fn isSubmitKeyboard(widget: Widget, keyboard: canvas.WidgetKeyboardEvent) bool {
|
|
|
3825
3840
|
// Multi-line entry: Enter edits (newline), so submit rides the
|
|
3826
3841
|
// primary chord — cmd+Enter on macOS, ctrl+Enter elsewhere.
|
|
3827
3842
|
// Shift/alt variants stay free for apps.
|
|
3828
|
-
.textarea =>
|
|
3843
|
+
.textarea => if (widget.submit_on_enter)
|
|
3844
|
+
(!keyboard.modifiers.hasNavigationModifier() and !keyboard.modifiers.shift) or
|
|
3845
|
+
(keyboard.modifiers.hasCommandModifier() and !keyboard.modifiers.alt and !keyboard.modifiers.shift)
|
|
3846
|
+
else
|
|
3847
|
+
keyboard.modifiers.hasCommandModifier() and !keyboard.modifiers.alt and !keyboard.modifiers.shift,
|
|
3829
3848
|
// List rows: plain Enter is the row's primary action when the
|
|
3830
3849
|
// app binds `on_submit` (play the track, open the record); the
|
|
3831
3850
|
// select activation keeps Space. `msgForKeyboard` resolves the
|
|
@@ -1175,6 +1175,8 @@ pub fn deadHandlerOnNonHitTarget(attr_name: []const u8) bool {
|
|
|
1175
1175
|
|
|
1176
1176
|
pub const autofocus_element_message = "autofocus is only supported on focusable controls (text fields, buttons, checkboxes, ...) - it moves keyboard focus to the element when it mounts or when the flag turns on, and nothing about this element can take focus";
|
|
1177
1177
|
|
|
1178
|
+
pub const submit_on_enter_element_message = "submit-on-enter is only supported on textarea - it makes plain Enter dispatch on-submit while Shift+Enter inserts a newline; single-line fields already submit on Enter, and other elements have no multiline Enter policy";
|
|
1179
|
+
|
|
1178
1180
|
pub const non_hit_target_handler_message = "on-change/on-submit/on-input never fire here: this element has no control or text behavior - put them on a control (input, checkbox, slider) inside it (on-press/on-double-press/on-toggle are fine anywhere: a bound press handler makes any element pressable, and clicks on plain text or icons inside it fall through to it)";
|
|
1179
1181
|
|
|
1180
1182
|
/// Elements whose widget kind layers its children on top of each other
|
|
@@ -3281,6 +3283,19 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
|
|
|
3281
3283
|
}
|
|
3282
3284
|
continue;
|
|
3283
3285
|
}
|
|
3286
|
+
if (std.mem.eql(u8, attribute.name, "submit-on-enter")) {
|
|
3287
|
+
// Only textarea has two meaningful Enter gestures:
|
|
3288
|
+
// submit or insert a newline. Single-line fields
|
|
3289
|
+
// already submit on plain Enter, and the option would
|
|
3290
|
+
// be dead on every other kind.
|
|
3291
|
+
if (!std.mem.eql(u8, node.name, "textarea")) {
|
|
3292
|
+
return attrError(node, attribute, submit_on_enter_element_message);
|
|
3293
|
+
}
|
|
3294
|
+
if (attrExpressionError(attribute.value, invalid_expression_message)) |message| {
|
|
3295
|
+
return attrError(node, attribute, message);
|
|
3296
|
+
}
|
|
3297
|
+
continue;
|
|
3298
|
+
}
|
|
3284
3299
|
if (std.mem.eql(u8, attribute.name, "icon")) {
|
|
3285
3300
|
// Inline vector icon, scoped to the labeled
|
|
3286
3301
|
// interactive elements that render it themselves
|
|
@@ -373,6 +373,15 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
|
+
// Interpreter parity: only textarea has a configurable
|
|
377
|
+
// Enter-vs-newline policy.
|
|
378
|
+
if (kind != .textarea) {
|
|
379
|
+
for (node.attrs) |attribute| {
|
|
380
|
+
if (std.mem.eql(u8, attribute.name, "submit-on-enter")) {
|
|
381
|
+
fail(node, markup.submit_on_enter_element_message);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
376
385
|
// Interpreter parity: the overflow policy's closed
|
|
377
386
|
// literal vocabulary. A compile error here; bindings
|
|
378
387
|
// resolve at runtime like any enum option.
|
|
@@ -1158,7 +1158,7 @@ test "compiled code element matches the interpreter and Ui.code" {
|
|
|
1158
1158
|
try expectSameTree(fixture.CodeMsg, editable_hand, editable_interpreted);
|
|
1159
1159
|
try expectSameTree(fixture.CodeMsg, editable_hand, editable_compiled);
|
|
1160
1160
|
try testing.expectEqual(canvas.WidgetKind.textarea, editable_compiled.root.kind);
|
|
1161
|
-
try testing.expect(editable_compiled.root.code_editor);
|
|
1161
|
+
try testing.expect(editable_compiled.root.runtime_flags.code_editor);
|
|
1162
1162
|
}
|
|
1163
1163
|
|
|
1164
1164
|
// ------------------------------------------- template/use + style parity
|
|
@@ -314,6 +314,10 @@ test "structural validation reports positions for grammar misuse" {
|
|
|
314
314
|
var autofocus_parser = markup.Parser.init(arena_state.allocator(), autofocus_source);
|
|
315
315
|
try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try autofocus_parser.parse()));
|
|
316
316
|
|
|
317
|
+
const submit_on_enter_source = "<column>\n <textarea submit-on-enter=\"true\" label=\"Prompt\" on-input=\"edit\" on-submit=\"send\" />\n</column>";
|
|
318
|
+
var submit_on_enter_parser = markup.Parser.init(arena_state.allocator(), submit_on_enter_source);
|
|
319
|
+
try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try submit_on_enter_parser.parse()));
|
|
320
|
+
|
|
317
321
|
const cases = [_]struct { source: []const u8, message: []const u8 }{
|
|
318
322
|
.{ .source = "<column>\n <weird />\n</column>", .message = "unknown element" },
|
|
319
323
|
.{ .source = "<column bogus=\"1\" />", .message = "unknown attribute" },
|
|
@@ -362,6 +366,7 @@ test "structural validation reports positions for grammar misuse" {
|
|
|
362
366
|
// elements can never take the keyboard.
|
|
363
367
|
.{ .source = "<column>\n <row autofocus=\"true\">\n <text>x</text>\n </row>\n</column>", .message = markup.autofocus_element_message },
|
|
364
368
|
.{ .source = "<column>\n <badge autofocus=\"true\">3</badge>\n</column>", .message = markup.autofocus_element_message },
|
|
369
|
+
.{ .source = "<column>\n <text-field submit-on-enter=\"true\" label=\"Prompt\" />\n</column>", .message = markup.submit_on_enter_element_message },
|
|
365
370
|
};
|
|
366
371
|
for (cases) |case| {
|
|
367
372
|
var case_parser = markup.Parser.init(arena_state.allocator(), case.source);
|