@oxy.so/bloom 21.4.0 → 21.5.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.
Files changed (79) hide show
  1. package/docs/adoption-matrix.mdx +4 -4
  2. package/docs/agent-task-index.mdx +1 -0
  3. package/docs/menubar.mdx +21 -0
  4. package/docs/platform-surface.mdx +11 -2
  5. package/docs/task-catalog.json +1 -1
  6. package/docs/task-catalog.mdx +1 -1
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/commonjs/index.web.js.map +1 -1
  9. package/lib/commonjs/kbd/chord.js +53 -0
  10. package/lib/commonjs/kbd/chord.js.map +1 -1
  11. package/lib/commonjs/menubar/declared.js +134 -11
  12. package/lib/commonjs/menubar/declared.js.map +1 -1
  13. package/lib/commonjs/menubar/description.js +37 -1
  14. package/lib/commonjs/menubar/description.js.map +1 -1
  15. package/lib/commonjs/menubar/registry.js +4 -1
  16. package/lib/commonjs/menubar/registry.js.map +1 -1
  17. package/lib/commonjs/menubar/use-held-modifiers.js +88 -0
  18. package/lib/commonjs/menubar/use-held-modifiers.js.map +1 -0
  19. package/lib/module/index.js.map +1 -1
  20. package/lib/module/index.web.js.map +1 -1
  21. package/lib/module/kbd/chord.js +50 -0
  22. package/lib/module/kbd/chord.js.map +1 -1
  23. package/lib/module/menubar/declared.js +137 -14
  24. package/lib/module/menubar/declared.js.map +1 -1
  25. package/lib/module/menubar/description.js +36 -3
  26. package/lib/module/menubar/description.js.map +1 -1
  27. package/lib/module/menubar/registry.js +4 -1
  28. package/lib/module/menubar/registry.js.map +1 -1
  29. package/lib/module/menubar/use-held-modifiers.js +81 -0
  30. package/lib/module/menubar/use-held-modifiers.js.map +1 -0
  31. package/lib/typescript/commonjs/index.d.ts +1 -1
  32. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  33. package/lib/typescript/commonjs/index.web.d.ts +1 -1
  34. package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
  35. package/lib/typescript/commonjs/kbd/chord.d.ts +19 -1
  36. package/lib/typescript/commonjs/kbd/chord.d.ts.map +1 -1
  37. package/lib/typescript/commonjs/menubar/declared.d.ts.map +1 -1
  38. package/lib/typescript/commonjs/menubar/description.d.ts +20 -0
  39. package/lib/typescript/commonjs/menubar/description.d.ts.map +1 -1
  40. package/lib/typescript/commonjs/menubar/registry.d.ts +5 -0
  41. package/lib/typescript/commonjs/menubar/registry.d.ts.map +1 -1
  42. package/lib/typescript/commonjs/menubar/types.d.ts +20 -0
  43. package/lib/typescript/commonjs/menubar/types.d.ts.map +1 -1
  44. package/lib/typescript/commonjs/menubar/use-held-modifiers.d.ts +7 -0
  45. package/lib/typescript/commonjs/menubar/use-held-modifiers.d.ts.map +1 -0
  46. package/lib/typescript/commonjs/platform-surface/index.d.ts +1 -1
  47. package/lib/typescript/commonjs/platform-surface/index.d.ts.map +1 -1
  48. package/lib/typescript/commonjs/platform-surface/types.d.ts +16 -5
  49. package/lib/typescript/commonjs/platform-surface/types.d.ts.map +1 -1
  50. package/lib/typescript/module/index.d.ts +1 -1
  51. package/lib/typescript/module/index.d.ts.map +1 -1
  52. package/lib/typescript/module/index.web.d.ts +1 -1
  53. package/lib/typescript/module/index.web.d.ts.map +1 -1
  54. package/lib/typescript/module/kbd/chord.d.ts +19 -1
  55. package/lib/typescript/module/kbd/chord.d.ts.map +1 -1
  56. package/lib/typescript/module/menubar/declared.d.ts.map +1 -1
  57. package/lib/typescript/module/menubar/description.d.ts +20 -0
  58. package/lib/typescript/module/menubar/description.d.ts.map +1 -1
  59. package/lib/typescript/module/menubar/registry.d.ts +5 -0
  60. package/lib/typescript/module/menubar/registry.d.ts.map +1 -1
  61. package/lib/typescript/module/menubar/types.d.ts +20 -0
  62. package/lib/typescript/module/menubar/types.d.ts.map +1 -1
  63. package/lib/typescript/module/menubar/use-held-modifiers.d.ts +7 -0
  64. package/lib/typescript/module/menubar/use-held-modifiers.d.ts.map +1 -0
  65. package/lib/typescript/module/platform-surface/index.d.ts +1 -1
  66. package/lib/typescript/module/platform-surface/index.d.ts.map +1 -1
  67. package/lib/typescript/module/platform-surface/types.d.ts +16 -5
  68. package/lib/typescript/module/platform-surface/types.d.ts.map +1 -1
  69. package/package.json +1 -1
  70. package/src/index.ts +1 -0
  71. package/src/index.web.ts +1 -0
  72. package/src/kbd/chord.ts +52 -1
  73. package/src/menubar/declared.tsx +143 -13
  74. package/src/menubar/description.ts +42 -3
  75. package/src/menubar/registry.ts +9 -0
  76. package/src/menubar/types.ts +20 -0
  77. package/src/menubar/use-held-modifiers.ts +90 -0
  78. package/src/platform-surface/index.ts +1 -0
  79. package/src/platform-surface/types.ts +17 -5
@@ -0,0 +1,90 @@
1
+ /**
2
+ * The modifier keys held, followed while an open menu shows an item with an
3
+ * alternate (`MenubarItemProps.alternate`), as a Mac's menu follows the flags
4
+ * to swap an item for its alternate the instant Option goes down or up.
5
+ *
6
+ * WHERE THEY COME FROM:
7
+ * - the platform's `keyboard`: its `subscribeModifiers` (each change, and
8
+ * those held as the window takes the keyboard), and each key press's flags
9
+ * (a modifier's own press holds it), for a platform that tells no changes;
10
+ * - otherwise the document (the web): each key going down or up, and the
11
+ * pointer's flags as it moves or presses, so a menu opened with Option held
12
+ * shows its alternates as soon as the pointer moves; the window losing
13
+ * focus releases them all;
14
+ * - otherwise none: no modifier is ever held.
15
+ */
16
+ import { useEffect, useState } from 'react';
17
+
18
+ import { usePlatformKeyboard } from '../platform-surface/context';
19
+ import type { PlatformKeyEvent, PlatformModifiers } from '../platform-surface/types';
20
+
21
+ export const NO_MODIFIERS: PlatformModifiers = {
22
+ altKey: false,
23
+ ctrlKey: false,
24
+ metaKey: false,
25
+ shiftKey: false,
26
+ };
27
+
28
+ /** The flags a key press leaves held: its own, and its key when the key is a modifier. */
29
+ export function modifiersOfKey(event: PlatformKeyEvent): PlatformModifiers {
30
+ return {
31
+ altKey: event.altKey || event.key === 'Alt',
32
+ ctrlKey: event.ctrlKey || event.key === 'Control',
33
+ metaKey: event.metaKey || event.key === 'Meta',
34
+ shiftKey: event.shiftKey || event.key === 'Shift',
35
+ };
36
+ }
37
+
38
+ const sameModifiers = (a: PlatformModifiers, b: PlatformModifiers) =>
39
+ a.altKey === b.altKey &&
40
+ a.ctrlKey === b.ctrlKey &&
41
+ a.metaKey === b.metaKey &&
42
+ a.shiftKey === b.shiftKey;
43
+
44
+ const flagsOf = (event: PlatformModifiers): PlatformModifiers => ({
45
+ altKey: !!event.altKey,
46
+ ctrlKey: !!event.ctrlKey,
47
+ metaKey: !!event.metaKey,
48
+ shiftKey: !!event.shiftKey,
49
+ });
50
+
51
+ /** The modifiers held now, while the calling component is mounted. */
52
+ export function useHeldModifiers(): PlatformModifiers {
53
+ const keyboard = usePlatformKeyboard();
54
+ const [held, setHeld] = useState(NO_MODIFIERS);
55
+
56
+ useEffect(() => {
57
+ const hold = (next: PlatformModifiers) =>
58
+ setHeld((was) => (sameModifiers(was, next) ? was : next));
59
+ if (keyboard) {
60
+ const changes = keyboard.subscribeModifiers?.((flags) => hold(flagsOf(flags)));
61
+ const presses = keyboard.subscribe((event) => {
62
+ hold(modifiersOfKey(event));
63
+ return false;
64
+ });
65
+ return () => {
66
+ changes?.();
67
+ presses();
68
+ };
69
+ }
70
+ if (typeof document === 'undefined' || typeof window === 'undefined') return undefined;
71
+ // A key going down carries its own modifier's flag, and going up drops it (W3C).
72
+ const onKey = (event: KeyboardEvent) => hold(flagsOf(event));
73
+ const onPointer = (event: PointerEvent) => hold(flagsOf(event));
74
+ const onBlur = () => hold(NO_MODIFIERS);
75
+ document.addEventListener('keydown', onKey, true);
76
+ document.addEventListener('keyup', onKey, true);
77
+ document.addEventListener('pointermove', onPointer, true);
78
+ document.addEventListener('pointerdown', onPointer, true);
79
+ window.addEventListener('blur', onBlur);
80
+ return () => {
81
+ document.removeEventListener('keydown', onKey, true);
82
+ document.removeEventListener('keyup', onKey, true);
83
+ document.removeEventListener('pointermove', onPointer, true);
84
+ document.removeEventListener('pointerdown', onPointer, true);
85
+ window.removeEventListener('blur', onBlur);
86
+ };
87
+ }, [keyboard]);
88
+
89
+ return held;
90
+ }
@@ -50,6 +50,7 @@ export type {
50
50
  PlatformKeyboard,
51
51
  PlatformMaterialProps,
52
52
  PlatformKeyEvent,
53
+ PlatformModifiers,
53
54
  PlatformMenu,
54
55
  PlatformMenuBar,
55
56
  PlatformMenuAction,
@@ -461,19 +461,23 @@ export interface PlatformMenuBar {
461
461
  onActivate(listener: (id: string) => void): () => void;
462
462
  }
463
463
 
464
+ /** The modifier keys held: W3C `KeyboardEvent`'s and `PointerEvent`'s flags. */
465
+ export interface PlatformModifiers {
466
+ readonly altKey: boolean;
467
+ readonly ctrlKey: boolean;
468
+ readonly metaKey: boolean;
469
+ readonly shiftKey: boolean;
470
+ }
471
+
464
472
  /**
465
473
  * A key press as the platform reports it: W3C `KeyboardEvent`'s fields, the
466
474
  * shape React Native's own key events carry.
467
475
  */
468
- export interface PlatformKeyEvent {
476
+ export interface PlatformKeyEvent extends PlatformModifiers {
469
477
  /** `KeyboardEvent.key`: `n`, `N`, `Enter`, `ArrowDown`, … */
470
478
  readonly key: string;
471
479
  /** `KeyboardEvent.code`, the physical key (`KeyN`), when the platform knows it. */
472
480
  readonly code?: string;
473
- readonly altKey: boolean;
474
- readonly ctrlKey: boolean;
475
- readonly metaKey: boolean;
476
- readonly shiftKey: boolean;
477
481
  /** Held down and repeating. */
478
482
  readonly repeat?: boolean;
479
483
  /** Part of an input method's composition. */
@@ -494,6 +498,14 @@ export interface PlatformKeyboard {
494
498
  * then does not deliver it to the focused view. Returns the unsubscribe.
495
499
  */
496
500
  subscribe(listener: (event: PlatformKeyEvent) => boolean): () => void;
501
+ /**
502
+ * Calls `listener` with the modifiers held each time they change, as a Mac's
503
+ * `flagsChanged:`, and with those held as the window takes the keyboard.
504
+ * Optional: an open menu shows an item's alternate (`MenubarItemProps`'
505
+ * `alternate`) the instant Option goes down or up with it, and without it
506
+ * only as a key is pressed with Option held. Returns the unsubscribe.
507
+ */
508
+ subscribeModifiers?(listener: (held: PlatformModifiers) => void): () => void;
497
509
  }
498
510
 
499
511
  /**