@native-sdk/cli 0.6.3 → 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.
- package/build.zig +65 -91
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/text.ts +25 -14
- package/packages/core/src/checker.ts +39 -0
- package/packages/core/src/emitter.ts +125 -1
- package/skill-data/native-ui/SKILL.md +23 -6
- package/src/platform/macos/appkit_host.m +25 -1
- package/src/platform/macos/cef_host.mm +24 -2
- package/src/platform/macos/root.zig +13 -0
- package/src/primitives/canvas/code.zig +1008 -0
- package/src/primitives/canvas/code_tests.zig +1912 -0
- package/src/primitives/canvas/events.zig +111 -1
- package/src/primitives/canvas/layout_audit.zig +3 -1
- package/src/primitives/canvas/markdown.zig +13 -11
- package/src/primitives/canvas/markdown_tests.zig +168 -6
- package/src/primitives/canvas/root.zig +8 -2
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text.zig +6 -0
- package/src/primitives/canvas/text_measure_cache.zig +4 -4
- package/src/primitives/canvas/text_span_tests.zig +254 -0
- package/src/primitives/canvas/text_spans.zig +556 -32
- package/src/primitives/canvas/themes/geist.zig +29 -0
- package/src/primitives/canvas/tokens.zig +72 -2
- package/src/primitives/canvas/ui.zig +400 -22
- package/src/primitives/canvas/ui_markup.zig +78 -7
- package/src/primitives/canvas/ui_markup_compiled.zig +89 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +45 -0
- package/src/primitives/canvas/ui_markup_contract.zig +41 -0
- package/src/primitives/canvas/ui_markup_view.zig +89 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +154 -3
- package/src/primitives/canvas/ui_schema.zig +30 -6
- package/src/primitives/canvas/ui_schema_tests.zig +13 -10
- package/src/primitives/canvas/ui_tests.zig +26 -0
- package/src/primitives/canvas/widget_invalidation.zig +4 -0
- package/src/primitives/canvas/widget_layout.zig +57 -8
- package/src/primitives/canvas/widget_layout_tests.zig +35 -0
- package/src/primitives/canvas/widget_metrics.zig +35 -1
- package/src/primitives/canvas/widget_render.zig +1077 -11
- package/src/primitives/canvas/widget_render_controls.zig +4 -4
- package/src/primitives/canvas/widget_runtime.zig +2 -0
- package/src/primitives/canvas/widget_text_input.zig +165 -8
- package/src/primitives/canvas/widget_text_select.zig +2 -2
- package/src/primitives/canvas/widget_tree.zig +6 -5
- package/src/primitives/canvas/widgets.zig +38 -0
- package/src/root.zig +1 -0
- package/src/runtime/canvas_budget_edge_tests.zig +3 -2
- package/src/runtime/canvas_limits.zig +13 -6
- package/src/runtime/canvas_widget_clipboard_tests.zig +137 -4
- package/src/runtime/canvas_widget_context_menu.zig +17 -2
- package/src/runtime/canvas_widget_event_tests.zig +18 -14
- package/src/runtime/canvas_widget_events.zig +58 -21
- package/src/runtime/canvas_widget_runtime.zig +112 -6
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +59 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +100 -0
- package/src/runtime/canvas_widget_state.zig +27 -0
- package/src/runtime/canvas_widget_text_tests.zig +383 -0
- package/src/runtime/core.zig +15 -5
- package/src/runtime/gpu_surface_events.zig +12 -12
- package/src/runtime/view.zig +61 -19
- package/src/runtime/view_widget_scroll.zig +48 -18
- package/src/runtime/view_widget_text.zig +248 -17
- package/src/runtime/window_view_runtime.zig +9 -0
|
@@ -182,6 +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` | 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)` |
|
|
185
186
|
| `markdown` | rendered markdown subtree | leaf; `source` is one `{binding}` — see "Markdown in markup" |
|
|
186
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` |
|
|
187
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 |
|
|
@@ -298,7 +299,7 @@ How the pieces fit, all model-owned (TEA):
|
|
|
298
299
|
|
|
299
300
|
### Select, then act: double press and row-level Enter
|
|
300
301
|
|
|
301
|
-
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. `
|
|
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.
|
|
302
303
|
|
|
303
304
|
## Widget budgets and virtualization
|
|
304
305
|
|
|
@@ -353,7 +354,7 @@ The `examples/feed` app is the reference: a 100,000-post deterministic MIXED-HEI
|
|
|
353
354
|
|
|
354
355
|
Color and radius come from the design tokens, referenced by token NAME — literals only, no bindings, no raw colors (dynamic styling stays in Zig via `ElementOptions.style`):
|
|
355
356
|
|
|
356
|
-
- Color attributes: `background`, `foreground`, `accent`, `accent-foreground`, `border-color`, `focus-ring`. Values are `canvas.ColorTokens` field names — the complete list: `background`, `surface`, `surface_subtle`, `surface_pressed`, `text`, `text_muted`, `border`, `accent`, `accent_text`, `destructive`, `destructive_text`, `success`, `success_text`, `warning`, `warning_text`, `info`, `info_text`, `focus_ring`, `shadow`, `disabled`. `info` is the violet identity hue beside the status trio (merged PR badges, "new" chips). (`border-color`, not bare `border` — that name is reserved for a future width shorthand.)
|
|
357
|
+
- Color attributes: `background`, `foreground`, `accent`, `accent-foreground`, `border-color`, `focus-ring`. Values are `canvas.ColorTokens` field names — the complete list: `background`, `surface`, `surface_subtle`, `surface_pressed`, `text`, `text_muted`, `syntax_plain`, `syntax_comment`, `syntax_keyword`, `syntax_literal`, `syntax_function`, `syntax_property`, `syntax_constant`, `border`, `accent`, `accent_text`, `destructive`, `destructive_text`, `success`, `success_text`, `warning`, `warning_text`, `info`, `info_text`, `focus_ring`, `shadow`, `scrim`, `disabled`. The `syntax_*` roles are the Geist Code Block palette used automatically by `ui.code` and Markdown fences in both built-in packs. `info` is the violet identity hue beside the status trio (merged PR badges, "new" chips). (`border-color`, not bare `border` — that name is reserved for a future width shorthand.)
|
|
357
358
|
- `radius` — `canvas.RadiusTokens` field names: `sm`, `md`, `lg`, `xl`.
|
|
358
359
|
|
|
359
360
|
```html
|
|
@@ -474,7 +475,7 @@ For `<if test>`, prefer an explicit boolean predicate method over numeric truthi
|
|
|
474
475
|
|
|
475
476
|
## Messages
|
|
476
477
|
|
|
477
|
-
`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.
|
|
478
479
|
|
|
479
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`).
|
|
480
481
|
|
|
@@ -482,7 +483,7 @@ Scroll offsets follow the same mirror discipline as text: the Msg carries the of
|
|
|
482
483
|
|
|
483
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.
|
|
484
485
|
|
|
485
|
-
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.
|
|
486
487
|
|
|
487
488
|
### Keys: quiet list rows and the app-level fallback
|
|
488
489
|
|
|
@@ -967,6 +968,22 @@ Rules and semantics:
|
|
|
967
968
|
|
|
968
969
|
Both engines implement templates, defaults, slots, and imports: the interpreter expands at build time (hot reload re-resolves imports from disk, so edits to imported files reload), and the compiled engine inlines at comptime with the identical result. A document with imports compiles through `canvas.CompiledMarkupImports(Model, Msg, "root.native", &sources)` where `sources` is a `canvas.ui_markup.SourceFile` set (`.{ .path = "components/cards.native", .source = @embedFile("components/cards.native") }`, paths relative to the root file's directory); pass the same set on `MarkupOptions.sources` for the runtime engine. See `examples/kanban/src/board.native` + `examples/kanban/src/components/board-column.native`.
|
|
969
970
|
|
|
971
|
+
## Code in markup: `<code>`
|
|
972
|
+
|
|
973
|
+
Bare source-bound highlighted content shared with Markdown fences:
|
|
974
|
+
|
|
975
|
+
```html
|
|
976
|
+
<code source="{snippet}" language="tsx" line-numbers wrap="false" width="480" label="Component source" />
|
|
977
|
+
```
|
|
978
|
+
|
|
979
|
+
- `source` is one required `{binding}` producing `[]const u8`; the element has no children.
|
|
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.
|
|
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.
|
|
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.
|
|
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`.
|
|
986
|
+
|
|
970
987
|
## Markdown in markup: `<markdown>`
|
|
971
988
|
|
|
972
989
|
A leaf element that renders a markdown string (the GFM subset below) as ordinary widgets, wiring `native_sdk.markdown` for you — both engines implement it identically:
|
|
@@ -1080,7 +1097,7 @@ Md.view(ui, model.body_markdown, .{
|
|
|
1080
1097
|
})
|
|
1081
1098
|
```
|
|
1082
1099
|
|
|
1083
|
-
- Supported: `#`–`###` headings, paragraphs with `**bold**`/`*italic*`/`` `code` ``/`~~strike~~`/`[links](url)`, bare `http(s)://` URLs (autolink, trailing punctuation trimmed), `#123` issue refs (opt-in: set `Options.issue_link_base` and the ref links to base ++ number), bullet + ordered + task lists (task checkboxes are display-only, disabled), fenced code blocks, `> blockquotes`, `---` rules, GFM pipe tables (header bold, `:---`/`:--:`/`---:` column alignment, inline spans + clickable links inside cells, `\|` escapes a pipe in a cell; columns share width equally, and a missing/mismatched delimiter row degrades the block to paragraphs), `<details><summary>`.
|
|
1100
|
+
- Supported: `#`–`###` headings, paragraphs with `**bold**`/`*italic*`/`` `code` ``/`~~strike~~`/`[links](url)`, bare `http(s)://` URLs (autolink, trailing punctuation trimmed), `#123` issue refs (opt-in: set `Options.issue_link_base` and the ref links to base ++ number), bullet + ordered + task lists (task checkboxes are display-only, disabled), fenced code blocks (source indentation preserved; they lower through `ui.code` with wrapping on and line numbers off; recognized Zig, JS/TS, JSX/TSX, JSON, shell, Python, Rust, C-family, Go, HTML/XML/SVG, CSS-family, and SQL info strings get theme-token syntax highlighting; unknown tags stay plain mono), `> blockquotes`, `---` rules, GFM pipe tables (header bold, `:---`/`:--:`/`---:` column alignment, inline spans + clickable links inside cells, `\|` escapes a pipe in a cell; columns share width equally, and a missing/mismatched delimiter row degrades the block to paragraphs), `<details><summary>`.
|
|
1084
1101
|
- Not in v1 (degrades to plain text, never fails): reference links, raw HTML, footnotes, backslash escapes (except `\|` in table rows).
|
|
1085
1102
|
- `<details>` state is elm-style: the CALLER owns the expanded flags. Keep a bounded `details_expanded: [8]bool` in the model, toggle it in `update` on the details message, and pass the slice back in.
|
|
1086
1103
|
|
|
@@ -1123,7 +1140,7 @@ Two `msgForPointer` traps: a **disabled** control yields `null` (assert `== null
|
|
|
1123
1140
|
|
|
1124
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.
|
|
1125
1142
|
|
|
1126
|
-
`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`).
|
|
1127
1144
|
|
|
1128
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).
|
|
1129
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 =
|
|
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)
|
|
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 =
|
|
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,
|