@oxy.so/bloom-lens 0.0.0-bootstrap.0 → 1.0.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 (108) hide show
  1. package/LICENSE +673 -0
  2. package/NOTICE +26 -0
  3. package/android/build.gradle +19 -0
  4. package/android/src/main/AndroidManifest.xml +1 -0
  5. package/android/src/main/assets/fonts/Inter-OFL.txt +93 -0
  6. package/android/src/main/assets/fonts/Inter-Regular.ttf +0 -0
  7. package/android/src/main/java/so/oxy/bloom/glassmenu/220 +0 -0
  8. package/android/src/main/java/so/oxy/bloom/glassmenu/GlassMenuAndroidModule.kt +71 -0
  9. package/android/src/main/java/so/oxy/bloom/glassmenu/GlassMenuAndroidView.kt +548 -0
  10. package/android/src/main/java/so/oxy/bloom/glassmenu/backdrop/GlassBackdrop.kt +215 -0
  11. package/android/src/main/java/so/oxy/bloom/glassmenu/backdrop/GlassLens.kt +103 -0
  12. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeGeometry.kt +73 -0
  13. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeIcons.kt +74 -0
  14. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/ChromeMaterial.kt +74 -0
  15. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeHost.kt +73 -0
  16. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeModule.kt +31 -0
  17. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/GlassChromeView.kt +609 -0
  18. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/StaticGlassCache.kt +73 -0
  19. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceIcons.kt +114 -0
  20. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesHost.kt +71 -0
  21. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesModule.kt +22 -0
  22. package/android/src/main/java/so/oxy/bloom/glassmenu/chrome/SurfaceNodesView.kt +527 -0
  23. package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassIcons.kt +68 -0
  24. package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassMenuContent.kt +349 -0
  25. package/android/src/main/java/so/oxy/bloom/glassmenu/content/GlassRow.kt +19 -0
  26. package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassFieldTexture.kt +102 -0
  27. package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassGaussianField.kt +161 -0
  28. package/android/src/main/java/so/oxy/bloom/glassmenu/field/GlassShapes.kt +37 -0
  29. package/android/src/main/java/so/oxy/bloom/glassmenu/field/RoundedField.kt +119 -0
  30. package/android/src/main/java/so/oxy/bloom/glassmenu/field/RoundedUnion.kt +81 -0
  31. package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassGroup.kt +225 -0
  32. package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassJelly.kt +118 -0
  33. package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMorphFrame.kt +22 -0
  34. package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMorphTuning.kt +31 -0
  35. package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassMotion.kt +475 -0
  36. package/android/src/main/java/so/oxy/bloom/glassmenu/motion/GlassSpring.kt +78 -0
  37. package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassDevGuard.kt +31 -0
  38. package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassFeedback.kt +18 -0
  39. package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassMenuOverlay.kt +433 -0
  40. package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassMenuSession.kt +750 -0
  41. package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassScrub.kt +41 -0
  42. package/android/src/main/java/so/oxy/bloom/glassmenu/overlay/GlassSubmenuLayer.kt +290 -0
  43. package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassAbsorbRecord.kt +9 -0
  44. package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMemberRecord.kt +14 -0
  45. package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMenuConfigRecord.kt +24 -0
  46. package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassMenuItemRecord.kt +23 -0
  47. package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassShrinkRecord.kt +10 -0
  48. package/android/src/main/java/so/oxy/bloom/glassmenu/records/GlassTriggerConfigRecord.kt +19 -0
  49. package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassRecipe.kt +18 -0
  50. package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassRenderer.kt +361 -0
  51. package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassShaders.kt +318 -0
  52. package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassStill.kt +115 -0
  53. package/android/src/main/java/so/oxy/bloom/glassmenu/render/GlassSurfaceState.kt +38 -0
  54. package/expo-module.config.json +10 -0
  55. package/package.json +31 -1
  56. package/patches/bloom.patch +1908 -0
  57. package/patches/menu/bloom.patch +148 -0
  58. package/src/base.tsx +208 -0
  59. package/src/chrome/compositor-geometry.ts +163 -0
  60. package/src/chrome/glass-header.tsx +155 -0
  61. package/src/chrome/glass-search-fab.tsx +113 -0
  62. package/src/chrome/glass-size-class.tsx +150 -0
  63. package/src/chrome/glass-toolbar.tsx +45 -0
  64. package/src/chrome/interface.ts +17 -0
  65. package/src/chrome/ios-tab-bar.tsx +49 -0
  66. package/src/chrome/surface-layer.ts +91 -0
  67. package/src/chrome/surface-nodes.tsx +54 -0
  68. package/src/index.ts +19 -0
  69. package/src/menu/components/menu/index.ts +22 -0
  70. package/src/menu/components/menu/menu.tsx +97 -0
  71. package/src/menu/components/menu-action-row/index.ts +1 -0
  72. package/src/menu/components/menu-action-row/menu-action-row.tsx +12 -0
  73. package/src/menu/components/menu-content/index.ts +2 -0
  74. package/src/menu/components/menu-content/menu-content.tsx +11 -0
  75. package/src/menu/components/menu-item/index.ts +13 -0
  76. package/src/menu/components/menu-item/menu-item-icon.tsx +10 -0
  77. package/src/menu/components/menu-item/menu-item-subtitle.tsx +14 -0
  78. package/src/menu/components/menu-item/menu-item-title.tsx +11 -0
  79. package/src/menu/components/menu-item/menu-item.tsx +11 -0
  80. package/src/menu/components/menu-label/index.ts +3 -0
  81. package/src/menu/components/menu-label/menu-label.tsx +11 -0
  82. package/src/menu/components/menu-separator/index.ts +3 -0
  83. package/src/menu/components/menu-separator/menu-separator.tsx +7 -0
  84. package/src/menu/components/menu-submenu/index.ts +1 -0
  85. package/src/menu/components/menu-submenu/menu-submenu.tsx +12 -0
  86. package/src/menu/components/menu-trigger/index.ts +3 -0
  87. package/src/menu/components/menu-trigger/interface.ts +41 -0
  88. package/src/menu/components/menu-trigger/menu-trigger.android.tsx +97 -0
  89. package/src/menu/components/menu-trigger/menu-trigger.tsx +15 -0
  90. package/src/menu/components/menu-trigger/native-menu.android.ts +9 -0
  91. package/src/menu/components/menu-trigger-button/index.ts +3 -0
  92. package/src/menu/components/menu-trigger-button/menu-trigger-button.android.tsx +38 -0
  93. package/src/menu/components/menu-trigger-button/menu-trigger-button.tsx +17 -0
  94. package/src/menu/constants/interface.ts +6 -0
  95. package/src/menu/constants/menu.const.ts +11 -0
  96. package/src/menu/context/interface.ts +63 -0
  97. package/src/menu/context/menu.context.ts +7 -0
  98. package/src/menu/index.ts +53 -0
  99. package/src/menu/interface.ts +229 -0
  100. package/src/menu/utils/create-compound-component.util.ts +18 -0
  101. package/src/menu/utils/find-menu-content.util.ts +17 -0
  102. package/src/menu/utils/flatten-elements.util.ts +18 -0
  103. package/src/menu/utils/parse-menu-content.util.ts +98 -0
  104. package/src/menu/utils/parse-menu-item.util.ts +56 -0
  105. package/src/menu/utils/register-component.util.ts +13 -0
  106. package/src/menu/utils/to-native-item.util.ts +24 -0
  107. package/src/rows.tsx +61 -0
  108. package/README.md +0 -1
@@ -0,0 +1,229 @@
1
+ import type { ReactNode, Ref } from "react";
2
+ import type { PressableProps, StyleProp, ViewStyle } from "react-native";
3
+
4
+ type TMenuScheme = "light" | "dark";
5
+
6
+ type TMenuColorScheme = "auto" | TMenuScheme;
7
+
8
+ type TMenuAlignment = "auto" | "start" | "center" | "end";
9
+
10
+ type TMenuIconName =
11
+ | "check"
12
+ | "grid"
13
+ | "list"
14
+ | "plus"
15
+ | "filter"
16
+ | "ellipsis"
17
+ | "trash"
18
+ | "share"
19
+ | "pencil"
20
+ | "copy"
21
+ | "heart"
22
+ | "folder"
23
+ | "sort"
24
+ | "clock";
25
+
26
+ type TMenuAction = {
27
+ id: string;
28
+ title: string;
29
+ subtitle?: string;
30
+ icon?: TMenuIconName;
31
+ iconPath?: string;
32
+ checked?: boolean;
33
+ destructive?: boolean;
34
+ disabled?: boolean;
35
+ keepOpen?: boolean;
36
+ onSelect?: () => void;
37
+ };
38
+
39
+ type TMenuEntry = TMenuAction | { separator: true } | { heading: string };
40
+
41
+ type TMenuSelectEvent = {
42
+ id: string;
43
+ index: number;
44
+ title: string;
45
+ };
46
+
47
+ type TMenuRect = {
48
+ x: number;
49
+ y: number;
50
+ width: number;
51
+ height: number;
52
+ };
53
+
54
+ type TMenuConfig = {
55
+ blur?: number;
56
+ morphBlur?: number;
57
+ tintColor?: string;
58
+ tintOpacity?: number;
59
+ // Bloom: the rows' ink (the engine's patch); a missing colour keeps the engine's own.
60
+ textColor?: string;
61
+ mutedColor?: string;
62
+ destructiveColor?: string;
63
+ separatorColor?: string;
64
+ saturation?: number;
65
+ refraction?: number;
66
+ rim?: number;
67
+ shine?: number;
68
+ highlightOpacity?: number;
69
+ jelly?: number;
70
+ speed?: number;
71
+ };
72
+
73
+ type TMenuMorphOrigin = "trigger" | "press";
74
+
75
+ type TMenuShrink = {
76
+ duration?: number;
77
+ damping?: number;
78
+ scale?: number;
79
+ };
80
+
81
+ type TMenuAbsorb = {
82
+ duration?: number;
83
+ damping?: number;
84
+ };
85
+
86
+ type TMenuTriggerConfig = {
87
+ morphOrigin?: TMenuMorphOrigin;
88
+ shrink?: TMenuShrink;
89
+ absorb?: TMenuAbsorb;
90
+ blur?: number;
91
+ tintColor?: string;
92
+ tintOpacity?: number;
93
+ saturation?: number;
94
+ refraction?: number;
95
+ rim?: number;
96
+ shine?: number;
97
+ jelly?: number;
98
+ };
99
+
100
+ type TMenuItemIconState = {
101
+ color: string;
102
+ };
103
+
104
+ type TMenuTriggerButton = PressableProps;
105
+
106
+ interface IMenuHandle {
107
+ open: (from?: TMenuRect) => void;
108
+ close: () => void;
109
+ }
110
+
111
+ interface IMenu {
112
+ ref?: Ref<IMenuHandle>;
113
+ colorScheme?: TMenuColorScheme;
114
+ onSelect?: (event: TMenuSelectEvent) => void;
115
+ onOpenChange?: (open: boolean) => void;
116
+ children?: ReactNode;
117
+ }
118
+
119
+ // Bloom: a glass of a group on one trigger. Views with one key are one shape around them all (a union).
120
+ type TMenuGroupMember = {
121
+ key: string;
122
+ // The corner radius in points; unset is a capsule.
123
+ cornerRadius?: number;
124
+ // How it arrives and leaves: out of and into the nearest glass (default), or where it is.
125
+ transition?: "matchedGeometry" | "materialize";
126
+ };
127
+
128
+ interface IMenuTrigger {
129
+ lens?: boolean;
130
+ // Morph from the trigger when it has no glass (lens={false}): the panel grows out of the trigger's rectangle,
131
+ // corner radius and tint, as with glass. Default true. Ignored with glass (a glass trigger always morphs).
132
+ morph?: boolean;
133
+ cornerRadius?: number;
134
+ config?: TMenuTriggerConfig;
135
+ openOnPress?: boolean;
136
+ // Bloom: the rows arrive only as the menu opens; the view opens itself with them, again after they are emptied.
137
+ openWithItems?: boolean;
138
+ // Bloom: the menu has finished closing (its motion ended).
139
+ onMenuClosed?: () => void;
140
+ // Bloom: the colour the trigger sits on. Set, the trigger draws its glass at rest in its place in the view hierarchy
141
+ // (a trigger in a scroll, under the bars) against that colour; the overlay draws it only while the menu is open.
142
+ restBackdrop?: string;
143
+ // Bloom: a tap on the trigger opens the menu natively, with no round trip to JS.
144
+ openOnTap?: boolean;
145
+ // Bloom: the trigger is a group of glasses: it draws each member's glass (found by the nativeID of its views), not its
146
+ // own rect, and they blend within `blend` points.
147
+ members?: readonly TMenuGroupMember[];
148
+ blend?: number;
149
+ accessibilityLabel?: string;
150
+ style?: StyleProp<ViewStyle>;
151
+ children?: ReactNode;
152
+ }
153
+
154
+ interface IMenuContent {
155
+ items?: TMenuEntry[];
156
+ width?: number;
157
+ alignment?: TMenuAlignment;
158
+ fontFamily?: string;
159
+ config?: TMenuConfig;
160
+ children?: ReactNode;
161
+ }
162
+
163
+ // A submenu: a row with a chevron that opens the child items in a glass layer (touch: a layer over the root;
164
+ // fine pointer: a flyout beside the row).
165
+ interface ISubmenu {
166
+ id?: string;
167
+ title: string;
168
+ icon?: TMenuIconName;
169
+ children?: ReactNode;
170
+ }
171
+
172
+ interface IMenuItem {
173
+ id?: string;
174
+ checked?: boolean;
175
+ destructive?: boolean;
176
+ disabled?: boolean;
177
+ keepOpen?: boolean;
178
+ onSelect?: () => void;
179
+ children?: ReactNode;
180
+ }
181
+
182
+ interface IMenuItemIcon {
183
+ name?: TMenuIconName;
184
+ path?: string;
185
+ children?: ReactNode | ((state: TMenuItemIconState) => ReactNode);
186
+ }
187
+
188
+ interface IMenuItemText {
189
+ children: string;
190
+ }
191
+
192
+ interface IMenuLabel {
193
+ children: string;
194
+ }
195
+
196
+ // A row of icon actions at the top of the content (the iOS context menu's row): one cell per action, icon above the
197
+ // title, no separator before the list. Its actions are TMenuAction entries; `onSelect` is per action.
198
+ interface IMenuActionRow {
199
+ items: TMenuAction[];
200
+ }
201
+
202
+ export {
203
+ type IMenu,
204
+ type IMenuContent,
205
+ type IMenuHandle,
206
+ type IMenuItem,
207
+ type ISubmenu,
208
+ type IMenuItemIcon,
209
+ type IMenuItemText,
210
+ type IMenuActionRow,
211
+ type IMenuLabel,
212
+ type IMenuTrigger,
213
+ type TMenuAbsorb,
214
+ type TMenuAction,
215
+ type TMenuAlignment,
216
+ type TMenuColorScheme,
217
+ type TMenuConfig,
218
+ type TMenuEntry,
219
+ type TMenuGroupMember,
220
+ type TMenuIconName,
221
+ type TMenuItemIconState,
222
+ type TMenuMorphOrigin,
223
+ type TMenuRect,
224
+ type TMenuScheme,
225
+ type TMenuSelectEvent,
226
+ type TMenuShrink,
227
+ type TMenuTriggerButton,
228
+ type TMenuTriggerConfig,
229
+ };
@@ -0,0 +1,18 @@
1
+ import type { ComponentType, NamedExoticComponent } from "react";
2
+
3
+ import { registerComponent } from "./register-component.util";
4
+
5
+ const createCompoundComponent = <
6
+ TComponent extends ComponentType<never> | NamedExoticComponent<never>,
7
+ TCompound extends Record<string, unknown> = Record<never, never>,
8
+ >(
9
+ name: string,
10
+ component: TComponent,
11
+ compound: TCompound = {} as TCompound,
12
+ ): TComponent & TCompound =>
13
+ Object.assign<TComponent, TCompound>(
14
+ registerComponent(name, component),
15
+ compound,
16
+ );
17
+
18
+ export { createCompoundComponent };
@@ -0,0 +1,17 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+
3
+ import { MenuContent } from "../components/menu-content/menu-content";
4
+ import type { IMenuContent } from "../interface";
5
+ import {
6
+ flattenElements,
7
+ type TElementWithChildren,
8
+ } from "./flatten-elements.util";
9
+
10
+ const findMenuContent = (
11
+ children: ReactNode,
12
+ ): ReactElement<IMenuContent> | null =>
13
+ (flattenElements(children).find(
14
+ (element: TElementWithChildren): boolean => element.type === MenuContent,
15
+ ) as ReactElement<IMenuContent> | undefined) ?? null;
16
+
17
+ export { findMenuContent };
@@ -0,0 +1,18 @@
1
+ import {
2
+ Children,
3
+ Fragment,
4
+ isValidElement,
5
+ type ReactElement,
6
+ type ReactNode,
7
+ } from "react";
8
+
9
+ type TElementWithChildren = ReactElement<{ children?: ReactNode }>;
10
+
11
+ const flattenElements = (nodes: ReactNode): TElementWithChildren[] =>
12
+ Children.toArray(nodes).flatMap((node: ReactNode): TElementWithChildren[] => {
13
+ if (!isValidElement<{ children?: ReactNode }>(node)) return [];
14
+ if (node.type === Fragment) return flattenElements(node.props.children);
15
+ return [node];
16
+ });
17
+
18
+ export { flattenElements, type TElementWithChildren };
@@ -0,0 +1,98 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+
3
+ import { MenuActionRow } from "../components/menu-action-row/menu-action-row";
4
+ import { MenuItem } from "../components/menu-item/menu-item";
5
+ import { MenuSubmenu } from "../components/menu-submenu/menu-submenu";
6
+ import { MenuLabel } from "../components/menu-label/menu-label";
7
+ import { MenuSeparator } from "../components/menu-separator/menu-separator";
8
+ import type { TNativeMenuItem, TParsedMenu } from "../context/interface";
9
+ import type {
10
+ IMenuActionRow,
11
+ IMenuContent,
12
+ IMenuItem,
13
+ IMenuLabel,
14
+ ISubmenu,
15
+ TMenuAction,
16
+ TMenuEntry,
17
+ TMenuScheme,
18
+ } from "../interface";
19
+ import {
20
+ flattenElements,
21
+ type TElementWithChildren,
22
+ } from "./flatten-elements.util";
23
+ import { parseMenuItem } from "./parse-menu-item.util";
24
+ import { toNativeItem } from "./to-native-item.util";
25
+
26
+ const parseMenuContent = (
27
+ content: IMenuContent | null,
28
+ scheme: TMenuScheme,
29
+ ): TParsedMenu => {
30
+ const items: TNativeMenuItem[] = [];
31
+ const icons: ReactNode[] = [];
32
+ const handlers: Record<string, () => void> = {};
33
+ if (!content) return { items, icons, handlers };
34
+
35
+ (content.items ?? []).forEach((entry: TMenuEntry) => {
36
+ items.push(toNativeItem(entry, items.length));
37
+ if ("onSelect" in entry && entry.onSelect)
38
+ handlers[entry.id] = entry.onSelect;
39
+ });
40
+
41
+ flattenElements(content.children).forEach((element: TElementWithChildren) => {
42
+ if (element.type === MenuSeparator) {
43
+ items.push({
44
+ id: `separator-${items.length}`,
45
+ title: "",
46
+ separator: true,
47
+ });
48
+ } else if (element.type === MenuLabel) {
49
+ const label: ReactElement<IMenuLabel> =
50
+ element as ReactElement<IMenuLabel>;
51
+ items.push({
52
+ id: `heading-${items.length}`,
53
+ title: label.props.children,
54
+ heading: true,
55
+ });
56
+ } else if (element.type === MenuActionRow) {
57
+ // One row of icon actions: a single native item whose cells are the actions (each keeps its own handler).
58
+ const row: ReactElement<IMenuActionRow> = element as ReactElement<IMenuActionRow>;
59
+ const actions: TNativeMenuItem[] = (row.props.items ?? []).map(
60
+ (action: TMenuAction, index: number): TNativeMenuItem => {
61
+ if (action.onSelect) handlers[action.id] = action.onSelect;
62
+ return toNativeItem(action, index);
63
+ },
64
+ );
65
+ items.push({ id: `actions-${items.length}`, title: "", actions });
66
+ } else if (element.type === MenuSubmenu) {
67
+ const sub: ReactElement<ISubmenu> = element as ReactElement<ISubmenu>;
68
+ const children: TNativeMenuItem[] = [];
69
+ flattenElements(sub.props.children).forEach((part: TElementWithChildren): void => {
70
+ if (part.type !== MenuItem) return;
71
+ const entry: ReactElement<IMenuItem> = part as ReactElement<IMenuItem>;
72
+ const child: TNativeMenuItem = parseMenuItem(entry, children.length, scheme, icons);
73
+ children.push(child);
74
+ if (entry.props.onSelect) handlers[child.id] = entry.props.onSelect;
75
+ });
76
+ items.push({
77
+ id: sub.props.id ?? `submenu-${items.length}`,
78
+ title: sub.props.title,
79
+ icon: sub.props.icon,
80
+ items: children,
81
+ });
82
+ } else if (element.type === MenuItem) {
83
+ const entry: ReactElement<IMenuItem> = element as ReactElement<IMenuItem>;
84
+ const item: TNativeMenuItem = parseMenuItem(
85
+ entry,
86
+ items.length,
87
+ scheme,
88
+ icons,
89
+ );
90
+ items.push(item);
91
+ if (entry.props.onSelect) handlers[item.id] = entry.props.onSelect;
92
+ }
93
+ });
94
+
95
+ return { items, icons, handlers };
96
+ };
97
+
98
+ export { parseMenuContent };
@@ -0,0 +1,56 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+
3
+ import { MenuItemIcon } from "../components/menu-item/menu-item-icon";
4
+ import { MenuItemSubtitle } from "../components/menu-item/menu-item-subtitle";
5
+ import { MenuItemTitle } from "../components/menu-item/menu-item-title";
6
+ import { MENU_ICON_COLORS } from "../constants/menu.const";
7
+ import type { TNativeMenuItem } from "../context/interface";
8
+ import type {
9
+ IMenuItem,
10
+ IMenuItemIcon,
11
+ IMenuItemText,
12
+ TMenuScheme,
13
+ } from "../interface";
14
+ import {
15
+ flattenElements,
16
+ type TElementWithChildren,
17
+ } from "./flatten-elements.util";
18
+
19
+ const parseMenuItem = (
20
+ element: ReactElement<IMenuItem>,
21
+ index: number,
22
+ scheme: TMenuScheme,
23
+ icons: ReactNode[],
24
+ ): TNativeMenuItem => {
25
+ const props: IMenuItem = element.props;
26
+ const parts: TElementWithChildren[] = flattenElements(props.children);
27
+ const title: ReactElement<IMenuItemText> | undefined = parts.find(
28
+ (part: TElementWithChildren): boolean => part.type === MenuItemTitle,
29
+ ) as ReactElement<IMenuItemText> | undefined;
30
+ const subtitle: ReactElement<IMenuItemText> | undefined = parts.find(
31
+ (part: TElementWithChildren): boolean => part.type === MenuItemSubtitle,
32
+ ) as ReactElement<IMenuItemText> | undefined;
33
+ const icon: ReactElement<IMenuItemIcon> | undefined = parts.find(
34
+ (part: TElementWithChildren): boolean => part.type === MenuItemIcon,
35
+ ) as ReactElement<IMenuItemIcon> | undefined;
36
+ const item: TNativeMenuItem = {
37
+ id: props.id ?? `item-${index}`,
38
+ title: title?.props.children ?? "",
39
+ subtitle: subtitle?.props.children,
40
+ checked: props.checked,
41
+ destructive: props.destructive,
42
+ disabled: props.disabled,
43
+ keepOpen: props.keepOpen,
44
+ };
45
+ if (!icon) return item;
46
+ const { name, path, children } = icon.props;
47
+ if (children === undefined || children === null) {
48
+ return { ...item, icon: name, iconPath: path };
49
+ }
50
+ const colors = MENU_ICON_COLORS[scheme];
51
+ const color: string = props.destructive ? colors.destructive : colors.base;
52
+ icons.push(typeof children === "function" ? children({ color }) : children);
53
+ return { ...item, iconSlot: icons.length - 1 };
54
+ };
55
+
56
+ export { parseMenuItem };
@@ -0,0 +1,13 @@
1
+ import type { ComponentType, NamedExoticComponent } from "react";
2
+
3
+ const registerComponent = <
4
+ TComponent extends ComponentType<never> | NamedExoticComponent<never>,
5
+ >(
6
+ name: string,
7
+ component: TComponent,
8
+ ): TComponent => {
9
+ component.displayName = name;
10
+ return component;
11
+ };
12
+
13
+ export { registerComponent };
@@ -0,0 +1,24 @@
1
+ import type { TNativeMenuItem } from "../context/interface";
2
+ import type { TMenuEntry } from "../interface";
3
+
4
+ const toNativeItem = (entry: TMenuEntry, index: number): TNativeMenuItem => {
5
+ if ("separator" in entry) {
6
+ return { id: `separator-${index}`, title: "", separator: true };
7
+ }
8
+ if ("heading" in entry) {
9
+ return { id: `heading-${index}`, title: entry.heading, heading: true };
10
+ }
11
+ return {
12
+ id: entry.id,
13
+ title: entry.title,
14
+ subtitle: entry.subtitle,
15
+ icon: entry.icon,
16
+ iconPath: entry.iconPath,
17
+ checked: entry.checked,
18
+ destructive: entry.destructive,
19
+ disabled: entry.disabled,
20
+ keepOpen: entry.keepOpen,
21
+ };
22
+ };
23
+
24
+ export { toNativeItem };
package/src/rows.tsx ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Bloom's rows as the upstream menu's own parts (`Menu.Item`, `Menu.Submenu`, `Menu.Label`,
3
+ * `Menu.Separator`), so the menu reads them as it reads the upstream app's: Bloom gives data
4
+ * and glyph views, the menu does the rest.
5
+ */
6
+ import type { ReactNode } from 'react';
7
+
8
+ import { Menu } from './menu';
9
+
10
+ /** One row of a lens menu. */
11
+ export type LensRow =
12
+ | {
13
+ kind: 'item';
14
+ id: string;
15
+ title: string;
16
+ subtitle?: string;
17
+ /** The row's glyph, a view drawn in the row's ink. */
18
+ icon?: ReactNode;
19
+ checked?: boolean;
20
+ destructive?: boolean;
21
+ disabled?: boolean;
22
+ keepOpen?: boolean;
23
+ onSelect?: () => void;
24
+ }
25
+ | { kind: 'submenu'; id: string; title: string; rows: readonly LensRow[] }
26
+ | { kind: 'heading'; id: string; title: string }
27
+ | { kind: 'separator'; id: string };
28
+
29
+ /** The rows as the menu's children (a submenu holds items only, as upstream). */
30
+ export function lensRows(rows: readonly LensRow[]): ReactNode[] {
31
+ return rows.map((row) => {
32
+ switch (row.kind) {
33
+ case 'separator':
34
+ return <Menu.Separator key={row.id} />;
35
+ case 'heading':
36
+ return <Menu.Label key={row.id}>{row.title}</Menu.Label>;
37
+ case 'submenu':
38
+ return (
39
+ <Menu.Submenu key={row.id} id={row.id} title={row.title}>
40
+ {lensRows(row.rows)}
41
+ </Menu.Submenu>
42
+ );
43
+ case 'item':
44
+ return (
45
+ <Menu.Item
46
+ key={row.id}
47
+ id={row.id}
48
+ checked={row.checked}
49
+ destructive={row.destructive}
50
+ disabled={row.disabled}
51
+ keepOpen={row.keepOpen}
52
+ onSelect={row.onSelect}
53
+ >
54
+ {row.icon ? <Menu.Item.Icon>{row.icon}</Menu.Item.Icon> : null}
55
+ <Menu.Item.Title>{row.title}</Menu.Item.Title>
56
+ {row.subtitle ? <Menu.Item.Subtitle>{row.subtitle}</Menu.Item.Subtitle> : null}
57
+ </Menu.Item>
58
+ );
59
+ }
60
+ });
61
+ }
package/README.md DELETED
@@ -1 +0,0 @@
1
- Placeholder for @oxy.so/bloom-lens. The real package is published by CI from OxyHQ/Bloom.