@native-sdk/cli 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/build.zig +65 -91
  2. package/package.json +9 -9
  3. package/packages/core/package-lock.json +2 -2
  4. package/packages/core/package.json +1 -1
  5. package/packages/core/sdk/text.ts +25 -14
  6. package/packages/core/src/checker.ts +39 -0
  7. package/packages/core/src/emitter.ts +125 -1
  8. package/skill-data/native-ui/SKILL.md +9 -7
  9. package/src/platform/macos/appkit_host.m +25 -1
  10. package/src/platform/macos/cef_host.mm +24 -2
  11. package/src/platform/macos/root.zig +13 -0
  12. package/src/primitives/canvas/code.zig +451 -33
  13. package/src/primitives/canvas/code_tests.zig +855 -5
  14. package/src/primitives/canvas/events.zig +111 -1
  15. package/src/primitives/canvas/markdown_tests.zig +17 -18
  16. package/src/primitives/canvas/root.zig +4 -0
  17. package/src/primitives/canvas/text.zig +6 -0
  18. package/src/primitives/canvas/ui.zig +108 -29
  19. package/src/primitives/canvas/ui_markup.zig +23 -9
  20. package/src/primitives/canvas/ui_markup_compiled.zig +13 -0
  21. package/src/primitives/canvas/ui_markup_compiled_tests.zig +12 -0
  22. package/src/primitives/canvas/ui_markup_contract.zig +8 -1
  23. package/src/primitives/canvas/ui_markup_view.zig +16 -0
  24. package/src/primitives/canvas/ui_markup_view_tests.zig +71 -5
  25. package/src/primitives/canvas/ui_schema.zig +13 -0
  26. package/src/primitives/canvas/ui_schema_tests.zig +9 -7
  27. package/src/primitives/canvas/ui_tests.zig +26 -0
  28. package/src/primitives/canvas/widget_invalidation.zig +1 -0
  29. package/src/primitives/canvas/widget_metrics.zig +10 -5
  30. package/src/primitives/canvas/widget_render.zig +660 -39
  31. package/src/primitives/canvas/widget_render_controls.zig +4 -4
  32. package/src/primitives/canvas/widget_runtime.zig +2 -0
  33. package/src/primitives/canvas/widget_text_input.zig +165 -8
  34. package/src/primitives/canvas/widget_tree.zig +6 -5
  35. package/src/primitives/canvas/widgets.zig +25 -0
  36. package/src/runtime/canvas_budget_edge_tests.zig +3 -2
  37. package/src/runtime/canvas_limits.zig +13 -6
  38. package/src/runtime/canvas_widget_clipboard_tests.zig +7 -4
  39. package/src/runtime/canvas_widget_context_menu.zig +7 -2
  40. package/src/runtime/canvas_widget_event_tests.zig +18 -14
  41. package/src/runtime/canvas_widget_events.zig +51 -20
  42. package/src/runtime/canvas_widget_runtime.zig +105 -4
  43. package/src/runtime/canvas_widget_scroll_driver_tests.zig +59 -0
  44. package/src/runtime/canvas_widget_split_tree_tests.zig +100 -0
  45. package/src/runtime/canvas_widget_state.zig +27 -0
  46. package/src/runtime/canvas_widget_text_tests.zig +326 -0
  47. package/src/runtime/core.zig +15 -5
  48. package/src/runtime/gpu_surface_events.zig +12 -12
  49. package/src/runtime/view.zig +54 -16
  50. package/src/runtime/view_widget_scroll.zig +48 -18
  51. package/src/runtime/view_widget_text.zig +54 -13
  52. package/src/runtime/window_view_runtime.zig +9 -0
@@ -182,7 +182,7 @@ Automation drives the native path honestly: snapshots list every widget's declar
182
182
  | `icon` | vector icon leaf | `name` picks the icon: a bare literal is a curated built-in stroke icon (compile-checked; 49 names: search, plus, x, x-circle, check, check-circle, chevron-up/down/left/right, arrow-up/down/right, menu, panel-left, panel-right, settings, terminal, wrench, trash, edit, copy, external-link, play, pause, skip-back/forward, shuffle, repeat, music, volume, info, alert, download, save, folder, folder-open, file-text, sun, moon, eye, clock, git-pull-request, git-merge, git-branch, circle-dot, archive, refresh-cw, send); `app:<name>` reaches an icon the app registered at boot with `canvas.icons.registerAppIcons` (declare the table as `pub const app_icons` on the app root so `native check` verifies the name against the model contract), and one `{binding}` defers the choice to model data - an unknown resolved name draws the missing-icon fallback (a slashed circle) with a Debug warning naming the value, never a silent gap; tint with `foreground`, size with `width`/`height` |
183
183
  | `media-surface` | media surface leaf | composites a texture produced OUTSIDE the widget tree (video decoder, camera, an external renderer like mpv) into the layout like any widget — clipped, z-ordered, rounded. `surface="{binding}"` (required) binds the model-owned u64 surface id a Zig-tier producer targets (`runtime.acquireMediaSurfaceProducer` pushes RGBA8 frames, latest-wins, paced by the presented-frame clock; 0 = unbound, draws nothing; usable ids are nonzero values below the reserved bit 63). No intrinsic size — give it `width`/`height` or `grow`; display-only (presses fall through); `label` it (pictorial content). Texture contents are presentation chrome: goldens, reference screenshots, and session replay show the deterministic id-derived placeholder, never producer frames |
184
184
  | `image` | runtime image leaf | draws a RUNTIME-REGISTERED image by its model-owned u64 ImageId — the id `Cmd.imageLoad` (TS) or `fx.loadImage`/`fx.registerImageBytes` (Zig) registered pixels under. `image="{binding}"` (required) binds a model field/fn; ids are model data, never markup literals, and 0 draws nothing (store the id only when the load reports loaded — see the Images section). No intrinsic size — give it `width`/`height` or `grow`; display-only (presses fall through); `label` it (pictorial content) |
185
- | `code` | highlighted source surface | `source="{binding}"` (required) provides source text and `language="tsx"` selects a literal lexer name; wraps by default, `line-numbers` opts into logical line numbers, and `wrap="false"` preserves lines inside one horizontal scroll region. HTML-family highlighting distinguishes HTML/XML/SVG and JSX/TSX tags, attributes, strings, comments, and embedded expressions. Zig builder: `ui.code(CodeOptions, source)` |
185
+ | `code` | bare highlighted source/editor | `source="{binding}"` (required) provides source text and `language="tsx"` selects a literal lexer name; the component supplies no background, border, radius, shadow, or padding, so wrap it in a panel/card when chrome is wanted. It is read-only by default; `editable on-input="edit"` opts into multiline editing while retaining highlighting. It wraps by default, `line-numbers` opts into logical line numbers, and `wrap="false"` preserves lines inside one horizontal scroll region. HTML-family highlighting distinguishes HTML/XML/SVG and JSX/TSX tags, attributes, strings, comments, and embedded expressions. Zig builder: `ui.code(CodeOptions, source)` |
186
186
  | `markdown` | rendered markdown subtree | leaf; `source` is one `{binding}` — see "Markdown in markup" |
187
187
  | `stepper` > `step` | composite stage track | `active="{index}"` (required) derives each step's completed/active/pending state; steps are text leaves (no attributes) joined by connectors; stepper also takes `key`, `global-key`, `label` |
188
188
  | `timeline` > `timeline-item` | composite ledger list | items only inside a timeline (for/if fine); items are leaves — `title` (required), `description`, `meta`, `indicator`, `variant`, `connector="false"` on the last item, `selected`; `on-press` makes the whole item pressable with a trailing chevron |
@@ -299,7 +299,7 @@ How the pieces fit, all model-owned (TEA):
299
299
 
300
300
  ### Select, then act: double press and row-level Enter
301
301
 
302
- The desktop list convention — click selects, the primary action (open the record, play the track) rides the double click and Enter — is two bindings on the same row. `on_double_press` (Zig views only — `ElementOptions.on_double_press`; the closed markup grammar has no double-click event) dispatches on the release whose runtime-derived click count reached 2, in place of a second press: the first click still dispatches `on_press` on its own release, so the pairing is additive, never a delay — no press timer, no swallowed first click. Like `on_press`, binding it makes the element a hit target; a widget with no double handler treats a double click as two single clicks. The keyboard mirror is row-level Enter: on a `list-item`, `on-submit` grows a second home beyond text entry — with a submit handler bound, plain Enter on a keyboard-focused row dispatches it as the row's PRIMARY action while Space keeps the select activation (`on-press`); rows without one resolve Enter as select, unchanged. It works from markup (`<list-item on-press="select_track:{t.id}" on-submit="play_track:{t.id}">{t.title}</list-item>`) and Zig views alike, and tests drive it through `msgForKeyboard` (an Enter event resolves the submit handler, Space the press). `examples/soundboard`'s track rows are the live reference: `on_press` select, `on_double_press` play, `on_submit` play.
302
+ The desktop list convention — click selects, the primary action (open the record, play the track) rides the double click and Enter — is two bindings on the same row. `on-double-press` in markup (`ElementOptions.on_double_press` in Zig) dispatches on the release whose runtime-derived click count reached 2, in place of a second press: the first click still dispatches `on-press` on its own release, so the pairing is additive, never a delay — no press timer, no swallowed first click. Like `on-press`, binding it makes the element a hit target; a widget with no double handler treats a double click as two single clicks. The keyboard mirror is row-level Enter: on a `list-item`, `on-submit` grows a second home beyond text entry — with a submit handler bound, plain Enter on a keyboard-focused row dispatches it as the row's PRIMARY action while Space keeps the select activation (`on-press`); rows without one resolve Enter as select, unchanged. Markup pairs the gestures directly (`<list-item on-press="select_track:{t.id}" on-double-press="play_track:{t.id}" on-submit="play_track:{t.id}">{t.title}</list-item>`), and tests drive the pointer half through `msgForPointerClick` and the keyboard half through `msgForKeyboard`. `examples/soundboard`'s Zig track rows remain the live builder reference: `on_press` select, `on_double_press` play, `on_submit` play.
303
303
 
304
304
  ## Widget budgets and virtualization
305
305
 
@@ -475,7 +475,7 @@ For `<if test>`, prefer an explicit boolean predicate method over numeric truthi
475
475
 
476
476
  ## Messages
477
477
 
478
- `on-press`, `on-toggle`, `on-change`, `on-submit` (enter in a text field; primary+enter in a textarea, where enter inserts a newline), `on-dismiss` (dismissible surfaces: dialog, drawer, sheet, dropdown-menu — dispatched when Escape or a click outside dismisses the surface, so the model owns the close), `on-hold` (press-and-hold, see the Pickers section), and `on-hover-enter`/`on-hover-leave` (the pointer-hover containment pair, below) take `tag` or `tag:{payload}`. The tag must be a variant of your `Msg` union; payload bindings coerce to the variant's payload type: integers, floats, enums (from tag names), `[]const u8`, bool. `on-input` is special: name a `Msg` variant whose payload is `canvas.TextInputEvent` and the runtime delivers each text edit in it. `on-scroll` (the `scroll` element only) is the same shape: name a `Msg` variant whose payload is `canvas.ScrollState` and the runtime delivers the post-scroll state — `offset`, `viewport_extent`, `content_extent`, `maxOffset()` — after every user scroll (wheel, kinetic momentum steps, keyboard, accessibility). In Zig views the constructors are `Ui.inputMsg(.tag)` / `Ui.scrollMsg(.tag)` on `on_input` / `on_scroll`. `on-reach-end` (the `scroll` element only; `on_reach_end` in Zig views, any scroll container including the windowed virtual list) is a plain Msg dispatched when a user scroll comes within one viewport of the content end — the infinite-fetch signal, fired once per approach with hysteresis (re-arms past 1.5 viewports, which appending a batch causes by growing the extent). A programmatic jump to the end fires once and NEVER re-arms while the offset stays near the end — re-arming needs a post-scroll observation at least 1.5 viewports from it.
478
+ `on-press`, `on-double-press`, `on-toggle`, `on-change`, `on-submit` (enter in a text field; primary+enter in a textarea, where enter inserts a newline), `on-dismiss` (dismissible surfaces: dialog, drawer, sheet, dropdown-menu — dispatched when Escape or a click outside dismisses the surface, so the model owns the close), `on-hold` (press-and-hold, see the Pickers section), and `on-hover-enter`/`on-hover-leave` (the pointer-hover containment pair, below) take `tag` or `tag:{payload}`. The tag must be a variant of your `Msg` union; payload bindings coerce to the variant's payload type: integers, floats, enums (from tag names), `[]const u8`, bool. `on-input` is special: name a `Msg` variant whose payload is `canvas.TextInputEvent` and the runtime delivers each text edit in it. `on-scroll` (the `scroll` element only) is the same shape: name a `Msg` variant whose payload is `canvas.ScrollState` and the runtime delivers the post-scroll state — `offset`, `viewport_extent`, `content_extent`, `maxOffset()` — after every user scroll (wheel, kinetic momentum steps, keyboard, accessibility). In Zig views the constructors are `Ui.inputMsg(.tag)` / `Ui.scrollMsg(.tag)` on `on_input` / `on_scroll`. `on-reach-end` (the `scroll` element only; `on_reach_end` in Zig views, any scroll container including the windowed virtual list) is a plain Msg dispatched when a user scroll comes within one viewport of the content end — the infinite-fetch signal, fired once per approach with hysteresis (re-arms past 1.5 viewports, which appending a batch causes by growing the extent). A programmatic jump to the end fires once and NEVER re-arms while the offset stays near the end — re-arming needs a post-scroll observation at least 1.5 viewports from it.
479
479
 
480
480
  Scroll offsets follow the same mirror discipline as text: the Msg carries the offset the runtime ALREADY applied, so store it in the model and echo it back through the scroll's `value` — the echoed source value equals the runtime offset, which the scroll reconcile rule treats as "unchanged", so rebuilds never stomp live scrolling. `on-scroll` is how long content pages or lazy-loads: keep a bounded window in the model and slide it from `offset` (near-end when `offset + viewport_extent` approaches `content_extent`).
481
481
 
@@ -483,7 +483,7 @@ Scroll offsets follow the same mirror discipline as text: the Msg carries the of
483
483
 
484
484
  A handler or update error DEGRADES, it does not exit the app: dispatch catches it, records it in a bounded ring (`runtime.dispatchErrors()`, the `error event=... name=...` lines and `dispatch_errors=` count in automation snapshots, and a `dispatch.error` trace record at error level), and the app keeps running. Trace-sink capacity failures likewise never fail dispatch — dropped records are counted (`dropped_trace_records=`), not fatal. Design for it: an arm that can fail should still surface its own status in the model; the error ring is the safety net, not the UX.
485
485
 
486
- Presses follow ONE rule: a click lands on the nearest pressable widget under the pointer — plain text, icons, images, badges, and layout containers let it fall through to their closest pressable ancestor, and dragging still selects text. "Pressable" means an interactive kind (button, checkbox, list-item, ...) or ANY element with a bound `on-press`/`on-toggle` — the handler itself makes the element a hit target, so a pressable row is just `<panel on-press="open:{id}">` (or `<row on-press=...>`, `ui.row(.{ .on_press = ... })`) with plain text children: no empty-text overlays, no duplicating the handler onto every text leaf. Nested pressables resolve to the deepest one (a button inside a pressable row wins over the row); editable text fields, scroll containers, and modal surfaces (dialog, drawer, sheet, popover, menus) always claim their own presses, so a click in a field inside a pressable row places the caret instead of activating the row. The value/text handlers (`on-change`, `on-submit`, `on-input`) still only belong on controls — both engines and `markup check` reject them on layout/decoration elements with a teaching error.
486
+ Presses follow ONE rule: a click lands on the nearest pressable widget under the pointer — plain text, icons, images, badges, and layout containers let it fall through to their closest pressable ancestor, and dragging still selects text. "Pressable" means an interactive kind (button, checkbox, list-item, ...) or ANY element with a bound `on-press`/`on-double-press`/`on-toggle` — the handler itself makes the element a hit target, so a pressable row is just `<panel on-press="open:{id}">` (or `<row on-press=...>`, `ui.row(.{ .on_press = ... })`) with plain text children: no empty-text overlays, no duplicating the handler onto every text leaf. Nested pressables resolve to the deepest one (a button inside a pressable row wins over the row); editable text fields, scroll containers, and modal surfaces (dialog, drawer, sheet, popover, menus) always claim their own presses, so a click in a field inside a pressable row places the caret instead of activating the row. The value/text handlers (`on-change`, `on-submit`, `on-input`) still only belong on controls — both engines and `markup check` reject them on layout/decoration elements with a teaching error.
487
487
 
488
488
  ### Keys: quiet list rows and the app-level fallback
489
489
 
@@ -970,7 +970,7 @@ Both engines implement templates, defaults, slots, and imports: the interpreter
970
970
 
971
971
  ## Code in markup: `<code>`
972
972
 
973
- A source-bound highlighted surface shared with Markdown fences:
973
+ Bare source-bound highlighted content shared with Markdown fences:
974
974
 
975
975
  ```html
976
976
  <code source="{snippet}" language="tsx" line-numbers wrap="false" width="480" label="Component source" />
@@ -978,9 +978,11 @@ A source-bound highlighted surface shared with Markdown fences:
978
978
 
979
979
  - `source` is one required `{binding}` producing `[]const u8`; the element has no children.
980
980
  - `language` is a literal lexer name: Zig, JS/TS, JSX/TSX, JSON, shell, Python, Rust, C-family, Go, HTML/XML/SVG, CSS-family, or SQL. Omit it for plain monospace.
981
+ - The component owns highlighting, line numbers, clipping, and scrolling, but no background, border, radius, shadow, or padding. Compose those choices outside it, for example `<panel padding="12"><code source="{snippet}" language="tsx" /></panel>`.
982
+ - Code is selectable/read-only by default. Add `editable on-input="edit"` to use the multiline editor path; the message carries `canvas.TextInputEvent`, so apply it to the same model-owned `TextBuffer` that supplies `source`. Editing retains syntax highlighting and does not add textarea chrome.
981
983
  - Wrapping is on by default. `wrap="false"` keeps logical lines intact inside one horizontal scroll region. A definite `height` makes overflow scroll vertically; with wrapping off, that constrained region scrolls on both axes.
982
984
  - `line-numbers` is off by default. Wrapped logical lines stay paired with their number. Numbered mode is limited to 128 logical lines and a reserved share of the per-view node and text-span budgets; sources that exceed any bound preserve all code and omit the gutter.
983
- - Zig builder: `ui.code(.{ .language = .html, .line_numbers = true, .wrap = false }, model.snippet)`. The public lexer helpers are under `native_sdk.canvas.code`.
985
+ - Zig builder: `ui.code(.{ .language = .html, .editable = true, .on_input = Ui.inputMsg(.edit), .line_numbers = true, .wrap = false }, model.snippet)`. Omit `editable`/`on_input` for read-only code. The public lexer helpers are under `native_sdk.canvas.code`.
984
986
 
985
987
  ## Markdown in markup: `<markdown>`
986
988
 
@@ -1138,7 +1140,7 @@ Two `msgForPointer` traps: a **disabled** control yields `null` (assert `== null
1138
1140
 
1139
1141
  One widget-field trap: there is no `Widget.enabled` — enabled-ness is spelled `widget.state.disabled` (a `bool`, disabled-positive), so a test asserts `try testing.expect(!button.state.disabled);` for an enabled control and `try testing.expect(save.state.disabled);` for a disabled one.
1140
1142
 
1141
- `msgForPointer` has a sibling for every handler channel — use the one matching the interaction under test, all on the finalized `Tree`: `msgForKeyboard(id, keyboard_event)` (activation keys, slider steps, enter-to-submit, text edits), `msgForResize(id, fraction)` (the split-divider round-trip: dispatch the fraction, assert the model stored it, rebuild, assert the `value` echo), `msgForDismiss(id)` (an anchored surface's `on-dismiss`), `msgForHold(id)` (`on-hold`), `msgForTextEdit(id, edit)` (text entry), `msgForValue(id, value)` (BUILDER views only — it fires the `on_value` constructor, so it returns null for a markup slider; a markup slider binds a plain `on-change`, so assert its dispatch with `msgFor(id, .change)` — the accessibility set-value intent falls back to the same handler), `msgForScroll(id, state)`, and `msgForContextMenu(id, item_index)`. For tree keyboard NAVIGATION there is nothing app-side to unit test: Up/Down/Left/Right/Home/End run engine-side over `role="treeitem"` rows and dispatch the landed row's `on-press`/`on-toggle` — assert those Msgs (via `msgForPointer`/`msgFor(id, .toggle)`) and the model transitions; the keymap itself is runtime behavior (drive it live with `native automate widget-key`).
1143
+ `msgForPointer` has a sibling for every handler channel — use the one matching the interaction under test, all on the finalized `Tree`: `msgForPointerClick(id, .up, click_count)` (double-click resolution: the second release prefers `on-double-press`), `msgForKeyboard(id, keyboard_event)` (activation keys, slider steps, enter-to-submit, text edits), `msgForResize(id, fraction)` (the split-divider round-trip: dispatch the fraction, assert the model stored it, rebuild, assert the `value` echo), `msgForDismiss(id)` (an anchored surface's `on-dismiss`), `msgForHold(id)` (`on-hold`), `msgForTextEdit(id, edit)` (text entry), `msgForValue(id, value)` (BUILDER views only — it fires the `on_value` constructor, so it returns null for a markup slider; a markup slider binds a plain `on-change`, so assert its dispatch with `msgFor(id, .change)` — the accessibility set-value intent falls back to the same handler), `msgForScroll(id, state)`, and `msgForContextMenu(id, item_index)`. For tree keyboard NAVIGATION there is nothing app-side to unit test: Up/Down/Left/Right/Home/End run engine-side over `role="treeitem"` rows and dispatch the landed row's `on-press`/`on-toggle` — assert those Msgs (via `msgForPointer`/`msgFor(id, .toggle)`) and the model transitions; the keymap itself is runtime behavior (drive it live with `native automate widget-key`).
1142
1144
 
1143
1145
  Runtime-integration tests use `native_sdk.TestHarness()` on the null platform; heap-allocate both the harness and the app struct (they are multi-megabyte; stack allocation crashes).
1144
1146
 
@@ -7352,6 +7352,30 @@ static BOOL NativeSdkScrollDriverCanConsumeHorizontally(NativeSdkScrollDriverVie
7352
7352
  }
7353
7353
  if (!restoreFrame) {
7354
7354
  [window center];
7355
+ // AppKit centers every new window by default, which leaves a
7356
+ // model-declared secondary window exactly covering the editor that
7357
+ // opened it. Cascade from the active window like Win32's default
7358
+ // placement so repeated Command+N windows stay visibly distinct.
7359
+ NSWindow *referenceWindow = NSApp.keyWindow ?: self.window;
7360
+ if (!makeMain && referenceWindow) {
7361
+ NSRect referenceFrame = referenceWindow.frame;
7362
+ NSRect cascadedFrame = window.frame;
7363
+ cascadedFrame.origin.x = NSMinX(referenceFrame) + 24.0;
7364
+ cascadedFrame.origin.y = NSMaxY(referenceFrame) - 24.0 - NSHeight(cascadedFrame);
7365
+
7366
+ // A maximized or edge-positioned reference must not push the new
7367
+ // window beyond the usable screen. Fit the complete frame when
7368
+ // possible; an oversized window keeps its leading/bottom edge.
7369
+ NSScreen *referenceScreen = referenceWindow.screen ?: window.screen ?: NSScreen.mainScreen;
7370
+ if (referenceScreen) {
7371
+ NSRect visibleFrame = referenceScreen.visibleFrame;
7372
+ CGFloat maxOriginX = MAX(NSMinX(visibleFrame), NSMaxX(visibleFrame) - NSWidth(cascadedFrame));
7373
+ CGFloat maxOriginY = MAX(NSMinY(visibleFrame), NSMaxY(visibleFrame) - NSHeight(cascadedFrame));
7374
+ cascadedFrame.origin.x = MIN(MAX(NSMinX(cascadedFrame), NSMinX(visibleFrame)), maxOriginX);
7375
+ cascadedFrame.origin.y = MIN(MAX(NSMinY(cascadedFrame), NSMinY(visibleFrame)), maxOriginY);
7376
+ }
7377
+ [window setFrame:cascadedFrame display:NO];
7378
+ }
7355
7379
  }
7356
7380
  if (makeMain) NativeSdkLaunchLap("window_chrome_ready");
7357
7381
 
@@ -12243,7 +12267,7 @@ native_sdk_appkit_open_dialog_result_t native_sdk_appkit_show_open_dialog(native
12243
12267
  NSString *path = [[NSString alloc] initWithBytes:opts->default_path length:opts->default_path_len encoding:NSUTF8StringEncoding];
12244
12268
  panel.directoryURL = [NSURL fileURLWithPath:path];
12245
12269
  }
12246
- panel.canChooseFiles = YES;
12270
+ panel.canChooseFiles = opts->allow_directories == 0;
12247
12271
  panel.canChooseDirectories = opts->allow_directories != 0;
12248
12272
  panel.allowsMultipleSelection = opts->allow_multiple != 0;
12249
12273
  NativeSdkConfigurePanelExtensions(panel, NativeSdkParseExtensions(opts->extensions, opts->extensions_len));
@@ -946,7 +946,29 @@ static const char *NativeSdkCefBridgeScript() {
946
946
  if ((windowFlags & (1u << 2)) != 0) window.ignoresMouseEvents = YES;
947
947
  if ((windowFlags & (1u << 3)) != 0) [self.passiveShowWindows addObject:key];
948
948
  [window setTitle:title.length > 0 ? title : @"native-sdk"];
949
- if (!restoreFrame) [window center];
949
+ if (!restoreFrame) {
950
+ [window center];
951
+ // Match the system-WebView host and Win32's default placement:
952
+ // secondary windows should reveal the window that opened them,
953
+ // not land directly on top of it.
954
+ NSWindow *referenceWindow = NSApp.keyWindow ?: self.window;
955
+ if (!makeMain && referenceWindow) {
956
+ NSRect referenceFrame = referenceWindow.frame;
957
+ NSRect cascadedFrame = window.frame;
958
+ cascadedFrame.origin.x = NSMinX(referenceFrame) + 24.0;
959
+ cascadedFrame.origin.y = NSMaxY(referenceFrame) - 24.0 - NSHeight(cascadedFrame);
960
+
961
+ NSScreen *referenceScreen = referenceWindow.screen ?: window.screen ?: NSScreen.mainScreen;
962
+ if (referenceScreen) {
963
+ NSRect visibleFrame = referenceScreen.visibleFrame;
964
+ CGFloat maxOriginX = MAX(NSMinX(visibleFrame), NSMaxX(visibleFrame) - NSWidth(cascadedFrame));
965
+ CGFloat maxOriginY = MAX(NSMinY(visibleFrame), NSMaxY(visibleFrame) - NSHeight(cascadedFrame));
966
+ cascadedFrame.origin.x = MIN(MAX(NSMinX(cascadedFrame), NSMinX(visibleFrame)), maxOriginX);
967
+ cascadedFrame.origin.y = MIN(MAX(NSMinY(cascadedFrame), NSMinY(visibleFrame)), maxOriginY);
968
+ }
969
+ [window setFrame:cascadedFrame display:NO];
970
+ }
971
+ }
950
972
 
951
973
  NSView *stackRoot = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, width, height)];
952
974
  stackRoot.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
@@ -3128,7 +3150,7 @@ native_sdk_appkit_open_dialog_result_t native_sdk_appkit_show_open_dialog(native
3128
3150
  NSString *path = [[NSString alloc] initWithBytes:opts->default_path length:opts->default_path_len encoding:NSUTF8StringEncoding];
3129
3151
  panel.directoryURL = [NSURL fileURLWithPath:path];
3130
3152
  }
3131
- panel.canChooseFiles = YES;
3153
+ panel.canChooseFiles = opts->allow_directories == 0;
3132
3154
  panel.canChooseDirectories = opts->allow_directories != 0;
3133
3155
  panel.allowsMultipleSelection = opts->allow_multiple != 0;
3134
3156
  NativeSdkConfigurePanelExtensions(panel, NativeSdkParseExtensions(opts->extensions, opts->extensions_len));
@@ -2471,6 +2471,19 @@ test "mac active implicit show activates before making the window key" {
2471
2471
  ) != null);
2472
2472
  }
2473
2473
 
2474
+ test "mac unrestored secondary windows cascade within the active screen" {
2475
+ for ([_][]const u8{ @embedFile("appkit_host.m"), @embedFile("cef_host.mm") }) |host_source| {
2476
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "NSWindow *referenceWindow = NSApp.keyWindow ?: self.window;") != null);
2477
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "NSMinX(referenceFrame) + 24.0") != null);
2478
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "NSMaxY(referenceFrame) - 24.0") != null);
2479
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "if (!makeMain && referenceWindow)") != null);
2480
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "NSRect visibleFrame = referenceScreen.visibleFrame;") != null);
2481
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "NSMaxX(visibleFrame) - NSWidth(cascadedFrame)") != null);
2482
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "NSMaxY(visibleFrame) - NSHeight(cascadedFrame)") != null);
2483
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "[window setFrame:cascadedFrame display:NO]") != null);
2484
+ }
2485
+ }
2486
+
2474
2487
  test "mac explicit focus activates before making the window key" {
2475
2488
  const host_source = @embedFile("appkit_host.m");
2476
2489
  try std.testing.expect(std.mem.indexOf(u8, host_source,