react-x11 2.39.0 → 2.41.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.
@@ -7,6 +7,7 @@
7
7
  import type { RefObject } from 'react';
8
8
  import type { DrawnNode, NtkWindow, TextInputNode } from './nodes.js';
9
9
  import type { MenuShortcut } from './components.js';
10
+ import type { PrimaryModifier } from '../keysyms.js';
10
11
 
11
12
  /** The raw ntk/X11 event a synthetic one was made from. */
12
13
  export interface NativeEvent {
@@ -139,10 +140,14 @@ export interface KeyboardEvent<T = DrawnNode> extends SyntheticEvent<T> {
139
140
  * group and sends no other notice. */
140
141
  group: number;
141
142
  /** Unicode code point, undefined when the key produces no character —
142
- * which includes every key a composition took (see `composing`). */
143
+ * which includes every key a composition took (see `composing`), a dead
144
+ * key on the Cocoa backend, and a key that typed more than one character
145
+ * there, whose text arrives as a composition that starts and ends on it. */
143
146
  codepoint?: number;
144
147
  /** The character the key produced, undefined for non-printing keys and
145
- * for keys a composition took. */
148
+ * for the keys `codepoint` is undefined for. On the Cocoa backend it is
149
+ * what the layout typed with ⌥ applied — `ß` for ⌥S — while `keysym` is
150
+ * still the key. */
146
151
  key?: string;
147
152
  /** Whether this key belongs to an open composition — a dead key, or a key
148
153
  * of a Compose sequence. Its text arrives on the composition events
@@ -331,7 +336,7 @@ export interface ChangeEvent<T = TextInputNode> extends Omit<
331
336
  }
332
337
 
333
338
  /**
334
- * `<textinput onSubmit>` — Enter, or Ctrl+Enter in a `<textarea>`. Same
339
+ * `<textinput onSubmit>` — Enter, or Ctrl+Enter in a `<textarea>` (⌘↩ on Cocoa). Same
335
340
  * shape as {@link ChangeEvent}; `nativeEvent` is the X key event.
336
341
  */
337
342
  export interface SubmitEvent<T = TextInputNode> extends Omit<
@@ -556,7 +561,8 @@ export interface AcceleratorOptions {
556
561
  * Exact on Control/Alt/Shift/Super, indifferent to Caps Lock and Num Lock,
557
562
  * matched against the Latin keysym so a layout switch does not turn it off,
558
563
  * and behind whatever a focused element consumed with `preventDefault()`.
559
- * See docs/events.md.
564
+ * `Control` is the app's primary modifier: ⌘ on the Cocoa backend, the key
565
+ * its menus print. See docs/events.md.
560
566
  *
561
567
  * With no `scope` the binding belongs to the tree's top-level `<window>`, or,
562
568
  * in an app that has none, to the root-level `<popup>` holding the keyboard —
@@ -569,10 +575,25 @@ export function useAccelerator(
569
575
  options?: AcceleratorOptions,
570
576
  ): void;
571
577
 
578
+ export interface MatchesShortcutOptions {
579
+ /**
580
+ * The app's primary modifier — `primaryModifier(app)` from
581
+ * `react-x11/keysyms`. `'Super'` reads a chord's `Control` (and its
582
+ * `Super`) as ⌘ and wants ⌃ up, which is the Cocoa backend's rule;
583
+ * `'Control'`, the default, reads the chord literally.
584
+ */
585
+ primary?: PrimaryModifier;
586
+ }
587
+
572
588
  /**
573
589
  * Whether a key event presses any alternative of a `shortcut` — the matcher
574
590
  * the menus and {@link useAccelerator} both run on, for an application
575
- * dispatching chords its own way.
591
+ * dispatching chords its own way. Pass the app's primary modifier to match
592
+ * the way they do:
593
+ *
594
+ * ```ts
595
+ * matchesShortcut(ev, [['Control', 'S']], { primary: primaryModifier(app) });
596
+ * ```
576
597
  */
577
598
  export function matchesShortcut(
578
599
  ev: {
@@ -584,4 +605,5 @@ export function matchesShortcut(
584
605
  metaKey?: boolean;
585
606
  },
586
607
  shortcut: MenuShortcut | undefined,
608
+ options?: MatchesShortcutOptions,
587
609
  ): boolean;
@@ -243,5 +243,11 @@ export interface NtkApp {
243
243
  createWindow(args?: Record<string, unknown>): NtkWindow;
244
244
  rootWindow(screen?: number): NtkWindow;
245
245
  close(): Promise<void>;
246
+ /**
247
+ * The modifier shortcuts are pressed with on this backend: `'Super'` (⌘)
248
+ * on Cocoa, absent — Ctrl — everywhere else. Read it through
249
+ * `primaryModifierHeld` from `react-x11/keysyms`.
250
+ */
251
+ readonly primaryModifier?: 'Control' | 'Super';
246
252
  [key: string]: any;
247
253
  }