@tearleads/windowing 0.2.42 → 0.2.43

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/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { DisplayProperties } from "./display/DisplayProperties.js";
7
7
  export { type WindowingIcons, WindowingIconsProvider, } from "./icons/WindowingIcons.js";
8
8
  export type { WindowingIcon, WindowingIconProps } from "./icons/windowingIcon.js";
9
9
  export { ROUTED_TABLET_BREAKPOINT_PX, ROUTED_TABLET_QUERY, WINDOWED_LAYOUT_MIN_WIDTH_PX, } from "./launcher/breakpoints.js";
10
+ export { LauncherMenuItem } from "./launcher/LauncherMenuItem.js";
10
11
  export { type LauncherNavigationActions, LauncherNavigationProvider, type LauncherNavigationState, useLauncherNavigationActions, useLauncherNavigationState, useMiniAppRouteSegments, useOptionalLauncherNavigationState, } from "./launcher/LauncherNavigationProvider.js";
11
12
  export { isLauncherAppId, type LauncherDefinition, type MiniAppDefinition, resolveLauncherHomeAppId, resolveLauncherOrder, } from "./launcher/launcherDefinition.js";
12
13
  export { MiniAppRouteSegmentsProvider, useMiniAppWindowRouteSegments, } from "./launcher/MiniAppRouteSegmentsContext.js";
package/index.js CHANGED
@@ -12,6 +12,7 @@ export { createMemoryDesktopStateStorage, createOpfsDesktopStateStorage, } from
12
12
  export { DisplayProperties } from "./display/DisplayProperties.js";
13
13
  export { WindowingIconsProvider, } from "./icons/WindowingIcons.js";
14
14
  export { ROUTED_TABLET_BREAKPOINT_PX, ROUTED_TABLET_QUERY, WINDOWED_LAYOUT_MIN_WIDTH_PX, } from "./launcher/breakpoints.js";
15
+ export { LauncherMenuItem } from "./launcher/LauncherMenuItem.js";
15
16
  export { LauncherNavigationProvider, useLauncherNavigationActions, useLauncherNavigationState, useMiniAppRouteSegments, useOptionalLauncherNavigationState, } from "./launcher/LauncherNavigationProvider.js";
16
17
  export { isLauncherAppId, resolveLauncherHomeAppId, resolveLauncherOrder, } from "./launcher/launcherDefinition.js";
17
18
  export { MiniAppRouteSegmentsProvider, useMiniAppWindowRouteSegments, } from "./launcher/MiniAppRouteSegmentsContext.js";
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../home/runner/work/tearleads/tearleads/packages/windowing/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,6EAA6E;AAC7E,8EAA8E;AAC9E,2EAA2E;AAC3E,4EAA4E;AAC5E,6EAA6E;AAC7E,sEAAsE;AACtE,6BAA6B;AAC7B,OAAO,EACL,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,YAAY,GAEb,MAAM,wBAAwB,CAAC;AAKhC,OAAO,EACL,+BAA+B,EAC/B,6BAA6B,GAG9B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAEL,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,0BAA0B,EAE1B,4BAA4B,EAC5B,0BAA0B,EAC1B,uBAAuB,EACvB,kCAAkC,GACnC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,eAAe,EAGf,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAwB,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EACL,8BAA8B,EAC9B,yBAAyB,EACzB,iCAAiC,GAClC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EACL,wBAAwB,EAGxB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,2BAA2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AM,qBAAqB,CAAC;AAMlD,OAAO,EAAE,UAAU,EAA2B,MAAM,mBAAmB,CAAC;AACxE,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,aAAa,GACd,MAAM,2BAA2B,CAAC;AAKnC,OAAO,EACL,gBAAgB,GAEjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,GAClB,MAAM,+BAA+B,CAAC;AAKvC,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,MAAM,EAA8B,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,6BAA6B,EAC7B,uBAAuB,EACvB,wBAAwB,EACxB,2BAA2B,EAC3B,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAQlB,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["import \"./tokens.css\";\n\n// The public windowing API: window state, window chrome and its registration\n// hooks, the menu and sidebar primitives the chrome renders with, a taskbar's\n// start menu, theme switch, and system tray, the icons the chrome draws, a\n// launcher of mini-apps that shows them in windows or in the routed (iPad /\n// phone) shell, and desktop icons that open them, with a storage adapter for\n// their layout, over a wallpaper chosen in Display Properties, plus a\n// host-supplied screensaver.\nexport {\n createRequiredContext,\n type RequiredContext,\n} from \"./createRequiredContext\";\nexport type { DesktopIconMenuItem } from \"./desktop/DesktopIconMenu\";\nexport {\n DesktopIcons,\n type DesktopIconsProps,\n} from \"./desktop/DesktopIcons\";\nexport type {\n DesktopIconPosition,\n DesktopState,\n} from \"./desktop/desktopState\";\nexport {\n createMemoryDesktopStateStorage,\n createOpfsDesktopStateStorage,\n type DesktopStateStorage,\n type OpfsDesktopStateStorageOptions,\n} from \"./desktop/desktopStateStorage\";\nexport { DisplayProperties } from \"./display/DisplayProperties\";\nexport {\n type WindowingIcons,\n WindowingIconsProvider,\n} from \"./icons/WindowingIcons\";\nexport type { WindowingIcon, WindowingIconProps } from \"./icons/windowingIcon\";\nexport {\n ROUTED_TABLET_BREAKPOINT_PX,\n ROUTED_TABLET_QUERY,\n WINDOWED_LAYOUT_MIN_WIDTH_PX,\n} from \"./launcher/breakpoints\";\nexport {\n type LauncherNavigationActions,\n LauncherNavigationProvider,\n type LauncherNavigationState,\n useLauncherNavigationActions,\n useLauncherNavigationState,\n useMiniAppRouteSegments,\n useOptionalLauncherNavigationState,\n} from \"./launcher/LauncherNavigationProvider\";\nexport {\n isLauncherAppId,\n type LauncherDefinition,\n type MiniAppDefinition,\n resolveLauncherHomeAppId,\n resolveLauncherOrder,\n} from \"./launcher/launcherDefinition\";\nexport {\n MiniAppRouteSegmentsProvider,\n useMiniAppWindowRouteSegments,\n} from \"./launcher/MiniAppRouteSegmentsContext\";\nexport { type MiniAppBoundary, MiniAppWindow } from \"./launcher/MiniAppWindow\";\nexport {\n NavigationModeOverrideProvider,\n useNavigationModeOverride,\n useOptionalNavigationModeOverride,\n} from \"./launcher/NavigationModeOverrideProvider\";\nexport { NavigationModeSwitch } from \"./launcher/NavigationModeSwitch\";\nexport {\n isWindowedLayoutEligible,\n type NavigationEnvironment,\n type NavigationMode,\n readNavigationEnvironment,\n resolveNavigationMode,\n} from \"./launcher/navigationMode\";\nexport {\n DEFAULT_MINI_APP_POSITION,\n type MiniAppWindowPlacement,\n type OpenMiniAppRequest,\n type PlaceMiniAppWindow,\n} from \"./launcher/openMiniAppWindow\";\nexport {\n buildMiniAppPath,\n type LauncherRoute,\n parseLauncherRoute,\n} from \"./launcher/routePaths\";\nexport {\n resolveActiveLauncherRoute,\n useActiveLauncherRoute,\n} from \"./launcher/useActiveLauncherRoute\";\nexport { useCompactRoutedMode } from \"./launcher/useCompactRoutedMode\";\nexport {\n type MiniAppRouteSetOptions,\n useMiniAppRouteState,\n} from \"./launcher/useMiniAppRouteState\";\nexport { useNavigationMode } from \"./launcher/useNavigationMode\";\nexport { useNavigationModeDocumentAttribute } from \"./launcher/useNavigationModeDocumentAttribute\";\nexport {\n useRoutedLayoutActive,\n useWindowedLayoutActive,\n} from \"./launcher/useRoutedLayoutActive\";\nexport {\n type RoutedLayoutTier,\n useRoutedLayoutTier,\n} from \"./launcher/useRoutedLayoutTier\";\nexport { Menu, type MenuPosition } from \"./menu/Menu\";\nexport { MenuItem, type MenuItemProps } from \"./menu/MenuItem\";\nexport {\n StartMenu,\n type StartMenuItem,\n type StartMenuProps,\n} from \"./menu/StartMenu\";\nexport {\n type ContextMenuState,\n useContextMenuPositionState,\n useContextMenuState,\n} from \"./menu/useContextMenuState\";\nexport { useLongPress } from \"./menu/useLongPress\";\nexport { RoutedPane, type RoutedPaneProps } from \"./routed/RoutedPane\";\nexport {\n RoutedPaneOverlayHostProvider,\n type RoutedPaneOverlayHostValue,\n useRoutedPaneOverlayHost,\n} from \"./routed/RoutedPaneOverlayHost\";\nexport type { SubscribeKeyboardVisibility } from \"./routed/useMobileKeyboardVisible\";\nexport { LaserScreensaver } from \"./screensaver/LaserScreensaver\";\nexport {\n type ScreensaverControls,\n ScreensaverProvider,\n type ScreensaverProviderProps,\n useOptionalScreensaver,\n useScreensaver,\n} from \"./screensaver/ScreensaverProvider\";\nexport type { ScreensaverPinVerifier } from \"./screensaver/screensaverPinVerifier\";\nexport { SidebarResizeHandle, useSidebarResize } from \"./sidebar/SidebarResize\";\nexport {\n ThemeProvider,\n useOptionalTheme,\n useTheme,\n} from \"./theme/ThemeProvider\";\nexport { ThemeSwitch } from \"./theme/ThemeSwitch\";\nexport type {\n DefaultTheme,\n ThemeDefinition,\n ThemeScheme,\n} from \"./theme/themes\";\nexport { SystemTray, type SystemTrayMenuItem } from \"./tray/SystemTray\";\nexport {\n SystemTrayProvider,\n useOptionalSystemTray,\n useSystemTray,\n} from \"./tray/SystemTrayProvider\";\nexport type {\n SystemTrayDefinition,\n TrayAppDefinition,\n} from \"./tray/systemTrayDefinition\";\nexport {\n DesktopWallpaper,\n type DesktopWallpaperProps,\n} from \"./wallpaper/DesktopWallpaper\";\nexport {\n BLOCKS_WALLPAPER,\n CHEVRON_WALLPAPER,\n HARLEQUIN_WALLPAPER,\n HONEYCOMB_WALLPAPER,\n PLAIN_WALLPAPER,\n TRIANGLES_WALLPAPER,\n} from \"./wallpaper/tessellations\";\nexport {\n useOptionalWallpaper,\n useWallpaper,\n WallpaperProvider,\n} from \"./wallpaper/WallpaperProvider\";\nexport type {\n WallpaperDefinition,\n WallpaperTile,\n} from \"./wallpaper/wallpapers\";\nexport {\n CurrentWindowProvider,\n useCurrentWindow,\n useSuppressWindowToolbar,\n useWindowBackground,\n useWindowContentSize,\n} from \"./window/CurrentWindowContext\";\nexport { Window, type WindowContentBoundary } from \"./window/Window\";\nexport { WindowTitleBarActionButtons } from \"./window/WindowChromeActions\";\nexport { WindowCloseButton } from \"./window/WindowCloseButton\";\nexport {\n useWindowBackAction,\n useWindowBackActionValue,\n useWindowFileMenuItem,\n useWindowRefreshMenuItem,\n useWindowRefreshMenuItemValue,\n useWindowTitleBarAction,\n useWindowTitleBarActions,\n useWindowToolbarReservation,\n useWindowViewMenuItem,\n WindowMenuProvider,\n} from \"./window/WindowMenuContext\";\nexport {\n hasWindowSidebar,\n useRegisteredWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./window/WindowSidebarContext\";\nexport {\n findTopWindow,\n useWindowActions,\n useWindowStateData,\n type WindowCreateOptions,\n type WindowEntry,\n type WindowGeometry,\n type WindowPosition,\n type WindowSize,\n type WindowStateActions,\n type WindowStateData,\n WindowStateProvider,\n} from \"./window/WindowStateProvider\";\nexport { WindowToolBar } from \"./window/WindowToolBar\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../home/runner/work/tearleads/tearleads/packages/windowing/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,6EAA6E;AAC7E,8EAA8E;AAC9E,2EAA2E;AAC3E,4EAA4E;AAC5E,6EAA6E;AAC7E,sEAAsE;AACtE,6BAA6B;AAC7B,OAAO,EACL,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,YAAY,GAEb,MAAM,wBAAwB,CAAC;AAKhC,OAAO,EACL,+BAA+B,EAC/B,6BAA6B,GAG9B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAEL,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAEL,0BAA0B,EAE1B,4BAA4B,EAC5B,0BAA0B,EAC1B,uBAAuB,EACvB,kCAAkC,GACnC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,eAAe,EAGf,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAwB,aAAa,EAAE,M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AQlB,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["import \"./tokens.css\";\n\n// The public windowing API: window state, window chrome and its registration\n// hooks, the menu and sidebar primitives the chrome renders with, a taskbar's\n// start menu, theme switch, and system tray, the icons the chrome draws, a\n// launcher of mini-apps that shows them in windows or in the routed (iPad /\n// phone) shell, and desktop icons that open them, with a storage adapter for\n// their layout, over a wallpaper chosen in Display Properties, plus a\n// host-supplied screensaver.\nexport {\n createRequiredContext,\n type RequiredContext,\n} from \"./createRequiredContext\";\nexport type { DesktopIconMenuItem } from \"./desktop/DesktopIconMenu\";\nexport {\n DesktopIcons,\n type DesktopIconsProps,\n} from \"./desktop/DesktopIcons\";\nexport type {\n DesktopIconPosition,\n DesktopState,\n} from \"./desktop/desktopState\";\nexport {\n createMemoryDesktopStateStorage,\n createOpfsDesktopStateStorage,\n type DesktopStateStorage,\n type OpfsDesktopStateStorageOptions,\n} from \"./desktop/desktopStateStorage\";\nexport { DisplayProperties } from \"./display/DisplayProperties\";\nexport {\n type WindowingIcons,\n WindowingIconsProvider,\n} from \"./icons/WindowingIcons\";\nexport type { WindowingIcon, WindowingIconProps } from \"./icons/windowingIcon\";\nexport {\n ROUTED_TABLET_BREAKPOINT_PX,\n ROUTED_TABLET_QUERY,\n WINDOWED_LAYOUT_MIN_WIDTH_PX,\n} from \"./launcher/breakpoints\";\nexport { LauncherMenuItem } from \"./launcher/LauncherMenuItem\";\nexport {\n type LauncherNavigationActions,\n LauncherNavigationProvider,\n type LauncherNavigationState,\n useLauncherNavigationActions,\n useLauncherNavigationState,\n useMiniAppRouteSegments,\n useOptionalLauncherNavigationState,\n} from \"./launcher/LauncherNavigationProvider\";\nexport {\n isLauncherAppId,\n type LauncherDefinition,\n type MiniAppDefinition,\n resolveLauncherHomeAppId,\n resolveLauncherOrder,\n} from \"./launcher/launcherDefinition\";\nexport {\n MiniAppRouteSegmentsProvider,\n useMiniAppWindowRouteSegments,\n} from \"./launcher/MiniAppRouteSegmentsContext\";\nexport { type MiniAppBoundary, MiniAppWindow } from \"./launcher/MiniAppWindow\";\nexport {\n NavigationModeOverrideProvider,\n useNavigationModeOverride,\n useOptionalNavigationModeOverride,\n} from \"./launcher/NavigationModeOverrideProvider\";\nexport { NavigationModeSwitch } from \"./launcher/NavigationModeSwitch\";\nexport {\n isWindowedLayoutEligible,\n type NavigationEnvironment,\n type NavigationMode,\n readNavigationEnvironment,\n resolveNavigationMode,\n} from \"./launcher/navigationMode\";\nexport {\n DEFAULT_MINI_APP_POSITION,\n type MiniAppWindowPlacement,\n type OpenMiniAppRequest,\n type PlaceMiniAppWindow,\n} from \"./launcher/openMiniAppWindow\";\nexport {\n buildMiniAppPath,\n type LauncherRoute,\n parseLauncherRoute,\n} from \"./launcher/routePaths\";\nexport {\n resolveActiveLauncherRoute,\n useActiveLauncherRoute,\n} from \"./launcher/useActiveLauncherRoute\";\nexport { useCompactRoutedMode } from \"./launcher/useCompactRoutedMode\";\nexport {\n type MiniAppRouteSetOptions,\n useMiniAppRouteState,\n} from \"./launcher/useMiniAppRouteState\";\nexport { useNavigationMode } from \"./launcher/useNavigationMode\";\nexport { useNavigationModeDocumentAttribute } from \"./launcher/useNavigationModeDocumentAttribute\";\nexport {\n useRoutedLayoutActive,\n useWindowedLayoutActive,\n} from \"./launcher/useRoutedLayoutActive\";\nexport {\n type RoutedLayoutTier,\n useRoutedLayoutTier,\n} from \"./launcher/useRoutedLayoutTier\";\nexport { Menu, type MenuPosition } from \"./menu/Menu\";\nexport { MenuItem, type MenuItemProps } from \"./menu/MenuItem\";\nexport {\n StartMenu,\n type StartMenuItem,\n type StartMenuProps,\n} from \"./menu/StartMenu\";\nexport {\n type ContextMenuState,\n useContextMenuPositionState,\n useContextMenuState,\n} from \"./menu/useContextMenuState\";\nexport { useLongPress } from \"./menu/useLongPress\";\nexport { RoutedPane, type RoutedPaneProps } from \"./routed/RoutedPane\";\nexport {\n RoutedPaneOverlayHostProvider,\n type RoutedPaneOverlayHostValue,\n useRoutedPaneOverlayHost,\n} from \"./routed/RoutedPaneOverlayHost\";\nexport type { SubscribeKeyboardVisibility } from \"./routed/useMobileKeyboardVisible\";\nexport { LaserScreensaver } from \"./screensaver/LaserScreensaver\";\nexport {\n type ScreensaverControls,\n ScreensaverProvider,\n type ScreensaverProviderProps,\n useOptionalScreensaver,\n useScreensaver,\n} from \"./screensaver/ScreensaverProvider\";\nexport type { ScreensaverPinVerifier } from \"./screensaver/screensaverPinVerifier\";\nexport { SidebarResizeHandle, useSidebarResize } from \"./sidebar/SidebarResize\";\nexport {\n ThemeProvider,\n useOptionalTheme,\n useTheme,\n} from \"./theme/ThemeProvider\";\nexport { ThemeSwitch } from \"./theme/ThemeSwitch\";\nexport type {\n DefaultTheme,\n ThemeDefinition,\n ThemeScheme,\n} from \"./theme/themes\";\nexport { SystemTray, type SystemTrayMenuItem } from \"./tray/SystemTray\";\nexport {\n SystemTrayProvider,\n useOptionalSystemTray,\n useSystemTray,\n} from \"./tray/SystemTrayProvider\";\nexport type {\n SystemTrayDefinition,\n TrayAppDefinition,\n} from \"./tray/systemTrayDefinition\";\nexport {\n DesktopWallpaper,\n type DesktopWallpaperProps,\n} from \"./wallpaper/DesktopWallpaper\";\nexport {\n BLOCKS_WALLPAPER,\n CHEVRON_WALLPAPER,\n HARLEQUIN_WALLPAPER,\n HONEYCOMB_WALLPAPER,\n PLAIN_WALLPAPER,\n TRIANGLES_WALLPAPER,\n} from \"./wallpaper/tessellations\";\nexport {\n useOptionalWallpaper,\n useWallpaper,\n WallpaperProvider,\n} from \"./wallpaper/WallpaperProvider\";\nexport type {\n WallpaperDefinition,\n WallpaperTile,\n} from \"./wallpaper/wallpapers\";\nexport {\n CurrentWindowProvider,\n useCurrentWindow,\n useSuppressWindowToolbar,\n useWindowBackground,\n useWindowContentSize,\n} from \"./window/CurrentWindowContext\";\nexport { Window, type WindowContentBoundary } from \"./window/Window\";\nexport { WindowTitleBarActionButtons } from \"./window/WindowChromeActions\";\nexport { WindowCloseButton } from \"./window/WindowCloseButton\";\nexport {\n useWindowBackAction,\n useWindowBackActionValue,\n useWindowFileMenuItem,\n useWindowRefreshMenuItem,\n useWindowRefreshMenuItemValue,\n useWindowTitleBarAction,\n useWindowTitleBarActions,\n useWindowToolbarReservation,\n useWindowViewMenuItem,\n WindowMenuProvider,\n} from \"./window/WindowMenuContext\";\nexport {\n hasWindowSidebar,\n useRegisteredWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./window/WindowSidebarContext\";\nexport {\n findTopWindow,\n useWindowActions,\n useWindowStateData,\n type WindowCreateOptions,\n type WindowEntry,\n type WindowGeometry,\n type WindowPosition,\n type WindowSize,\n type WindowStateActions,\n type WindowStateData,\n WindowStateProvider,\n} from \"./window/WindowStateProvider\";\nexport { WindowToolBar } from \"./window/WindowToolBar\";\n"]}
@@ -0,0 +1,6 @@
1
+ import type { WindowingIcon } from "../icons/windowingIcon.js";
2
+ export declare function LauncherMenuItem({ icon, label, onClick, }: {
3
+ icon?: WindowingIcon | undefined;
4
+ label: string;
5
+ onClick: () => void;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { MenuItem } from "../menu/MenuItem.js";
3
+ import { useLauncherEntryMenu } from "./useLauncherEntryMenu.js";
4
+ export function LauncherMenuItem({ icon, label, onClick, }) {
5
+ const { menu, triggerProps } = useLauncherEntryMenu(icon, onClick);
6
+ return (_jsxs(_Fragment, { children: [_jsx(MenuItem, { ...triggerProps, icon: icon, label: label, onClick: onClick }), menu] }));
7
+ }
8
+ //# sourceMappingURL=LauncherMenuItem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LauncherMenuItem.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/LauncherMenuItem.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,MAAM,UAAU,gBAAgB,CAAC,EAC/B,IAAI,EACJ,KAAK,EACL,OAAO,GAKR;IACC,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACnE,OAAO,CACL,8BACE,KAAC,QAAQ,OAAK,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,GAAI,EACzE,IAAI,IACJ,CACJ,CAAC;AACJ,CAAC","sourcesContent":["import type { WindowingIcon } from \"../icons/windowingIcon\";\nimport { MenuItem } from \"../menu/MenuItem\";\nimport { useLauncherEntryMenu } from \"./useLauncherEntryMenu\";\n\nexport function LauncherMenuItem({\n icon,\n label,\n onClick,\n}: {\n icon?: WindowingIcon | undefined;\n label: string;\n onClick: () => void;\n}) {\n const { menu, triggerProps } = useLauncherEntryMenu(icon, onClick);\n return (\n <>\n <MenuItem {...triggerProps} icon={icon} label={label} onClick={onClick} />\n {menu}\n </>\n );\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { MouseEvent } from "react";
2
+ import type { WindowingIcon } from "../icons/windowingIcon.js";
3
+ /** Secondary activation offers the same Open action as the entry itself. */
4
+ export declare function useLauncherEntryMenu(icon: WindowingIcon | undefined, onOpen: () => void): {
5
+ triggerProps: {
6
+ onContextMenu(event: MouseEvent<HTMLElement>): void;
7
+ onPointerCancel: (event: import("react").PointerEvent<HTMLElement>) => void;
8
+ onPointerDown: (event: import("react").PointerEvent<HTMLElement>) => void;
9
+ onPointerMove: (event: import("react").PointerEvent<HTMLElement>) => void;
10
+ onPointerUp: (event: import("react").PointerEvent<HTMLElement>) => void;
11
+ };
12
+ menu: import("react").JSX.Element | null;
13
+ };
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { DesktopIconMenu } from "../desktop/DesktopIconMenu.js";
3
+ import { useContextMenuState } from "../menu/useContextMenuState.js";
4
+ import { useLongPress } from "../menu/useLongPress.js";
5
+ /** Secondary activation offers the same Open action as the entry itself. */
6
+ export function useLauncherEntryMenu(icon, onOpen) {
7
+ const { closeContextMenu, contextMenu, openContextMenu } = useContextMenuState();
8
+ const longPress = useLongPress(true, { emulateRightClick: true });
9
+ return {
10
+ triggerProps: {
11
+ ...longPress,
12
+ onContextMenu(event) {
13
+ event.currentTarget.focus({ preventScroll: true });
14
+ openContextMenu(event, null);
15
+ },
16
+ },
17
+ menu: contextMenu && (_jsx(DesktopIconMenu, { icon: icon, items: [], onClose: closeContextMenu, onOpen: onOpen, position: contextMenu.position })),
18
+ };
19
+ }
20
+ //# sourceMappingURL=useLauncherEntryMenu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLauncherEntryMenu.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/useLauncherEntryMenu.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,4EAA4E;AAC5E,MAAM,UAAU,oBAAoB,CAClC,IAA+B,EAC/B,MAAkB;IAElB,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,eAAe,EAAE,GACtD,mBAAmB,EAAQ,CAAC;IAC9B,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;IAClE,OAAO;QACL,YAAY,EAAE;YACZ,GAAG,SAAS;YACZ,aAAa,CAAC,KAA8B;gBAC1C,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;gBACnD,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAC/B,CAAC;SACF;QACD,IAAI,EAAE,WAAW,IAAI,CACnB,KAAC,eAAe,IACd,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,EAAE,EACT,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,WAAW,CAAC,QAAQ,GAC9B,CACH;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { MouseEvent } from \"react\";\nimport { DesktopIconMenu } from \"../desktop/DesktopIconMenu\";\nimport type { WindowingIcon } from \"../icons/windowingIcon\";\nimport { useContextMenuState } from \"../menu/useContextMenuState\";\nimport { useLongPress } from \"../menu/useLongPress\";\n\n/** Secondary activation offers the same Open action as the entry itself. */\nexport function useLauncherEntryMenu(\n icon: WindowingIcon | undefined,\n onOpen: () => void,\n) {\n const { closeContextMenu, contextMenu, openContextMenu } =\n useContextMenuState<null>();\n const longPress = useLongPress(true, { emulateRightClick: true });\n return {\n triggerProps: {\n ...longPress,\n onContextMenu(event: MouseEvent<HTMLElement>) {\n event.currentTarget.focus({ preventScroll: true });\n openContextMenu(event, null);\n },\n },\n menu: contextMenu && (\n <DesktopIconMenu\n icon={icon}\n items={[]}\n onClose={closeContextMenu}\n onOpen={onOpen}\n position={contextMenu.position}\n />\n ),\n };\n}\n"]}
package/menu/Menu.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect, useEffectEvent, useLayoutEffect, useRef, useState, } from "react";
2
+ import { useContext, useEffect, useEffectEvent, useLayoutEffect, useRef, useState, } from "react";
3
3
  import { createPortal } from "react-dom";
4
4
  import "./Menu.css";
5
+ import { menuContainsTarget, ParentMenu, registerMenuParent, } from "./menuOwnership.js";
5
6
  import { useMenuKeyboard } from "./useMenuKeyboard.js";
6
7
  const MENU_VIEWPORT_MARGIN_PX = 8;
7
8
  const MEASUREMENT_MENU_STYLE = {
@@ -46,12 +47,7 @@ function useMenuOutsideDismissal(menuRef, onClose) {
46
47
  const close = useEffectEvent(onClose);
47
48
  useEffect(() => {
48
49
  function handleClick(e) {
49
- const target = e.target;
50
- if (!(target instanceof Node)) {
51
- close();
52
- return;
53
- }
54
- if (menuRef.current && !menuRef.current.contains(target)) {
50
+ if (menuRef.current && !menuContainsTarget(menuRef.current, e.target)) {
55
51
  close();
56
52
  }
57
53
  }
@@ -62,13 +58,10 @@ function useMenuOutsideDismissal(menuRef, onClose) {
62
58
  // anywhere else would leave it floating where the trigger used to be. Close
63
59
  // it instead. Scrolls inside the menu — its own overflow, or a list it
64
60
  // hosts — are the menu working as intended. Capture phase, because scroll
65
- // events do not bubble. The check covers this menu's own subtree only: a
66
- // nested Menu is portaled to the body too, so scrolling one would close its
67
- // parent. Nothing nests menus today; revisit here if that changes.
61
+ // events do not bubble. Include any child menus portaled to the body.
68
62
  useEffect(() => {
69
63
  function handleScroll(e) {
70
- const target = e.target;
71
- if (target instanceof Node && menuRef.current?.contains(target)) {
64
+ if (menuRef.current && menuContainsTarget(menuRef.current, e.target)) {
72
65
  return;
73
66
  }
74
67
  close();
@@ -115,6 +108,12 @@ function placeMenuInViewport(input) {
115
108
  }
116
109
  export function Menu({ position, onClose, direction = "up", keyboardNavigation = true, children, }) {
117
110
  const menuRef = useRef(null);
111
+ const parent = useContext(ParentMenu);
112
+ useLayoutEffect(() => {
113
+ return parent && menuRef.current
114
+ ? registerMenuParent(menuRef.current, parent)
115
+ : undefined;
116
+ }, [parent]);
118
117
  useMenuOutsideDismissal(menuRef, onClose);
119
118
  const { x, y } = position;
120
119
  const [placement, setPlacement] = useState(() => createInitialMenuPlacement(position, direction));
@@ -170,6 +169,6 @@ export function Menu({ position, onClose, direction = "up", keyboardNavigation =
170
169
  top: placement.top,
171
170
  }
172
171
  : MEASUREMENT_MENU_STYLE;
173
- return createPortal(_jsx("div", { ref: menuRef, className: "menu", "data-scrollable": scrollable || undefined, style: menuStyle, tabIndex: -1, children: children }), document.body);
172
+ return createPortal(_jsx("div", { ref: menuRef, className: "menu", "data-scrollable": scrollable || undefined, style: menuStyle, tabIndex: -1, children: _jsx(ParentMenu.Provider, { value: menuRef, children: children }) }), document.body);
174
173
  }
175
174
  //# sourceMappingURL=Menu.js.map
package/menu/Menu.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Menu.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/Menu.tsx"],"names":[],"mappings":";AAAA,OAAO,EAIL,SAAS,EACT,cAAc,EACd,eAAe,EACf,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAClC,MAAM,sBAAsB,GAAkB;IAC5C,IAAI,EAAE,uBAAuB;IAC7B,aAAa,EAAE,MAAM;IACrB,GAAG,EAAE,uBAAuB;IAC5B,UAAU,EAAE,QAAQ;CACrB,CAAC;AAEF,2EAA2E;AAC3E,2EAA2E;AAC3E,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAEvC,SAAS,SAAS,CAAC,OAAoB;IACrC,OAAO,CACL,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,GAAG,4BAA4B,CAC3E,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,yBAAyB,CAAC,IAAiB;IAClD,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAc,GAAG,CAAC,CAAC,EAAE,CAAC;QAC1E,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YACxB,SAAS;QACX,CAAC;QACD,M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AE,eAAe,CAAC,CAAC;QACnD,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,UAAU,EAAE,CAAC;YACtB,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QACxD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IAEtB,MAAM,sBAAsB,GAC1B,SAAS,CAAC,QAAQ;QAClB,SAAS,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC;QAChC,SAAS,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC;QAChC,SAAS,CAAC,eAAe,KAAK,SAAS,CAAC;IAC1C,eAAe,CACb,OAAO,EACP,sBAAsB,IAAI,kBAAkB,EAC5C,OAAO,CACR,CAAC;IACF,MAAM,SAAS,GAAkB,sBAAsB;QACrD,CAAC,CAAC;YACE,IAAI,EAAE,SAAS,CAAC,IAAI;YACpB,SAAS,EAAE,SAAS,CAAC,SAAS;YAC9B,QAAQ,EAAE,SAAS,CAAC,QAAQ;YAC5B,GAAG,EAAE,SAAS,CAAC,GAAG;SACnB;QACH,CAAC,CAAC,sBAAsB,CAAC;IAE3B,OAAO,YAAY,CACjB,cACE,GAAG,EAAE,OAAO,EACZ,SAAS,EAAC,MAAM,qBACC,UAAU,IAAI,SAAS,EACxC,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,CAAC,CAAC,YAEX,QAAQ,GACL,EACN,QAAQ,CAAC,IAAI,CACd,CAAC;AACJ,CAAC","sourcesContent":["import {\n type CSSProperties,\n type PropsWithChildren,\n type RefObject,\n useEffect,\n useEffectEvent,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport \"./Menu.css\";\nimport { useMenuKeyboard } from \"./useMenuKeyboard\";\n\nconst MENU_VIEWPORT_MARGIN_PX = 8;\nconst MEASUREMENT_MENU_STYLE: CSSProperties = {\n left: MENU_VIEWPORT_MARGIN_PX,\n pointerEvents: \"none\",\n top: MENU_VIEWPORT_MARGIN_PX,\n visibility: \"hidden\",\n};\n\n// Fractional layout or zoom can report a spurious pixel of overflow; treat\n// that as fitting, since a false positive hands touch panning to the page.\nconst SCROLL_OVERFLOW_TOLERANCE_PX = 1;\n\nfunction overflows(element: HTMLElement): boolean {\n return (\n element.scrollHeight > element.clientHeight + SCROLL_OVERFLOW_TOLERANCE_PX\n );\n}\n\n/**\n * Whether touch should be allowed to pan inside the menu: its own box scrolls,\n * or a descendant scroll container (a select menu's option list) does. The\n * menu box is a scroll container by its stylesheet; descendants qualify by\n * their computed overflow so a plain overflowing block does not count.\n */\nfunction hasTouchScrollableContent(menu: HTMLElement): boolean {\n if (overflows(menu)) {\n return true;\n }\n\n for (const element of Array.from(menu.querySelectorAll<HTMLElement>(\"*\"))) {\n if (!overflows(element)) {\n continue;\n }\n const overflowY = getComputedStyle(element).overflowY;\n if (overflowY === \"auto\" || overflowY === \"scroll\") {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Dismiss the menu on a pointer press or a scroll outside it. The closer is\n * read through an effect event: consumers commonly pass an inline one, and\n * the document listeners should subscribe once, not on every render.\n */\nfunction useMenuOutsideDismissal(\n menuRef: RefObject<HTMLDivElement | null>,\n onClose: () => void,\n): void {\n const close = useEffectEvent(onClose);\n\n useEffect(() => {\n function handleClick(e: MouseEvent) {\n const target = e.target;\n if (!(target instanceof Node)) {\n close();\n return;\n }\n\n if (menuRef.current && !menuRef.current.contains(target)) {\n close();\n }\n }\n document.addEventListener(\"mousedown\", handleClick);\n return () => document.removeEventListener(\"mousedown\", handleClick);\n }, [menuRef]);\n\n // The menu is anchored once, from its trigger's position, so a scroll\n // anywhere else would leave it floating where the trigger used to be. Close\n // it instead. Scrolls inside the menu — its own overflow, or a list it\n // hosts — are the menu working as intended. Capture phase, because scroll\n // events do not bubble. The check covers this menu's own subtree only: a\n // nested Menu is portaled to the body too, so scrolling one would close its\n // parent. Nothing nests menus today; revisit here if that changes.\n useEffect(() => {\n function handleScroll(e: Event) {\n const target = e.target;\n if (target instanceof Node && menuRef.current?.contains(target)) {\n return;\n }\n close();\n }\n document.addEventListener(\"scroll\", handleScroll, true);\n return () => document.removeEventListener(\"scroll\", handleScroll, true);\n }, [menuRef]);\n}\n\nexport interface MenuPosition {\n x: number;\n y: number;\n}\n\ninterface MenuPlacement {\n anchorDirection: \"up\" | \"down\";\n anchorX: number;\n anchorY: number;\n left: number;\n maxHeight: number | undefined;\n maxWidth: number | undefined;\n measured: boolean;\n top: number;\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\nfunction createInitialMenuPlacement(\n position: MenuPosition,\n direction: \"up\" | \"down\",\n): MenuPlacement {\n return {\n anchorDirection: direction,\n anchorX: position.x,\n anchorY: position.y,\n left: position.x,\n maxHeight: undefined,\n maxWidth: undefined,\n measured: false,\n top: position.y,\n };\n}\n\nfunction placeMenuInViewport(input: {\n direction: \"up\" | \"down\";\n height: number;\n position: MenuPosition;\n viewportHeight: number;\n viewportWidth: number;\n width: number;\n}): MenuPlacement {\n const availableWidth = Math.max(\n 0,\n input.viewportWidth - MENU_VIEWPORT_MARGIN_PX * 2,\n );\n const availableHeight = Math.max(\n 0,\n input.viewportHeight - MENU_VIEWPORT_MARGIN_PX * 2,\n );\n const boundedWidth = Math.min(input.width, availableWidth);\n const boundedHeight = Math.min(input.height, availableHeight);\n const maxLeft = Math.max(\n MENU_VIEWPORT_MARGIN_PX,\n input.viewportWidth - MENU_VIEWPORT_MARGIN_PX - boundedWidth,\n );\n const maxTop = Math.max(\n MENU_VIEWPORT_MARGIN_PX,\n input.viewportHeight - MENU_VIEWPORT_MARGIN_PX - boundedHeight,\n );\n const preferredTop =\n input.direction === \"up\"\n ? input.position.y - boundedHeight\n : input.position.y;\n\n return {\n anchorDirection: input.direction,\n anchorX: input.position.x,\n anchorY: input.position.y,\n left: clamp(input.position.x, MENU_VIEWPORT_MARGIN_PX, maxLeft),\n maxHeight: availableHeight > 0 ? availableHeight : undefined,\n maxWidth: availableWidth > 0 ? availableWidth : undefined,\n measured: true,\n top: clamp(preferredTop, MENU_VIEWPORT_MARGIN_PX, maxTop),\n };\n}\n\nexport function Menu({\n position,\n onClose,\n direction = \"up\",\n keyboardNavigation = true,\n children,\n}: PropsWithChildren<{\n position: MenuPosition;\n onClose: () => void;\n direction?: \"up\" | \"down\";\n keyboardNavigation?: boolean;\n}>) {\n const menuRef = useRef<HTMLDivElement>(null);\n useMenuOutsideDismissal(menuRef, onClose);\n const { x, y } = position;\n const [placement, setPlacement] = useState(() =>\n createInitialMenuPlacement(position, direction),\n );\n // Whether anything in the menu scrolls, so the stylesheet can let touch pan\n // it while consuming swipes on a menu that fits (see Menu.css).\n const [scrollable, setScrollable] = useState(false);\n\n // Re-measure after every commit as well as on resize below: children can be\n // swapped or filtered while the menu is open without its box changing size,\n // which moves scrollHeight but not the ResizeObserver. setState bails out\n // when the answer is unchanged.\n useLayoutEffect(() => {\n const menu = menuRef.current;\n if (menu) {\n setScrollable(hasTouchScrollableContent(menu));\n }\n });\n\n useLayoutEffect(() => {\n const menu = menuRef.current;\n if (!menu) {\n return;\n }\n\n const updatePlacement = () => {\n const rect = menu.getBoundingClientRect();\n setPlacement(\n placeMenuInViewport({\n direction,\n height: rect.height,\n position: { x, y },\n viewportHeight: window.innerHeight,\n viewportWidth: window.innerWidth,\n width: rect.width,\n }),\n );\n setScrollable(hasTouchScrollableContent(menu));\n };\n updatePlacement();\n const observer = new ResizeObserver(updatePlacement);\n observer.observe(menu);\n window.addEventListener(\"resize\", updatePlacement);\n return () => {\n observer.disconnect();\n window.removeEventListener(\"resize\", updatePlacement);\n };\n }, [x, y, direction]);\n\n const placementMatchesAnchor =\n placement.measured &&\n placement.anchorX === position.x &&\n placement.anchorY === position.y &&\n placement.anchorDirection === direction;\n useMenuKeyboard(\n menuRef,\n placementMatchesAnchor && keyboardNavigation,\n onClose,\n );\n const menuStyle: CSSProperties = placementMatchesAnchor\n ? {\n left: placement.left,\n maxHeight: placement.maxHeight,\n maxWidth: placement.maxWidth,\n top: placement.top,\n }\n : MEASUREMENT_MENU_STYLE;\n\n return createPortal(\n <div\n ref={menuRef}\n className=\"menu\"\n data-scrollable={scrollable || undefined}\n style={menuStyle}\n tabIndex={-1}\n >\n {children}\n </div>,\n document.body,\n );\n}\n"]}
1
+ {"version":3,"file":"Menu.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/Menu.tsx"],"names":[],"mappings":";AAAA,OAAO,EAIL,UAAU,EACV,SAAS,EACT,cAAc,EACd,eAAe,EACf,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,YAAY,CAAC;AACpB,OAAO,EACL,kBAAkB,EAClB,UAAU,EACV,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAClC,MAAM,sBAAsB,GAAkB;IAC5C,IAAI,EAAE,uBAAuB;IAC7B,aAAa,EAAE,MAAM;IACrB,GAAG,EAAE,uBAAuB;IAC5B,UAAU,EAAE,QAAQ;CACrB,CAAC;AAEF,2EAA2E;AAC3E,2EAA2E;AAC3E,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAEvC,SAAS,SAAS,CAAC,OAAoB;IACrC,OAAO,CACL,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,GAAG,4BAA4B,CAC3E,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,yBAAyB,CAAC,IAAiB;IAClD,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAc,GAAG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\n type RefObject,\n useContext,\n useEffect,\n useEffectEvent,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport \"./Menu.css\";\nimport {\n menuContainsTarget,\n ParentMenu,\n registerMenuParent,\n} from \"./menuOwnership\";\nimport { useMenuKeyboard } from \"./useMenuKeyboard\";\n\nconst MENU_VIEWPORT_MARGIN_PX = 8;\nconst MEASUREMENT_MENU_STYLE: CSSProperties = {\n left: MENU_VIEWPORT_MARGIN_PX,\n pointerEvents: \"none\",\n top: MENU_VIEWPORT_MARGIN_PX,\n visibility: \"hidden\",\n};\n\n// Fractional layout or zoom can report a spurious pixel of overflow; treat\n// that as fitting, since a false positive hands touch panning to the page.\nconst SCROLL_OVERFLOW_TOLERANCE_PX = 1;\n\nfunction overflows(element: HTMLElement): boolean {\n return (\n element.scrollHeight > element.clientHeight + SCROLL_OVERFLOW_TOLERANCE_PX\n );\n}\n\n/**\n * Whether touch should be allowed to pan inside the menu: its own box scrolls,\n * or a descendant scroll container (a select menu's option list) does. The\n * menu box is a scroll container by its stylesheet; descendants qualify by\n * their computed overflow so a plain overflowing block does not count.\n */\nfunction hasTouchScrollableContent(menu: HTMLElement): boolean {\n if (overflows(menu)) {\n return true;\n }\n\n for (const element of Array.from(menu.querySelectorAll<HTMLElement>(\"*\"))) {\n if (!overflows(element)) {\n continue;\n }\n const overflowY = getComputedStyle(element).overflowY;\n if (overflowY === \"auto\" || overflowY === \"scroll\") {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Dismiss the menu on a pointer press or a scroll outside it. The closer is\n * read through an effect event: consumers commonly pass an inline one, and\n * the document listeners should subscribe once, not on every render.\n */\nfunction useMenuOutsideDismissal(\n menuRef: RefObject<HTMLDivElement | null>,\n onClose: () => void,\n): void {\n const close = useEffectEvent(onClose);\n\n useEffect(() => {\n function handleClick(e: MouseEvent) {\n if (menuRef.current && !menuContainsTarget(menuRef.current, e.target)) {\n close();\n }\n }\n document.addEventListener(\"mousedown\", handleClick);\n return () => document.removeEventListener(\"mousedown\", handleClick);\n }, [menuRef]);\n\n // The menu is anchored once, from its trigger's position, so a scroll\n // anywhere else would leave it floating where the trigger used to be. Close\n // it instead. Scrolls inside the menu — its own overflow, or a list it\n // hosts — are the menu working as intended. Capture phase, because scroll\n // events do not bubble. Include any child menus portaled to the body.\n useEffect(() => {\n function handleScroll(e: Event) {\n if (menuRef.current && menuContainsTarget(menuRef.current, e.target)) {\n return;\n }\n close();\n }\n document.addEventListener(\"scroll\", handleScroll, true);\n return () => document.removeEventListener(\"scroll\", handleScroll, true);\n }, [menuRef]);\n}\n\nexport interface MenuPosition {\n x: number;\n y: number;\n}\n\ninterface MenuPlacement {\n anchorDirection: \"up\" | \"down\";\n anchorX: number;\n anchorY: number;\n left: number;\n maxHeight: number | undefined;\n maxWidth: number | undefined;\n measured: boolean;\n top: number;\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\nfunction createInitialMenuPlacement(\n position: MenuPosition,\n direction: \"up\" | \"down\",\n): MenuPlacement {\n return {\n anchorDirection: direction,\n anchorX: position.x,\n anchorY: position.y,\n left: position.x,\n maxHeight: undefined,\n maxWidth: undefined,\n measured: false,\n top: position.y,\n };\n}\n\nfunction placeMenuInViewport(input: {\n direction: \"up\" | \"down\";\n height: number;\n position: MenuPosition;\n viewportHeight: number;\n viewportWidth: number;\n width: number;\n}): MenuPlacement {\n const availableWidth = Math.max(\n 0,\n input.viewportWidth - MENU_VIEWPORT_MARGIN_PX * 2,\n );\n const availableHeight = Math.max(\n 0,\n input.viewportHeight - MENU_VIEWPORT_MARGIN_PX * 2,\n );\n const boundedWidth = Math.min(input.width, availableWidth);\n const boundedHeight = Math.min(input.height, availableHeight);\n const maxLeft = Math.max(\n MENU_VIEWPORT_MARGIN_PX,\n input.viewportWidth - MENU_VIEWPORT_MARGIN_PX - boundedWidth,\n );\n const maxTop = Math.max(\n MENU_VIEWPORT_MARGIN_PX,\n input.viewportHeight - MENU_VIEWPORT_MARGIN_PX - boundedHeight,\n );\n const preferredTop =\n input.direction === \"up\"\n ? input.position.y - boundedHeight\n : input.position.y;\n\n return {\n anchorDirection: input.direction,\n anchorX: input.position.x,\n anchorY: input.position.y,\n left: clamp(input.position.x, MENU_VIEWPORT_MARGIN_PX, maxLeft),\n maxHeight: availableHeight > 0 ? availableHeight : undefined,\n maxWidth: availableWidth > 0 ? availableWidth : undefined,\n measured: true,\n top: clamp(preferredTop, MENU_VIEWPORT_MARGIN_PX, maxTop),\n };\n}\n\nexport function Menu({\n position,\n onClose,\n direction = \"up\",\n keyboardNavigation = true,\n children,\n}: PropsWithChildren<{\n position: MenuPosition;\n onClose: () => void;\n direction?: \"up\" | \"down\";\n keyboardNavigation?: boolean;\n}>) {\n const menuRef = useRef<HTMLDivElement>(null);\n const parent = useContext(ParentMenu);\n useLayoutEffect(() => {\n return parent && menuRef.current\n ? registerMenuParent(menuRef.current, parent)\n : undefined;\n }, [parent]);\n useMenuOutsideDismissal(menuRef, onClose);\n const { x, y } = position;\n const [placement, setPlacement] = useState(() =>\n createInitialMenuPlacement(position, direction),\n );\n // Whether anything in the menu scrolls, so the stylesheet can let touch pan\n // it while consuming swipes on a menu that fits (see Menu.css).\n const [scrollable, setScrollable] = useState(false);\n\n // Re-measure after every commit as well as on resize below: children can be\n // swapped or filtered while the menu is open without its box changing size,\n // which moves scrollHeight but not the ResizeObserver. setState bails out\n // when the answer is unchanged.\n useLayoutEffect(() => {\n const menu = menuRef.current;\n if (menu) {\n setScrollable(hasTouchScrollableContent(menu));\n }\n });\n\n useLayoutEffect(() => {\n const menu = menuRef.current;\n if (!menu) {\n return;\n }\n\n const updatePlacement = () => {\n const rect = menu.getBoundingClientRect();\n setPlacement(\n placeMenuInViewport({\n direction,\n height: rect.height,\n position: { x, y },\n viewportHeight: window.innerHeight,\n viewportWidth: window.innerWidth,\n width: rect.width,\n }),\n );\n setScrollable(hasTouchScrollableContent(menu));\n };\n updatePlacement();\n const observer = new ResizeObserver(updatePlacement);\n observer.observe(menu);\n window.addEventListener(\"resize\", updatePlacement);\n return () => {\n observer.disconnect();\n window.removeEventListener(\"resize\", updatePlacement);\n };\n }, [x, y, direction]);\n\n const placementMatchesAnchor =\n placement.measured &&\n placement.anchorX === position.x &&\n placement.anchorY === position.y &&\n placement.anchorDirection === direction;\n useMenuKeyboard(\n menuRef,\n placementMatchesAnchor && keyboardNavigation,\n onClose,\n );\n const menuStyle: CSSProperties = placementMatchesAnchor\n ? {\n left: placement.left,\n maxHeight: placement.maxHeight,\n maxWidth: placement.maxWidth,\n top: placement.top,\n }\n : MEASUREMENT_MENU_STYLE;\n\n return createPortal(\n <div\n ref={menuRef}\n className=\"menu\"\n data-scrollable={scrollable || undefined}\n style={menuStyle}\n tabIndex={-1}\n >\n <ParentMenu.Provider value={menuRef}>{children}</ParentMenu.Provider>\n </div>,\n document.body,\n );\n}\n"]}
@@ -1,10 +1,10 @@
1
- import type { MouseEventHandler } from "react";
1
+ import type { ButtonHTMLAttributes, MouseEventHandler } from "react";
2
2
  import type { WindowingIcon } from "../icons/windowingIcon.js";
3
- export interface MenuItemProps {
3
+ export interface MenuItemProps extends Pick<ButtonHTMLAttributes<HTMLButtonElement>, "onContextMenu" | "onPointerDown" | "onPointerMove" | "onPointerUp" | "onPointerCancel"> {
4
4
  /** Any icon component, such as a Phosphor or Lucide icon. */
5
5
  icon?: WindowingIcon | undefined;
6
6
  label: string;
7
7
  disabled?: boolean | undefined;
8
8
  onClick: MouseEventHandler<HTMLButtonElement>;
9
9
  }
10
- export declare function MenuItem({ icon: IconComponent, label, disabled, onClick, }: MenuItemProps): import("react").JSX.Element;
10
+ export declare function MenuItem({ icon: IconComponent, label, disabled, onClick, ...buttonProps }: MenuItemProps): import("react").JSX.Element;
package/menu/MenuItem.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- export function MenuItem({ icon: IconComponent, label, disabled, onClick, }) {
3
- return (_jsxs("button", { type: "button", disabled: disabled, onClick: onClick, children: [IconComponent && (_jsx(IconComponent, { "aria-hidden": "true", className: "menu-item-icon", focusable: "false", size: 16 })), _jsx("span", { className: "menu-item-label", children: label })] }));
2
+ export function MenuItem({ icon: IconComponent, label, disabled, onClick, ...buttonProps }) {
3
+ return (_jsxs("button", { ...buttonProps, type: "button", disabled: disabled, onClick: onClick, children: [IconComponent && (_jsx(IconComponent, { "aria-hidden": "true", className: "menu-item-icon", focusable: "false", size: 16 })), _jsx("span", { className: "menu-item-label", children: label })] }));
4
4
  }
5
5
  //# sourceMappingURL=MenuItem.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MenuItem.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/MenuItem.tsx"],"names":[],"mappings":";AAWA,MAAM,UAAU,QAAQ,CAAC,EACvB,IAAI,EAAE,aAAa,EACnB,KAAK,EACL,QAAQ,EACR,OAAO,GACO;IACd,OAAO,CACL,kBAAQ,IAAI,EAAC,QAAQ,EAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,aACvD,aAAa,IAAI,CAChB,KAAC,aAAa,mBACA,MAAM,EAClB,SAAS,EAAC,gBAAgB,EAC1B,SAAS,EAAC,OAAO,EACjB,IAAI,EAAE,EAAE,GACR,CACH,EACD,eAAM,SAAS,EAAC,iBAAiB,YAAE,KAAK,GAAQ,IACzC,CACV,CAAC;AACJ,CAAC","sourcesContent":["import type { MouseEventHandler } from \"react\";\nimport type { WindowingIcon } from \"../icons/windowingIcon\";\n\nexport interface MenuItemProps {\n /** Any icon component, such as a Phosphor or Lucide icon. */\n icon?: WindowingIcon | undefined;\n label: string;\n disabled?: boolean | undefined;\n onClick: MouseEventHandler<HTMLButtonElement>;\n}\n\nexport function MenuItem({\n icon: IconComponent,\n label,\n disabled,\n onClick,\n}: MenuItemProps) {\n return (\n <button type=\"button\" disabled={disabled} onClick={onClick}>\n {IconComponent && (\n <IconComponent\n aria-hidden=\"true\"\n className=\"menu-item-icon\"\n focusable=\"false\"\n size={16}\n />\n )}\n <span className=\"menu-item-label\">{label}</span>\n </button>\n );\n}\n"]}
1
+ {"version":3,"file":"MenuItem.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/MenuItem.tsx"],"names":[],"mappings":";AAmBA,MAAM,UAAU,QAAQ,CAAC,EACvB,IAAI,EAAE,aAAa,EACnB,KAAK,EACL,QAAQ,EACR,OAAO,EACP,GAAG,WAAW,EACA;IACd,OAAO,CACL,qBACM,WAAW,EACf,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,aAEf,aAAa,IAAI,CAChB,KAAC,aAAa,mBACA,MAAM,EAClB,SAAS,EAAC,gBAAgB,EAC1B,SAAS,EAAC,OAAO,EACjB,IAAI,EAAE,EAAE,GACR,CACH,EACD,eAAM,SAAS,EAAC,iBAAiB,YAAE,KAAK,GAAQ,IACzC,CACV,CAAC;AACJ,CAAC","sourcesContent":["import type { ButtonHTMLAttributes, MouseEventHandler } from \"react\";\nimport type { WindowingIcon } from \"../icons/windowingIcon\";\n\nexport interface MenuItemProps\n extends Pick<\n ButtonHTMLAttributes<HTMLButtonElement>,\n | \"onContextMenu\"\n | \"onPointerDown\"\n | \"onPointerMove\"\n | \"onPointerUp\"\n | \"onPointerCancel\"\n > {\n /** Any icon component, such as a Phosphor or Lucide icon. */\n icon?: WindowingIcon | undefined;\n label: string;\n disabled?: boolean | undefined;\n onClick: MouseEventHandler<HTMLButtonElement>;\n}\n\nexport function MenuItem({\n icon: IconComponent,\n label,\n disabled,\n onClick,\n ...buttonProps\n}: MenuItemProps) {\n return (\n <button\n {...buttonProps}\n type=\"button\"\n disabled={disabled}\n onClick={onClick}\n >\n {IconComponent && (\n <IconComponent\n aria-hidden=\"true\"\n className=\"menu-item-icon\"\n focusable=\"false\"\n size={16}\n />\n )}\n <span className=\"menu-item-label\">{label}</span>\n </button>\n );\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import { type RefObject } from "react";
2
+ export declare const ParentMenu: import("react").Context<RefObject<HTMLDivElement | null> | null>;
3
+ export declare function registerMenuParent(menu: HTMLElement, parent: RefObject<HTMLDivElement | null>): () => void;
4
+ export declare function menuContainsTarget(menu: HTMLElement, target: EventTarget | null): boolean;
@@ -0,0 +1,25 @@
1
+ import { createContext } from "react";
2
+ // Nested menus portal to the body. Follow their owner refs when deciding
3
+ // whether a pointer press or scroll happened outside an ancestor menu.
4
+ export const ParentMenu = createContext(null);
5
+ const parents = new WeakMap();
6
+ export function registerMenuParent(menu, parent) {
7
+ parents.set(menu, parent);
8
+ return () => {
9
+ parents.delete(menu);
10
+ };
11
+ }
12
+ export function menuContainsTarget(menu, target) {
13
+ if (!(target instanceof Node))
14
+ return false;
15
+ if (menu.contains(target))
16
+ return true;
17
+ let owner = (target instanceof Element ? target : target.parentElement)?.closest(".menu");
18
+ while (owner) {
19
+ owner = parents.get(owner)?.current;
20
+ if (owner === menu)
21
+ return true;
22
+ }
23
+ return false;
24
+ }
25
+ //# sourceMappingURL=menuOwnership.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"menuOwnership.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/menuOwnership.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkB,MAAM,OAAO,CAAC;AAEtD,yEAAyE;AACzE,uEAAuE;AACvE,MAAM,CAAC,MAAM,UAAU,GACrB,aAAa,CAA0C,IAAI,CAAC,CAAC;AAE/D,MAAM,OAAO,GAAG,IAAI,OAAO,EAA6C,CAAC;AAEzE,MAAM,UAAU,kBAAkB,CAChC,IAAiB,EACjB,MAAwC;IAExC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC1B,OAAO,GAAG,EAAE;QACV,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,IAAiB,EACjB,MAA0B;IAE1B,IAAI,CAAC,CAAC,MAAM,YAAY,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IACvC,IAAI,KAAK,GAAG,CACV,MAAM,YAAY,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAC1D,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,OAAO,KAAK,EAAE,CAAC;QACb,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;QACpC,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;IAClC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { createContext, type RefObject } from \"react\";\n\n// Nested menus portal to the body. Follow their owner refs when deciding\n// whether a pointer press or scroll happened outside an ancestor menu.\nexport const ParentMenu =\n createContext<RefObject<HTMLDivElement | null> | null>(null);\n\nconst parents = new WeakMap<Element, RefObject<HTMLDivElement | null>>();\n\nexport function registerMenuParent(\n menu: HTMLElement,\n parent: RefObject<HTMLDivElement | null>,\n) {\n parents.set(menu, parent);\n return () => {\n parents.delete(menu);\n };\n}\n\nexport function menuContainsTarget(\n menu: HTMLElement,\n target: EventTarget | null,\n): boolean {\n if (!(target instanceof Node)) return false;\n if (menu.contains(target)) return true;\n let owner = (\n target instanceof Element ? target : target.parentElement\n )?.closest(\".menu\");\n while (owner) {\n owner = parents.get(owner)?.current;\n if (owner === menu) return true;\n }\n return false;\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { useEffect, useEffectEvent } from "react";
2
+ import { menuContainsTarget } from "./menuOwnership.js";
2
3
  function nextControl(controls, focused, key) {
3
4
  if (controls.length === 0)
4
5
  return undefined;
@@ -75,7 +76,7 @@ export function useMenuKeyboard(menuRef, ready, onClose) {
75
76
  }
76
77
  function handleMouseDown(event) {
77
78
  dismissedByPointer =
78
- event.target instanceof Node && !menu?.contains(event.target);
79
+ menu !== null && !menuContainsTarget(menu, event.target);
79
80
  }
80
81
  document.addEventListener("mousedown", handleMouseDown, true);
81
82
  document.addEventListener("keydown", handleKeyDown, true);
@@ -1 +1 @@
1
- {"version":3,"file":"useMenuKeyboard.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/useMenuKeyboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAElE,SAAS,WAAW,CAClB,QAAuB,EACvB,OAAuB,EACvB,GAAW;IAEX,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5C,MAAM,KAAK,GAAG,OAAO,YAAY,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9E,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,WAAW;YACd,OAAO,QAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;QACjD,KAAK,SAAS;YACZ,OAAO,QAAQ,CACb,KAAK,GAAG,CAAC;gBACP,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;gBACrB,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,MAAM,CACpD,CAAC;QACJ,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;QACrB,KAAK,KAAK;YACR,OAAO,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACzB;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AA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,EAAE,IAAI,CAAC,CAAC;QAC9D,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC;QAC1D,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,UAAU,EAAE,CAAC;YACtB,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,eAAe,EAAE,IAAI,CAAC,CAAC;YACjE,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC;YAC7D,IACE,CAAC,kBAAkB;gBACnB,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC;oBACpC,QAAQ,CAAC,aAAa,KAAK,QAAQ,CAAC,IAAI,CAAC,EAC3C,CAAC;gBACD,YAAY,EAAE,CAAC;YACjB,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import { type RefObject, useEffect, useEffectEvent } from \"react\";\n\nfunction nextControl(\n controls: HTMLElement[],\n focused: Element | null,\n key: string,\n) {\n if (controls.length === 0) return undefined;\n const index = focused instanceof HTMLElement ? controls.indexOf(focused) : -1;\n switch (key) {\n case \"ArrowDown\":\n return controls[(index + 1) % controls.length];\n case \"ArrowUp\":\n return controls[\n index < 0\n ? controls.length - 1\n : (index - 1 + controls.length) % controls.length\n ];\n case \"Home\":\n return controls[0];\n case \"End\":\n return controls.at(-1);\n default:\n return undefined;\n }\n}\n\nexport function useMenuKeyboard(\n menuRef: RefObject<HTMLDivElement | null>,\n ready: boolean,\n onClose: () => void,\n) {\n const close = useEffectEvent(onClose);\n\n useEffect(() => {\n const menu = menuRef.current;\n if (!ready || !menu) return;\n\n const trigger = document.activeElement;\n let dismissedByPointer = false;\n const items = () =>\n Array.from(\n menu.querySelectorAll<HTMLElement>(\n \":is(button, input[type=checkbox]):not(:disabled):not([hidden])\",\n ),\n );\n const focusFirst = () =>\n (items()[0] ?? menu).focus({ preventScroll: true });\n focusFirst();\n // Startup and sync can replace an action while its menu is open. Recover\n // focus only when that replacement dropped it onto the document body.\n const observer = new MutationObserver(() => {\n if (!dismissedByPointer && document.activeElement === document.body) {\n focusFirst();\n }\n });\n observer.observe(menu, { childList: true, subtree: true });\n\n function restoreFocus() {\n if (trigger instanceof HTMLElement && trigger.isConnected) {\n trigger.focus({ preventScroll: true });\n return document.activeElement === trigger && trigger !== document.body;\n }\n return false;\n }\n\n function handleKeyDown(event: KeyboardEvent) {\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n if (!menu?.contains(document.activeElement)) return;\n if (event.key === \"Escape\" || event.key === \"Tab\") {\n leaveMenu(event);\n return;\n }\n const next = nextControl(items(), document.activeElement, event.key);\n if (next) {\n event.preventDefault();\n event.stopPropagation();\n next.focus();\n }\n }\n\n // Escape returns focus to the trigger; Tab moves on from it natively\n // unless focus could not return there.\n function leaveMenu(event: KeyboardEvent) {\n if (event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n restoreFocus();\n } else if (!restoreFocus()) {\n event.preventDefault();\n }\n close();\n }\n\n function handleMouseDown(event: MouseEvent) {\n dismissedByPointer =\n event.target instanceof Node && !menu?.contains(event.target);\n }\n\n document.addEventListener(\"mousedown\", handleMouseDown, true);\n document.addEventListener(\"keydown\", handleKeyDown, true);\n return () => {\n observer.disconnect();\n document.removeEventListener(\"mousedown\", handleMouseDown, true);\n document.removeEventListener(\"keydown\", handleKeyDown, true);\n if (\n !dismissedByPointer &&\n (menu.contains(document.activeElement) ||\n document.activeElement === document.body)\n ) {\n restoreFocus();\n }\n };\n }, [menuRef, ready]);\n}\n"]}
1
+ {"version":3,"file":"useMenuKeyboard.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/useMenuKeyboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAElE,OAAO,EAAE,k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aAAa,CAAC;oBACpC,QAAQ,CAAC,aAAa,KAAK,QAAQ,CAAC,IAAI,CAAC,EAC3C,CAAC;gBACD,YAAY,EAAE,CAAC;YACjB,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import { type RefObject, useEffect, useEffectEvent } from \"react\";\n\nimport { menuContainsTarget } from \"./menuOwnership\";\n\nfunction nextControl(\n controls: HTMLElement[],\n focused: Element | null,\n key: string,\n) {\n if (controls.length === 0) return undefined;\n const index = focused instanceof HTMLElement ? controls.indexOf(focused) : -1;\n switch (key) {\n case \"ArrowDown\":\n return controls[(index + 1) % controls.length];\n case \"ArrowUp\":\n return controls[\n index < 0\n ? controls.length - 1\n : (index - 1 + controls.length) % controls.length\n ];\n case \"Home\":\n return controls[0];\n case \"End\":\n return controls.at(-1);\n default:\n return undefined;\n }\n}\n\nexport function useMenuKeyboard(\n menuRef: RefObject<HTMLDivElement | null>,\n ready: boolean,\n onClose: () => void,\n) {\n const close = useEffectEvent(onClose);\n\n useEffect(() => {\n const menu = menuRef.current;\n if (!ready || !menu) return;\n\n const trigger = document.activeElement;\n let dismissedByPointer = false;\n const items = () =>\n Array.from(\n menu.querySelectorAll<HTMLElement>(\n \":is(button, input[type=checkbox]):not(:disabled):not([hidden])\",\n ),\n );\n const focusFirst = () =>\n (items()[0] ?? menu).focus({ preventScroll: true });\n focusFirst();\n // Startup and sync can replace an action while its menu is open. Recover\n // focus only when that replacement dropped it onto the document body.\n const observer = new MutationObserver(() => {\n if (!dismissedByPointer && document.activeElement === document.body) {\n focusFirst();\n }\n });\n observer.observe(menu, { childList: true, subtree: true });\n\n function restoreFocus() {\n if (trigger instanceof HTMLElement && trigger.isConnected) {\n trigger.focus({ preventScroll: true });\n return document.activeElement === trigger && trigger !== document.body;\n }\n return false;\n }\n\n function handleKeyDown(event: KeyboardEvent) {\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n if (!menu?.contains(document.activeElement)) return;\n if (event.key === \"Escape\" || event.key === \"Tab\") {\n leaveMenu(event);\n return;\n }\n const next = nextControl(items(), document.activeElement, event.key);\n if (next) {\n event.preventDefault();\n event.stopPropagation();\n next.focus();\n }\n }\n\n // Escape returns focus to the trigger; Tab moves on from it natively\n // unless focus could not return there.\n function leaveMenu(event: KeyboardEvent) {\n if (event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n restoreFocus();\n } else if (!restoreFocus()) {\n event.preventDefault();\n }\n close();\n }\n\n function handleMouseDown(event: MouseEvent) {\n dismissedByPointer =\n menu !== null && !menuContainsTarget(menu, event.target);\n }\n\n document.addEventListener(\"mousedown\", handleMouseDown, true);\n document.addEventListener(\"keydown\", handleKeyDown, true);\n return () => {\n observer.disconnect();\n document.removeEventListener(\"mousedown\", handleMouseDown, true);\n document.removeEventListener(\"keydown\", handleKeyDown, true);\n if (\n !dismissedByPointer &&\n (menu.contains(document.activeElement) ||\n document.activeElement === document.body)\n ) {\n restoreFocus();\n }\n };\n }, [menuRef, ready]);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tearleads/windowing",
3
- "version": "0.2.42",
3
+ "version": "0.2.43",
4
4
  "description": "App-agnostic window management for React: window state, window chrome, and the menu and sidebar primitives it renders with.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -21,6 +21,8 @@
21
21
  /* Borderless rows: the active/hover fill is the only affordance, so the rail
22
22
  reads as a launcher list rather than a stack of buttons. */
23
23
  .routed-pane-nav-link {
24
+ -webkit-touch-callout: none;
25
+ user-select: none;
24
26
  border-radius: var(--app-radius-control);
25
27
  display: flex;
26
28
  align-items: center;
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { SidebarSimpleIcon } from "@phosphor-icons/react/dist/csr/SidebarSimple";
3
- import { useCallback, useEffect, useMemo, useRef, } from "react";
3
+ import { useEffect, useMemo, useRef, } from "react";
4
4
  import { useLauncherNavigationActions, useLauncherNavigationState, } from "../launcher/LauncherNavigationProvider.js";
5
+ import { useLauncherEntryMenu } from "../launcher/useLauncherEntryMenu.js";
5
6
  import { classNames } from "./classNames.js";
6
7
  import { RoutedPanePlacementButton } from "./RoutedPanePlacementButton.js";
7
8
  import { useMobileSheetDrag } from "./useMobileSheetDrag.js";
@@ -30,15 +31,17 @@ function isBrowserHandledNavClick(event) {
30
31
  }
31
32
  function RoutedPaneNavLink({ appId, activeAppId, icon: LinkIcon, label, onNavigate, }) {
32
33
  const { getMiniAppHref, openMiniApp } = useLauncherNavigationActions();
33
- const handleClick = useCallback((event) => {
34
- if (isBrowserHandledNavClick(event)) {
35
- return;
36
- }
37
- event.preventDefault();
34
+ const open = () => {
38
35
  openMiniApp({ appId });
39
36
  onNavigate();
40
- }, [appId, onNavigate, openMiniApp]);
41
- return (_jsxs("a", { "aria-current": activeAppId === appId ? "page" : undefined, className: classNames("routed-pane-nav-link", activeAppId === appId && "routed-pane-nav-link--active"), href: getMiniAppHref(appId), onClick: handleClick, children: [LinkIcon && _jsx(LinkIcon, { "aria-hidden": "true", size: 20 }), _jsx("span", { className: "routed-pane-nav-link-label", children: label })] }));
37
+ };
38
+ const { menu, triggerProps } = useLauncherEntryMenu(LinkIcon, open);
39
+ return (_jsxs(_Fragment, { children: [_jsxs("a", { ...triggerProps, "aria-current": activeAppId === appId ? "page" : undefined, className: classNames("routed-pane-nav-link", activeAppId === appId && "routed-pane-nav-link--active"), href: getMiniAppHref(appId), onClick: (event) => {
40
+ if (isBrowserHandledNavClick(event))
41
+ return;
42
+ event.preventDefault();
43
+ open();
44
+ }, children: [LinkIcon && _jsx(LinkIcon, { "aria-hidden": "true", size: 20 }), _jsx("span", { className: "routed-pane-nav-link-label", children: label })] }), menu] }));
42
45
  }
43
46
  /**
44
47
  * The tablet rail's navigation surface: an icon-and-label link per routed
@@ -1 +1 @@
1
- {"version":3,"file":"RoutedPaneNav.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/routed/RoutedPaneNav.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AACjF,OAAO,EAGL,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,GACP,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,qBAAqB,CAAC;AAE7B,MAAM,CAAC,MAAM,wBAAwB,GAAG,uBAAuB,CAAC;AAChE,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAQxD,yEAAyE;AACzE,SAAS,qBAAqB,CAC5B,MAA6B;IAE7B,MAAM,EAAE,UAAU,EAAE,GAAG,0BAA0B,EAAE,CAAC;IACpD,OAAO,OAAO,CACZ,GAAG,EAAE,CACH,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACvB,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,GAAG;YACR,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;YAChE,CAAC,CAAC,EAAE,CAAC;IACT,CAAC,CAAC,EACJ,CAAC,MAAM,EAAE,UAAU,CAAC,CACrB,CAAC;AACJ,CAAC;AAED,sEAAsE;AACtE,4EAA4E;AAC5E,4CAA4C;AAC5C,SAAS,wBAAwB,CAC/B,KAAyC;IAEzC,OAAO,CACL,KAA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,EACpC,QAAQ,EAAE,yBAAyB,GACnC,IACI,CACT,CAAC;IACJ,CAAC;IAED,OAAO,CACL,8BACG,UAAU,IAAI,CACb,+BACa,YAAY,EACvB,SAAS,EAAC,mBAAmB,EAC7B,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,aAAa,GACtB,CACH,EACD,gCACe,CAAC,UAAU,EACxB,SAAS,EAAC,mBAAmB,EAC7B,GAAG,EAAE,QAAQ,mBACE,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,eAC/C,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EACxC,EAAE,EAAE,oBAAoB,EACxB,KAAK,EACH,UAAU,IAAI,eAAe,CAAC,UAAU,GAAG,CAAC;oBAC1C,CAAC,CAAC,EAAE,SAAS,EAAE,cAAc,eAAe,CAAC,UAAU,KAAK,EAAE;oBAC9D,CAAC,CAAC,SAAS,aAGf,eAAK,SAAS,EAAC,0BAA0B,aACvC,KAAC,2BAA2B,IAC1B,QAAQ,EAAE,eAAe,CAAC,QAAQ,EAClC,OAAO,EAAE,eAAe,CAAC,WAAW,EACpC,aAAa,EAAE,eAAe,CAAC,iBAAiB,GAChD,EACD,IAAI,KAAK,QAAQ,IAAI,CACpB,KAAC,yBAAyB,IACxB,iBAAiB,EAAE,iBAAiB,EACpC,QAAQ,EAAE,yBAAyB,GACnC,CACH,IACG,EACN,KAAC,mBAAmB,IAClB,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,aAAa,GACzB,IACI,IACP,CACJ,CAAC;AACJ,CAAC","sourcesContent":["import { SidebarSimpleIcon } from \"@phosphor-icons/react/dist/csr/SidebarSimple\";\nimport {\n type MouseEvent as ReactMouseEvent,\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport type { WindowingIcon } from \"../icons/windowingIcon\";\nimport {\n useLauncherNavigationActions,\n useLauncherNavigationState,\n} from \"../launcher/LauncherNavigationProvider\";\nimport type { RoutedLayoutTier } from \"../launcher/useRoutedLayoutTier\";\nimport { classNames } from \"./classNames\";\nimport type { LauncherPlacement } from \"./launcherPlacement\";\nimport { RoutedPanePlacementButton } from \"./RoutedPanePlacementButton\";\nimport { useMobileSheetDrag } from \"./useMobileSheetDrag\";\nimport \"./RoutedPaneNav.css\";\n\nexport const ROUTED_PANE_NAV_PANEL_ID = \"routed-pane-nav-panel\";\nexport const ROUTED_PANE_SHEET_ID = \"routed-pane-sheet\";\n\ninterface RoutedPaneNavItem {\n appId: string;\n icon: WindowingIcon | undefined;\n label: string;\n}\n\n// The launcher entries, in the order given, labeled from the definition.\nfunction useRoutedPaneNavItems(\n appIds: ReadonlyArray<string>,\n): ReadonlyArray<RoutedPaneNavItem> {\n const { definition } = useLauncherNavigationState();\n return useMemo(\n () =>\n appIds.flatMap((appId) => {\n const app = definition.apps[appId];\n return app\n ? [{ appId, icon: app.icon, label: app.iconLabel ?? app.title }]\n : [];\n }),\n [appIds, definition],\n );\n}\n\n// Let the browser handle modified clicks (Cmd/Ctrl/Shift/Alt + click,\n// middle-click) so the href still opens in a new tab/window; only intercept\n// a plain left-click for in-app navigation.\nfunction isBrowserHandledNavClick(\n event: ReactMouseEvent<HTMLAnchorElement>,\n): boolean {\n return (\n event.button !== 0 ||\n event.metaKey ||\n event.ctrlKey ||\n event.shiftKey ||\n event.altKey\n );\n}\n\nfunction RoutedPaneNavLink({\n appId,\n activeAppId,\n icon: LinkIcon,\n label,\n onNavigate,\n}: {\n appId: string;\n activeAppId: string;\n icon: WindowingIcon | undefined;\n label: string;\n onNavigate: () => void;\n}) {\n const { getMiniAppHref, openMiniApp } = useLauncherNavigationActions();\n const handleClick = useCallback(\n (event: ReactMouseEvent<HTMLAnchorElement>) => {\n if (isBrowserHandledNavClick(event)) {\n return;\n }\n event.preventDefault();\n openMiniApp({ appId });\n onNavigate();\n },\n [appId, onNavigate, openMiniApp],\n );\n\n return (\n <a\n aria-current={activeAppId === appId ? \"page\" : undefined}\n className={classNames(\n \"routed-pane-nav-link\",\n activeAppId === appId && \"routed-pane-nav-link--active\",\n )}\n href={getMiniAppHref(appId)}\n onClick={handleClick}\n >\n {LinkIcon && <LinkIcon aria-hidden=\"true\" size={20} />}\n <span className=\"routed-pane-nav-link-label\">{label}</span>\n </a>\n );\n}\n\n/**\n * The tablet rail's navigation surface: an icon-and-label link per routed\n * mini-app. System commands and per-app file/view actions belong to the app bar\n * toolbar at the top of the shell.\n */\nfunction RoutedPaneNavPanel({\n activeAppId,\n appIds,\n id,\n onNavigate,\n}: {\n activeAppId: string;\n appIds: ReadonlyArray<string>;\n id: string;\n onNavigate: () => void;\n}) {\n const visibleNavItems = useRoutedPaneNavItems(appIds);\n return (\n <nav aria-label=\"Apps\" className=\"routed-pane-nav-panel\" id={id}>\n {visibleNavItems.map(({ appId, icon, label }) => (\n <RoutedPaneNavLink\n key={appId}\n activeAppId={activeAppId}\n appId={appId}\n icon={icon}\n label={label}\n onNavigate={onNavigate}\n />\n ))}\n </nav>\n );\n}\n\nfunction RoutedPaneRailToggle({\n expanded,\n onToggle,\n}: {\n expanded: boolean;\n onToggle: () => void;\n}) {\n const label = expanded\n ? \"Collapse navigation rail\"\n : \"Expand navigation rail\";\n\n return (\n <button\n aria-controls={expanded ? ROUTED_PANE_NAV_PANEL_ID : undefined}\n aria-expanded={expanded}\n aria-label={label}\n className=\"routed-pane-iconbutton routed-pane-rail-toggle\"\n title={label}\n type=\"button\"\n onClick={onToggle}\n >\n <SidebarSimpleIcon aria-hidden=\"true\" size={18} />\n </button>\n );\n}\n\nfunction RoutedPaneMobileNavTile({\n active,\n href,\n icon: TileIcon,\n label,\n onSelect,\n}: {\n active: boolean;\n href: string;\n icon: WindowingIcon | undefined;\n label: string;\n onSelect: () => void;\n}) {\n return (\n <a\n aria-current={active ? \"page\" : undefined}\n className={classNames(\n \"routed-pane-sheet-tile\",\n active && \"routed-pane-sheet-tile--active\",\n )}\n href={href}\n onClick={(event) => {\n if (isBrowserHandledNavClick(event)) {\n return;\n }\n event.preventDefault();\n onSelect();\n }}\n >\n {TileIcon && <TileIcon aria-hidden=\"true\" size={32} />}\n <span className=\"routed-pane-sheet-tile-label\">{label}</span>\n </a>\n );\n}\n\n/**\n * The bottom-sheet navigation: every routed mini-app as a grid of square\n * icon-and-label tiles (styled after Explorer's New Document screen). Like the\n * tablet rail it carries no per-app contextual actions. Selecting a tile\n * navigates and dismisses.\n */\nfunction RoutedPaneMobileNav({\n activeAppId,\n appIds,\n onNavigate,\n}: {\n activeAppId: string;\n appIds: ReadonlyArray<string>;\n onNavigate: () => void;\n}) {\n const { getMiniAppHref, openMiniApp } = useLauncherNavigationActions();\n const visibleNavItems = useRoutedPaneNavItems(appIds);\n\n return (\n <nav aria-label=\"Apps\" className=\"routed-pane-sheet-grid\">\n {visibleNavItems.map(({ appId, icon, label }) => (\n <RoutedPaneMobileNavTile\n key={appId}\n active={activeAppId === appId}\n href={getMiniAppHref(appId)}\n icon={icon}\n label={label}\n onSelect={() => {\n openMiniApp({ appId });\n onNavigate();\n }}\n />\n ))}\n </nav>\n );\n}\n\nfunction RoutedPaneMobileSheetHandle({\n dragging,\n onClick,\n onPointerDown,\n}: {\n dragging: boolean;\n onClick: (event: ReactMouseEvent<HTMLButtonElement>) => void;\n onPointerDown: (event: ReactPointerEvent<HTMLButtonElement>) => void;\n}) {\n return (\n <button\n aria-label=\"Dismiss menu\"\n className=\"routed-pane-sheet-handle\"\n data-dragging={dragging ? \"true\" : \"false\"}\n type=\"button\"\n onClick={onClick}\n onPointerDown={onPointerDown}\n >\n <span aria-hidden=\"true\" />\n </button>\n );\n}\n\n/**\n * The navigation surface in its tier-appropriate container: a persistent\n * `<aside>` rail in tablet side mode, or a bottom sheet of launcher tiles (plus\n * dismiss scrim) on mobile and in tablet bottom mode.\n */\nexport function RoutedPaneNav({\n activeAppId,\n appIds,\n drawerOpen,\n launcherPlacement,\n onCloseDrawer,\n onNavigateRail,\n onToggleLauncherPlacement,\n onToggleRail,\n railExpanded,\n tier,\n}: {\n activeAppId: string;\n appIds: ReadonlyArray<string>;\n drawerOpen: boolean;\n launcherPlacement: LauncherPlacement;\n onCloseDrawer: () => void;\n onNavigateRail: () => void;\n onToggleLauncherPlacement: () => void;\n onToggleRail: () => void;\n railExpanded: boolean;\n tier: RoutedLayoutTier;\n}) {\n const sheetRef = useRef<HTMLElement>(null);\n useEffect(() => {\n if (drawerOpen && (tier === \"mobile\" || launcherPlacement === \"bottom\")) {\n const sheet = sheetRef.current;\n const tile = sheet?.querySelector<HTMLElement>(\n '.routed-pane-sheet-tile[aria-current=\"page\"]',\n );\n (\n tile ?? sheet?.querySelector<HTMLElement>(\".routed-pane-sheet-tile\")\n )?.focus();\n }\n }, [drawerOpen, launcherPlacement, tier]);\n\n const mobileSheetDrag = useMobileSheetDrag({\n drawerOpen:\n (tier === \"mobile\" || launcherPlacement === \"bottom\") && drawerOpen,\n onClose: onCloseDrawer,\n });\n\n if (tier === \"tablet\" && launcherPlacement === \"side\") {\n return (\n <aside\n className={classNames(\n \"routed-pane-rail\",\n !railExpanded && \"routed-pane-rail--collapsed\",\n )}\n data-state={railExpanded ? \"open\" : \"closed\"}\n >\n <RoutedPaneRailToggle expanded={railExpanded} onToggle={onToggleRail} />\n {railExpanded && (\n <RoutedPaneNavPanel\n activeAppId={activeAppId}\n appIds={appIds}\n id={ROUTED_PANE_NAV_PANEL_ID}\n onNavigate={onNavigateRail}\n />\n )}\n <RoutedPanePlacementButton\n launcherPlacement={launcherPlacement}\n onToggle={onToggleLauncherPlacement}\n />\n </aside>\n );\n }\n\n return (\n <>\n {drawerOpen && (\n <button\n aria-label=\"Close menu\"\n className=\"routed-pane-scrim\"\n type=\"button\"\n onClick={onCloseDrawer}\n />\n )}\n <aside\n aria-hidden={!drawerOpen}\n className=\"routed-pane-sheet\"\n ref={sheetRef}\n data-dragging={mobileSheetDrag.dragging ? \"true\" : \"false\"}\n data-open={drawerOpen ? \"true\" : \"false\"}\n id={ROUTED_PANE_SHEET_ID}\n style={\n drawerOpen && mobileSheetDrag.dragOffset > 0\n ? { transform: `translateY(${mobileSheetDrag.dragOffset}px)` }\n : undefined\n }\n >\n <div className=\"routed-pane-sheet-header\">\n <RoutedPaneMobileSheetHandle\n dragging={mobileSheetDrag.dragging}\n onClick={mobileSheetDrag.handleClick}\n onPointerDown={mobileSheetDrag.handlePointerDown}\n />\n {tier === \"tablet\" && (\n <RoutedPanePlacementButton\n launcherPlacement={launcherPlacement}\n onToggle={onToggleLauncherPlacement}\n />\n )}\n </div>\n <RoutedPaneMobileNav\n activeAppId={activeAppId}\n appIds={appIds}\n onNavigate={onCloseDrawer}\n />\n </aside>\n </>\n );\n}\n"]}
1
+ {"version":3,"file":"RoutedPaneNav.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/routed/RoutedPaneNav.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AACjF,OAAO,EAGL,SAAS,EACT,OAAO,EACP,MAAM,GACP,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,qBAAqB,CAAC;AAE7B,MAAM,CAAC,MAAM,wBAAwB,GAAG,uBAAuB,CAAC;AAChE,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAQxD,yEAAyE;AACzE,SAAS,qBAAqB,CAC5B,MAA6B;IAE7B,MAAM,EAAE,UAAU,EAAE,GAAG,0BAA0B,EAAE,CAA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,0BAA0B,aACvC,KAAC,2BAA2B,IAC1B,QAAQ,EAAE,eAAe,CAAC,QAAQ,EAClC,OAAO,EAAE,eAAe,CAAC,WAAW,EACpC,aAAa,EAAE,eAAe,CAAC,iBAAiB,GAChD,EACD,IAAI,KAAK,QAAQ,IAAI,CACpB,KAAC,yBAAyB,IACxB,iBAAiB,EAAE,iBAAiB,EACpC,QAAQ,EAAE,yBAAyB,GACnC,CACH,IACG,EACN,KAAC,mBAAmB,IAClB,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,aAAa,GACzB,IACI,IACP,CACJ,CAAC;AACJ,CAAC","sourcesContent":["import { SidebarSimpleIcon } from \"@phosphor-icons/react/dist/csr/SidebarSimple\";\nimport {\n type MouseEvent as ReactMouseEvent,\n type PointerEvent as ReactPointerEvent,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport type { WindowingIcon } from \"../icons/windowingIcon\";\nimport {\n useLauncherNavigationActions,\n useLauncherNavigationState,\n} from \"../launcher/LauncherNavigationProvider\";\nimport { useLauncherEntryMenu } from \"../launcher/useLauncherEntryMenu\";\nimport type { RoutedLayoutTier } from \"../launcher/useRoutedLayoutTier\";\nimport { classNames } from \"./classNames\";\nimport type { LauncherPlacement } from \"./launcherPlacement\";\nimport { RoutedPanePlacementButton } from \"./RoutedPanePlacementButton\";\nimport { useMobileSheetDrag } from \"./useMobileSheetDrag\";\nimport \"./RoutedPaneNav.css\";\n\nexport const ROUTED_PANE_NAV_PANEL_ID = \"routed-pane-nav-panel\";\nexport const ROUTED_PANE_SHEET_ID = \"routed-pane-sheet\";\n\ninterface RoutedPaneNavItem {\n appId: string;\n icon: WindowingIcon | undefined;\n label: string;\n}\n\n// The launcher entries, in the order given, labeled from the definition.\nfunction useRoutedPaneNavItems(\n appIds: ReadonlyArray<string>,\n): ReadonlyArray<RoutedPaneNavItem> {\n const { definition } = useLauncherNavigationState();\n return useMemo(\n () =>\n appIds.flatMap((appId) => {\n const app = definition.apps[appId];\n return app\n ? [{ appId, icon: app.icon, label: app.iconLabel ?? app.title }]\n : [];\n }),\n [appIds, definition],\n );\n}\n\n// Let the browser handle modified clicks (Cmd/Ctrl/Shift/Alt + click,\n// middle-click) so the href still opens in a new tab/window; only intercept\n// a plain left-click for in-app navigation.\nfunction isBrowserHandledNavClick(\n event: ReactMouseEvent<HTMLAnchorElement>,\n): boolean {\n return (\n event.button !== 0 ||\n event.metaKey ||\n event.ctrlKey ||\n event.shiftKey ||\n event.altKey\n );\n}\n\nfunction RoutedPaneNavLink({\n appId,\n activeAppId,\n icon: LinkIcon,\n label,\n onNavigate,\n}: {\n appId: string;\n activeAppId: string;\n icon: WindowingIcon | undefined;\n label: string;\n onNavigate: () => void;\n}) {\n const { getMiniAppHref, openMiniApp } = useLauncherNavigationActions();\n const open = () => {\n openMiniApp({ appId });\n onNavigate();\n };\n const { menu, triggerProps } = useLauncherEntryMenu(LinkIcon, open);\n\n return (\n <>\n <a\n {...triggerProps}\n aria-current={activeAppId === appId ? \"page\" : undefined}\n className={classNames(\n \"routed-pane-nav-link\",\n activeAppId === appId && \"routed-pane-nav-link--active\",\n )}\n href={getMiniAppHref(appId)}\n onClick={(event) => {\n if (isBrowserHandledNavClick(event)) return;\n event.preventDefault();\n open();\n }}\n >\n {LinkIcon && <LinkIcon aria-hidden=\"true\" size={20} />}\n <span className=\"routed-pane-nav-link-label\">{label}</span>\n </a>\n {menu}\n </>\n );\n}\n\n/**\n * The tablet rail's navigation surface: an icon-and-label link per routed\n * mini-app. System commands and per-app file/view actions belong to the app bar\n * toolbar at the top of the shell.\n */\nfunction RoutedPaneNavPanel({\n activeAppId,\n appIds,\n id,\n onNavigate,\n}: {\n activeAppId: string;\n appIds: ReadonlyArray<string>;\n id: string;\n onNavigate: () => void;\n}) {\n const visibleNavItems = useRoutedPaneNavItems(appIds);\n return (\n <nav aria-label=\"Apps\" className=\"routed-pane-nav-panel\" id={id}>\n {visibleNavItems.map(({ appId, icon, label }) => (\n <RoutedPaneNavLink\n key={appId}\n activeAppId={activeAppId}\n appId={appId}\n icon={icon}\n label={label}\n onNavigate={onNavigate}\n />\n ))}\n </nav>\n );\n}\n\nfunction RoutedPaneRailToggle({\n expanded,\n onToggle,\n}: {\n expanded: boolean;\n onToggle: () => void;\n}) {\n const label = expanded\n ? \"Collapse navigation rail\"\n : \"Expand navigation rail\";\n\n return (\n <button\n aria-controls={expanded ? ROUTED_PANE_NAV_PANEL_ID : undefined}\n aria-expanded={expanded}\n aria-label={label}\n className=\"routed-pane-iconbutton routed-pane-rail-toggle\"\n title={label}\n type=\"button\"\n onClick={onToggle}\n >\n <SidebarSimpleIcon aria-hidden=\"true\" size={18} />\n </button>\n );\n}\n\nfunction RoutedPaneMobileNavTile({\n active,\n href,\n icon: TileIcon,\n label,\n onSelect,\n}: {\n active: boolean;\n href: string;\n icon: WindowingIcon | undefined;\n label: string;\n onSelect: () => void;\n}) {\n return (\n <a\n aria-current={active ? \"page\" : undefined}\n className={classNames(\n \"routed-pane-sheet-tile\",\n active && \"routed-pane-sheet-tile--active\",\n )}\n href={href}\n onClick={(event) => {\n if (isBrowserHandledNavClick(event)) {\n return;\n }\n event.preventDefault();\n onSelect();\n }}\n >\n {TileIcon && <TileIcon aria-hidden=\"true\" size={32} />}\n <span className=\"routed-pane-sheet-tile-label\">{label}</span>\n </a>\n );\n}\n\n/**\n * The bottom-sheet navigation: every routed mini-app as a grid of square\n * icon-and-label tiles (styled after Explorer's New Document screen). Like the\n * tablet rail it carries no per-app contextual actions. Selecting a tile\n * navigates and dismisses.\n */\nfunction RoutedPaneMobileNav({\n activeAppId,\n appIds,\n onNavigate,\n}: {\n activeAppId: string;\n appIds: ReadonlyArray<string>;\n onNavigate: () => void;\n}) {\n const { getMiniAppHref, openMiniApp } = useLauncherNavigationActions();\n const visibleNavItems = useRoutedPaneNavItems(appIds);\n\n return (\n <nav aria-label=\"Apps\" className=\"routed-pane-sheet-grid\">\n {visibleNavItems.map(({ appId, icon, label }) => (\n <RoutedPaneMobileNavTile\n key={appId}\n active={activeAppId === appId}\n href={getMiniAppHref(appId)}\n icon={icon}\n label={label}\n onSelect={() => {\n openMiniApp({ appId });\n onNavigate();\n }}\n />\n ))}\n </nav>\n );\n}\n\nfunction RoutedPaneMobileSheetHandle({\n dragging,\n onClick,\n onPointerDown,\n}: {\n dragging: boolean;\n onClick: (event: ReactMouseEvent<HTMLButtonElement>) => void;\n onPointerDown: (event: ReactPointerEvent<HTMLButtonElement>) => void;\n}) {\n return (\n <button\n aria-label=\"Dismiss menu\"\n className=\"routed-pane-sheet-handle\"\n data-dragging={dragging ? \"true\" : \"false\"}\n type=\"button\"\n onClick={onClick}\n onPointerDown={onPointerDown}\n >\n <span aria-hidden=\"true\" />\n </button>\n );\n}\n\n/**\n * The navigation surface in its tier-appropriate container: a persistent\n * `<aside>` rail in tablet side mode, or a bottom sheet of launcher tiles (plus\n * dismiss scrim) on mobile and in tablet bottom mode.\n */\nexport function RoutedPaneNav({\n activeAppId,\n appIds,\n drawerOpen,\n launcherPlacement,\n onCloseDrawer,\n onNavigateRail,\n onToggleLauncherPlacement,\n onToggleRail,\n railExpanded,\n tier,\n}: {\n activeAppId: string;\n appIds: ReadonlyArray<string>;\n drawerOpen: boolean;\n launcherPlacement: LauncherPlacement;\n onCloseDrawer: () => void;\n onNavigateRail: () => void;\n onToggleLauncherPlacement: () => void;\n onToggleRail: () => void;\n railExpanded: boolean;\n tier: RoutedLayoutTier;\n}) {\n const sheetRef = useRef<HTMLElement>(null);\n useEffect(() => {\n if (drawerOpen && (tier === \"mobile\" || launcherPlacement === \"bottom\")) {\n const sheet = sheetRef.current;\n const tile = sheet?.querySelector<HTMLElement>(\n '.routed-pane-sheet-tile[aria-current=\"page\"]',\n );\n (\n tile ?? sheet?.querySelector<HTMLElement>(\".routed-pane-sheet-tile\")\n )?.focus();\n }\n }, [drawerOpen, launcherPlacement, tier]);\n\n const mobileSheetDrag = useMobileSheetDrag({\n drawerOpen:\n (tier === \"mobile\" || launcherPlacement === \"bottom\") && drawerOpen,\n onClose: onCloseDrawer,\n });\n\n if (tier === \"tablet\" && launcherPlacement === \"side\") {\n return (\n <aside\n className={classNames(\n \"routed-pane-rail\",\n !railExpanded && \"routed-pane-rail--collapsed\",\n )}\n data-state={railExpanded ? \"open\" : \"closed\"}\n >\n <RoutedPaneRailToggle expanded={railExpanded} onToggle={onToggleRail} />\n {railExpanded && (\n <RoutedPaneNavPanel\n activeAppId={activeAppId}\n appIds={appIds}\n id={ROUTED_PANE_NAV_PANEL_ID}\n onNavigate={onNavigateRail}\n />\n )}\n <RoutedPanePlacementButton\n launcherPlacement={launcherPlacement}\n onToggle={onToggleLauncherPlacement}\n />\n </aside>\n );\n }\n\n return (\n <>\n {drawerOpen && (\n <button\n aria-label=\"Close menu\"\n className=\"routed-pane-scrim\"\n type=\"button\"\n onClick={onCloseDrawer}\n />\n )}\n <aside\n aria-hidden={!drawerOpen}\n className=\"routed-pane-sheet\"\n ref={sheetRef}\n data-dragging={mobileSheetDrag.dragging ? \"true\" : \"false\"}\n data-open={drawerOpen ? \"true\" : \"false\"}\n id={ROUTED_PANE_SHEET_ID}\n style={\n drawerOpen && mobileSheetDrag.dragOffset > 0\n ? { transform: `translateY(${mobileSheetDrag.dragOffset}px)` }\n : undefined\n }\n >\n <div className=\"routed-pane-sheet-header\">\n <RoutedPaneMobileSheetHandle\n dragging={mobileSheetDrag.dragging}\n onClick={mobileSheetDrag.handleClick}\n onPointerDown={mobileSheetDrag.handlePointerDown}\n />\n {tier === \"tablet\" && (\n <RoutedPanePlacementButton\n launcherPlacement={launcherPlacement}\n onToggle={onToggleLauncherPlacement}\n />\n )}\n </div>\n <RoutedPaneMobileNav\n activeAppId={activeAppId}\n appIds={appIds}\n onNavigate={onCloseDrawer}\n />\n </aside>\n </>\n );\n}\n"]}