@tearleads/windowing 0.2.31 → 0.2.32
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/docs/windows.md +4 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/menu/useLongPress.d.ts +29 -0
- package/menu/useLongPress.js +106 -0
- package/menu/useLongPress.js.map +1 -0
- package/package.json +1 -1
- package/window/WindowMenuContext.d.ts +5 -0
- package/window/WindowMenuContext.js +12 -3
- package/window/WindowMenuContext.js.map +1 -1
- package/window/WindowRefreshButton.d.ts +4 -1
- package/window/WindowRefreshButton.js +23 -3
- package/window/WindowRefreshButton.js.map +1 -1
- package/window/windowMenuRegistrations.d.ts +3 -0
- package/window/windowMenuRegistrations.js +5 -0
- package/window/windowMenuRegistrations.js.map +1 -1
package/docs/windows.md
CHANGED
|
@@ -73,6 +73,10 @@ Memoized `buttonProps` forwards `ref`, `aria-expanded`, and `onMouseDown` to
|
|
|
73
73
|
popup triggers. Both toolbars place Refresh last; it also remains in View.
|
|
74
74
|
While a `useWindowRefreshMenuItem` registration reports `refreshing`, Refresh is
|
|
75
75
|
disabled, announced as `aria-busy`, and shows a turning ring instead of its icon.
|
|
76
|
+
A registration that also passes `onCancel` keeps the running Refresh reachable
|
|
77
|
+
but inert to a click: right-click, the context-menu key, or a touch long press
|
|
78
|
+
opens a menu offering Cancel Refresh. `useLongPress` is the touch half of that
|
|
79
|
+
gesture, exported for any element whose `onContextMenu` opens a menu.
|
|
76
80
|
|
|
77
81
|
Windows with an `appId` reserve the toolbar and offer route-history Back.
|
|
78
82
|
With `historyBack={false}`, the row appears when actions register, then stays.
|
package/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export { Menu, type MenuPosition } from "./menu/Menu.js";
|
|
|
26
26
|
export { MenuItem, type MenuItemProps } from "./menu/MenuItem.js";
|
|
27
27
|
export { StartMenu, type StartMenuItem, type StartMenuProps, } from "./menu/StartMenu.js";
|
|
28
28
|
export { type ContextMenuState, useContextMenuPositionState, useContextMenuState, } from "./menu/useContextMenuState.js";
|
|
29
|
+
export { useLongPress } from "./menu/useLongPress.js";
|
|
29
30
|
export { RoutedPane, type RoutedPaneProps } from "./routed/RoutedPane.js";
|
|
30
31
|
export { RoutedPaneOverlayHostProvider, type RoutedPaneOverlayHostValue, useRoutedPaneOverlayHost, } from "./routed/RoutedPaneOverlayHost.js";
|
|
31
32
|
export type { SubscribeKeyboardVisibility } from "./routed/useMobileKeyboardVisible.js";
|
package/index.js
CHANGED
|
@@ -30,6 +30,7 @@ export { Menu } from "./menu/Menu.js";
|
|
|
30
30
|
export { MenuItem } from "./menu/MenuItem.js";
|
|
31
31
|
export { StartMenu, } from "./menu/StartMenu.js";
|
|
32
32
|
export { useContextMenuPositionState, useContextMenuState, } from "./menu/useContextMenuState.js";
|
|
33
|
+
export { useLongPress } from "./menu/useLongPress.js";
|
|
33
34
|
export { RoutedPane } from "./routed/RoutedPane.js";
|
|
34
35
|
export { RoutedPaneOverlayHostProvider, useRoutedPaneOverlayHost, } from "./routed/RoutedPaneOverlayHost.js";
|
|
35
36
|
export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.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,yEAAyE;AACzE,8EAA8E;AAC9E,6EAA6E;AAC7E,iDAAiD;AACjD,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;A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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 and theme switch, the icons the chrome draws, a launcher of\n// mini-apps that shows them in windows or in the routed (iPad / phone) shell,\n// and desktop icons that open them, with a storage adapter for their layout,\n// over a wallpaper chosen in Display Properties.\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 DEFAULT_MINI_APP_POSITION,\n type LauncherNavigationActions,\n LauncherNavigationProvider,\n type LauncherNavigationState,\n type OpenMiniAppRequest,\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 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 { 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 { 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 {\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,yEAAyE;AACzE,8EAA8E;AAC9E,6EAA6E;AAC7E,iDAAiD;AACjD,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,EACL,yBAAyB,EAEzB,0BAA0B,EAG1B,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,2BAA2B,CAAC;AACnC,O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O,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 and theme switch, the icons the chrome draws, a launcher of\n// mini-apps that shows them in windows or in the routed (iPad / phone) shell,\n// and desktop icons that open them, with a storage adapter for their layout,\n// over a wallpaper chosen in Display Properties.\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 DEFAULT_MINI_APP_POSITION,\n type LauncherNavigationActions,\n LauncherNavigationProvider,\n type LauncherNavigationState,\n type OpenMiniAppRequest,\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 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 { 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 {\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,29 @@
|
|
|
1
|
+
import { type PointerEvent as ReactPointerEvent } from "react";
|
|
2
|
+
interface LongPressHandlers {
|
|
3
|
+
onPointerCancel: (event: ReactPointerEvent<HTMLElement>) => void;
|
|
4
|
+
onPointerDown: (event: ReactPointerEvent<HTMLElement>) => void;
|
|
5
|
+
onPointerMove: (event: ReactPointerEvent<HTMLElement>) => void;
|
|
6
|
+
onPointerUp: (event: ReactPointerEvent<HTMLElement>) => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Returns pointer handlers that, when a **touch** pointer is held still for
|
|
10
|
+
* {@link LONG_PRESS_DELAY_MS}, dispatch a native `contextmenu` event on the
|
|
11
|
+
* pressed element at the touch point.
|
|
12
|
+
*
|
|
13
|
+
* Dispatching the real event (rather than calling a handler directly) means the
|
|
14
|
+
* element's existing `onContextMenu` — the same one a right-click triggers —
|
|
15
|
+
* fires with a genuine event, so touch reuses the desktop context-menu path
|
|
16
|
+
* verbatim. Mouse and pen pointers are ignored so right-click stays the desktop
|
|
17
|
+
* affordance.
|
|
18
|
+
*
|
|
19
|
+
* After the long press fires we register a one-shot capturing `click` listener
|
|
20
|
+
* on `window` to swallow the click the browser synthesizes on touch release —
|
|
21
|
+
* `preventDefault()` on `pointerup` does NOT suppress that click per the Pointer
|
|
22
|
+
* Events spec, so without this the element's `onClick` (navigate/select) would
|
|
23
|
+
* also run.
|
|
24
|
+
*
|
|
25
|
+
* Pass `enabled: false` (e.g. when no context-menu handler is wired) to make the
|
|
26
|
+
* returned handlers no-ops.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useLongPress(enabled: boolean): LongPressHandlers;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, } from "react";
|
|
2
|
+
const LONG_PRESS_DELAY_MS = 450;
|
|
3
|
+
/** Cancel the press if the finger drifts past this many px (a scroll, not a hold). */
|
|
4
|
+
const LONG_PRESS_MOVE_TOLERANCE_PX = 10;
|
|
5
|
+
/** Drop the click-suppressor if no synthesized click arrives within this window. */
|
|
6
|
+
const SYNTHESIZED_CLICK_WINDOW_MS = 700;
|
|
7
|
+
/**
|
|
8
|
+
* Returns pointer handlers that, when a **touch** pointer is held still for
|
|
9
|
+
* {@link LONG_PRESS_DELAY_MS}, dispatch a native `contextmenu` event on the
|
|
10
|
+
* pressed element at the touch point.
|
|
11
|
+
*
|
|
12
|
+
* Dispatching the real event (rather than calling a handler directly) means the
|
|
13
|
+
* element's existing `onContextMenu` — the same one a right-click triggers —
|
|
14
|
+
* fires with a genuine event, so touch reuses the desktop context-menu path
|
|
15
|
+
* verbatim. Mouse and pen pointers are ignored so right-click stays the desktop
|
|
16
|
+
* affordance.
|
|
17
|
+
*
|
|
18
|
+
* After the long press fires we register a one-shot capturing `click` listener
|
|
19
|
+
* on `window` to swallow the click the browser synthesizes on touch release —
|
|
20
|
+
* `preventDefault()` on `pointerup` does NOT suppress that click per the Pointer
|
|
21
|
+
* Events spec, so without this the element's `onClick` (navigate/select) would
|
|
22
|
+
* also run.
|
|
23
|
+
*
|
|
24
|
+
* Pass `enabled: false` (e.g. when no context-menu handler is wired) to make the
|
|
25
|
+
* returned handlers no-ops.
|
|
26
|
+
*/
|
|
27
|
+
export function useLongPress(enabled) {
|
|
28
|
+
const timerRef = useRef(null);
|
|
29
|
+
const originRef = useRef(null);
|
|
30
|
+
const removeClickSuppressorRef = useRef(null);
|
|
31
|
+
const clearTimer = useCallback(() => {
|
|
32
|
+
if (timerRef.current !== null) {
|
|
33
|
+
clearTimeout(timerRef.current);
|
|
34
|
+
timerRef.current = null;
|
|
35
|
+
}
|
|
36
|
+
originRef.current = null;
|
|
37
|
+
}, []);
|
|
38
|
+
// Swallow exactly the next click (the one the browser synthesizes from the
|
|
39
|
+
// touch release after a long press) and then detach. A timeout detaches the
|
|
40
|
+
// suppressor if that click never arrives, so a later genuine tap still works.
|
|
41
|
+
const armClickSuppressor = useCallback(() => {
|
|
42
|
+
removeClickSuppressorRef.current?.();
|
|
43
|
+
let fallbackTimer = null;
|
|
44
|
+
const onClickCapture = (clickEvent) => {
|
|
45
|
+
clickEvent.preventDefault();
|
|
46
|
+
clickEvent.stopPropagation();
|
|
47
|
+
removeClickSuppressorRef.current?.();
|
|
48
|
+
};
|
|
49
|
+
const remove = () => {
|
|
50
|
+
window.removeEventListener("click", onClickCapture, true);
|
|
51
|
+
if (fallbackTimer !== null) {
|
|
52
|
+
clearTimeout(fallbackTimer);
|
|
53
|
+
fallbackTimer = null;
|
|
54
|
+
}
|
|
55
|
+
removeClickSuppressorRef.current = null;
|
|
56
|
+
};
|
|
57
|
+
removeClickSuppressorRef.current = remove;
|
|
58
|
+
window.addEventListener("click", onClickCapture, true);
|
|
59
|
+
fallbackTimer = setTimeout(remove, SYNTHESIZED_CLICK_WINDOW_MS);
|
|
60
|
+
}, []);
|
|
61
|
+
// Tear down on unmount, and also when `enabled` flips off mid-press so a
|
|
62
|
+
// scheduled long-press timer / click suppressor never fires after the hook
|
|
63
|
+
// is disabled.
|
|
64
|
+
useEffect(() => () => {
|
|
65
|
+
clearTimer();
|
|
66
|
+
removeClickSuppressorRef.current?.();
|
|
67
|
+
}, [clearTimer, enabled]);
|
|
68
|
+
const onPointerDown = useCallback((event) => {
|
|
69
|
+
if (!enabled || event.pointerType !== "touch") {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
clearTimer();
|
|
73
|
+
originRef.current = { x: event.clientX, y: event.clientY };
|
|
74
|
+
const element = event.currentTarget;
|
|
75
|
+
const clientX = event.clientX;
|
|
76
|
+
const clientY = event.clientY;
|
|
77
|
+
timerRef.current = setTimeout(() => {
|
|
78
|
+
timerRef.current = null;
|
|
79
|
+
armClickSuppressor();
|
|
80
|
+
element.dispatchEvent(new MouseEvent("contextmenu", {
|
|
81
|
+
bubbles: true,
|
|
82
|
+
cancelable: true,
|
|
83
|
+
clientX,
|
|
84
|
+
clientY,
|
|
85
|
+
}));
|
|
86
|
+
}, LONG_PRESS_DELAY_MS);
|
|
87
|
+
}, [armClickSuppressor, clearTimer, enabled]);
|
|
88
|
+
const onPointerMove = useCallback((event) => {
|
|
89
|
+
const origin = originRef.current;
|
|
90
|
+
if (!origin) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const movedTooFar = Math.abs(event.clientX - origin.x) > LONG_PRESS_MOVE_TOLERANCE_PX ||
|
|
94
|
+
Math.abs(event.clientY - origin.y) > LONG_PRESS_MOVE_TOLERANCE_PX;
|
|
95
|
+
if (movedTooFar) {
|
|
96
|
+
clearTimer();
|
|
97
|
+
}
|
|
98
|
+
}, [clearTimer]);
|
|
99
|
+
return {
|
|
100
|
+
onPointerCancel: clearTimer,
|
|
101
|
+
onPointerDown,
|
|
102
|
+
onPointerMove,
|
|
103
|
+
onPointerUp: clearTimer,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=useLongPress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLongPress.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/useLongPress.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,SAAS,EACT,MAAM,GACP,MAAM,OAAO,CAAC;AAEf,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,sFAAsF;AACtF,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,oFAAoF;AACpF,MAAM,2BAA2B,GAAG,GAAG,CAAC;AASxC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC3C,MAAM,QAAQ,GAAG,MAAM,CAAuC,IAAI,CAAC,CAAC;IACpE,MAAM,SAAS,GAAG,MAAM,CAAkC,IAAI,CAAC,CAAC;IAChE,MAAM,wBAAwB,GAAG,MAAM,CAAsB,IAAI,CAAC,CAAC;IAEnE,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE;QAClC,IAAI,QAAQ,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YAC9B,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC/B,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC;QAC1B,CAAC;QACD,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC;IAC3B,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,2EAA2E;IAC3E,4EAA4E;IAC5E,8EAA8E;IAC9E,MAAM,kBAAkB,GAAG,WAAW,CAAC,GAAG,EAAE;QAC1C,wBAAwB,CAAC,OAAO,EAAE,EAAE,CAAC;QAErC,IAAI,aAAa,GAAyC,IAAI,CAAC;QAC/D,MAAM,cAAc,GAAG,CAAC,UAAsB,EAAE,EAAE;YAChD,UAAU,CAAC,cAAc,EAAE,CAAC;Y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AAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC9B,QAAQ,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YACjC,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC;YACxB,kBAAkB,EAAE,CAAC;YACrB,OAAO,CAAC,aAAa,CACnB,IAAI,UAAU,CAAC,aAAa,EAAE;gBAC5B,OAAO,EAAE,IAAI;gBACb,UAAU,EAAE,IAAI;gBAChB,OAAO;gBACP,OAAO;aACR,CAAC,CACH,CAAC;QACJ,CAAC,EAAE,mBAAmB,CAAC,CAAC;IAC1B,CAAC,EACD,CAAC,kBAAkB,EAAE,UAAU,EAAE,OAAO,CAAC,CAC1C,CAAC;IAEF,MAAM,aAAa,GAAG,WAAW,CAC/B,CAAC,KAAqC,EAAE,EAAE;QACxC,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC;QACjC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO;QACT,CAAC;QAED,MAAM,WAAW,GACf,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,4BAA4B;YACjE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,4BAA4B,CAAC;QACpE,IAAI,WAAW,EAAE,CAAC;YAChB,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC,EACD,CAAC,UAAU,CAAC,CACb,CAAC;IAEF,OAAO;QACL,eAAe,EAAE,UAAU;QAC3B,aAAa;QACb,aAAa;QACb,WAAW,EAAE,UAAU;KACxB,CAAC;AACJ,CAAC","sourcesContent":["import {\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\n\nconst LONG_PRESS_DELAY_MS = 450;\n/** Cancel the press if the finger drifts past this many px (a scroll, not a hold). */\nconst LONG_PRESS_MOVE_TOLERANCE_PX = 10;\n/** Drop the click-suppressor if no synthesized click arrives within this window. */\nconst SYNTHESIZED_CLICK_WINDOW_MS = 700;\n\ninterface LongPressHandlers {\n onPointerCancel: (event: ReactPointerEvent<HTMLElement>) => void;\n onPointerDown: (event: ReactPointerEvent<HTMLElement>) => void;\n onPointerMove: (event: ReactPointerEvent<HTMLElement>) => void;\n onPointerUp: (event: ReactPointerEvent<HTMLElement>) => void;\n}\n\n/**\n * Returns pointer handlers that, when a **touch** pointer is held still for\n * {@link LONG_PRESS_DELAY_MS}, dispatch a native `contextmenu` event on the\n * pressed element at the touch point.\n *\n * Dispatching the real event (rather than calling a handler directly) means the\n * element's existing `onContextMenu` — the same one a right-click triggers —\n * fires with a genuine event, so touch reuses the desktop context-menu path\n * verbatim. Mouse and pen pointers are ignored so right-click stays the desktop\n * affordance.\n *\n * After the long press fires we register a one-shot capturing `click` listener\n * on `window` to swallow the click the browser synthesizes on touch release —\n * `preventDefault()` on `pointerup` does NOT suppress that click per the Pointer\n * Events spec, so without this the element's `onClick` (navigate/select) would\n * also run.\n *\n * Pass `enabled: false` (e.g. when no context-menu handler is wired) to make the\n * returned handlers no-ops.\n */\nexport function useLongPress(enabled: boolean): LongPressHandlers {\n const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const originRef = useRef<{ x: number; y: number } | null>(null);\n const removeClickSuppressorRef = useRef<(() => void) | null>(null);\n\n const clearTimer = useCallback(() => {\n if (timerRef.current !== null) {\n clearTimeout(timerRef.current);\n timerRef.current = null;\n }\n originRef.current = null;\n }, []);\n\n // Swallow exactly the next click (the one the browser synthesizes from the\n // touch release after a long press) and then detach. A timeout detaches the\n // suppressor if that click never arrives, so a later genuine tap still works.\n const armClickSuppressor = useCallback(() => {\n removeClickSuppressorRef.current?.();\n\n let fallbackTimer: ReturnType<typeof setTimeout> | null = null;\n const onClickCapture = (clickEvent: MouseEvent) => {\n clickEvent.preventDefault();\n clickEvent.stopPropagation();\n removeClickSuppressorRef.current?.();\n };\n\n const remove = () => {\n window.removeEventListener(\"click\", onClickCapture, true);\n if (fallbackTimer !== null) {\n clearTimeout(fallbackTimer);\n fallbackTimer = null;\n }\n removeClickSuppressorRef.current = null;\n };\n\n removeClickSuppressorRef.current = remove;\n window.addEventListener(\"click\", onClickCapture, true);\n fallbackTimer = setTimeout(remove, SYNTHESIZED_CLICK_WINDOW_MS);\n }, []);\n\n // Tear down on unmount, and also when `enabled` flips off mid-press so a\n // scheduled long-press timer / click suppressor never fires after the hook\n // is disabled.\n useEffect(\n () => () => {\n clearTimer();\n removeClickSuppressorRef.current?.();\n },\n [clearTimer, enabled],\n );\n\n const onPointerDown = useCallback(\n (event: ReactPointerEvent<HTMLElement>) => {\n if (!enabled || event.pointerType !== \"touch\") {\n return;\n }\n\n clearTimer();\n originRef.current = { x: event.clientX, y: event.clientY };\n const element = event.currentTarget;\n const clientX = event.clientX;\n const clientY = event.clientY;\n timerRef.current = setTimeout(() => {\n timerRef.current = null;\n armClickSuppressor();\n element.dispatchEvent(\n new MouseEvent(\"contextmenu\", {\n bubbles: true,\n cancelable: true,\n clientX,\n clientY,\n }),\n );\n }, LONG_PRESS_DELAY_MS);\n },\n [armClickSuppressor, clearTimer, enabled],\n );\n\n const onPointerMove = useCallback(\n (event: ReactPointerEvent<HTMLElement>) => {\n const origin = originRef.current;\n if (!origin) {\n return;\n }\n\n const movedTooFar =\n Math.abs(event.clientX - origin.x) > LONG_PRESS_MOVE_TOLERANCE_PX ||\n Math.abs(event.clientY - origin.y) > LONG_PRESS_MOVE_TOLERANCE_PX;\n if (movedTooFar) {\n clearTimer();\n }\n },\n [clearTimer],\n );\n\n return {\n onPointerCancel: clearTimer,\n onPointerDown,\n onPointerMove,\n onPointerUp: clearTimer,\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tearleads/windowing",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.32",
|
|
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": {
|
|
@@ -6,6 +6,11 @@ import { type WindowRefreshMenuItem } from "./windowMenuRegistrations.js";
|
|
|
6
6
|
interface WindowRefreshMenuItemInput {
|
|
7
7
|
disabled?: boolean;
|
|
8
8
|
label?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Cancels the running refresh. While `refreshing`, the Refresh button
|
|
11
|
+
* offers it in a context menu, by right-click or touch long press.
|
|
12
|
+
*/
|
|
13
|
+
onCancel?: (() => unknown) | undefined;
|
|
9
14
|
onRefresh: () => unknown;
|
|
10
15
|
priority?: number;
|
|
11
16
|
refreshing?: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useContext, useEffect, useMemo, useRef, } from "react";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, } from "react";
|
|
3
3
|
import { useWindowItemRegistration } from "./useWindowItemRegistration.js";
|
|
4
4
|
import { sameWindowItem, selectHighestPriorityItem, useWindowItemRegistry, } from "./useWindowItemRegistry.js";
|
|
5
5
|
import { useWindowToolbarReservationRegistry } from "./useWindowToolbarReservationRegistry.js";
|
|
@@ -14,10 +14,11 @@ function createRegisteredMenuItem(item, onClick) {
|
|
|
14
14
|
priority: item.priority ?? 0,
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
function createRegisteredRefreshMenuItem(item, onRefresh) {
|
|
17
|
+
function createRegisteredRefreshMenuItem(item, onRefresh, onCancel) {
|
|
18
18
|
return {
|
|
19
19
|
disabled: item.disabled ?? false,
|
|
20
20
|
label: item.label ?? REFRESH_LABEL,
|
|
21
|
+
onCancel: item.onCancel ? onCancel : null,
|
|
21
22
|
onRefresh,
|
|
22
23
|
priority: item.priority ?? 0,
|
|
23
24
|
refreshing: item.refreshing ?? false,
|
|
@@ -197,9 +198,17 @@ export function useWindowToolbarReservation(reserve = true) {
|
|
|
197
198
|
}
|
|
198
199
|
export function useWindowRefreshMenuItem(item) {
|
|
199
200
|
const { registerRefreshMenuItem, unregisterRefreshMenuItem } = useContext(WindowMenuContext);
|
|
201
|
+
// The registration compares items by value, so cancel goes through one
|
|
202
|
+
// stable handler that calls the caller's latest callback.
|
|
203
|
+
const onCancel = item?.onCancel ?? null;
|
|
204
|
+
const cancelRef = useRef(onCancel);
|
|
205
|
+
useLayoutEffect(() => {
|
|
206
|
+
cancelRef.current = onCancel;
|
|
207
|
+
}, [onCancel]);
|
|
208
|
+
const handleCancel = useCallback(() => cancelRef.current?.(), []);
|
|
200
209
|
useWindowItemRegistration({
|
|
201
210
|
action: item?.onRefresh ?? null,
|
|
202
|
-
createRegisteredItem: createRegisteredRefreshMenuItem,
|
|
211
|
+
createRegisteredItem: (input, onRefresh) => createRegisteredRefreshMenuItem(input, onRefresh, handleCancel),
|
|
203
212
|
input: item,
|
|
204
213
|
registerItem: registerRefreshMenuItem,
|
|
205
214
|
unregisterItem: unregisterRefreshMenuItem,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WindowMenuContext.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowMenuContext.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAEb,UAAU,EACV,SAAS,EACT,OAAO,EACP,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EACL,cAAc,EACd,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,mCAAmC,EAAE,MAAM,uCAAuC,CAAC;AAC5F,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,8BAA8B,EAC9B,qBAAqB,GAMtB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,aAAa,GAId,MAAM,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CAAC,KAAK,CAAC,CAAC;IAEzC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC;QAEzB,IAAI,OAAO,EAAE,CAAC;YACZ,kBAAkB,CAAC,OAAO,GAAG,IAAI,CAAC;YAClC,0BAA0B,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YACrC,OAAO,GAAG,EAAE,CAAC,4BAA4B,CAAC,EAAE,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC;YAChC,OAAO;QACT,CAAC;QAED,4EAA4E;QAC5E,yEAAyE;QACzE,oEAAoE;QACpE,0BAA0B,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACtC,OAAO,GAAG,EAAE,CAAC,4BAA4B,CAAC,EAAE,CAAC,CAAC;IAChD,CAAC,EAAE,CAAC,OAAO,EAAE,0BAA0B,EAAE,4BAA4B,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,IAAuC;IAEvC,MAAM,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,GAC1D,UAAU,CAAC,iBAAiB,CAAC,CAAC;IAChC,yBAAyB,CAAC;QACxB,MAAM,EAAE,IAAI,EAAE,SAAS,IAAI,IAAI;QAC/B,oBAAoB,EAAE,+BAA+B;QACrD,KAAK,EAAE,IAAI;QACX,YAAY,EAAE,uBAAuB;QACrC,cAAc,EAAE,yBAAyB;KAC1C,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n createContext,\n type PropsWithChildren,\n useContext,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport { useWindowItemRegistration } from \"./useWindowItemRegistration\";\nimport {\n sameWindowItem,\n selectHighestPriorityItem,\n useWindowItemRegistry,\n} from \"./useWindowItemRegistry\";\nimport { useWindowToolbarReservationRegistry } from \"./useWindowToolbarReservationRegistry\";\nimport {\n createBackAction,\n createRegisteredBackAction,\n createRegisteredTitleBarAction,\n createTitleBarActions,\n type RegisteredWindowBackAction,\n type RegisteredWindowTitleBarAction,\n type WindowBackAction,\n type WindowBackActionInput,\n type WindowTitleBarActionInput,\n} from \"./WindowChromeActions\";\nimport type { WindowMenuItem } from \"./WindowMenuBar\";\nimport type { WindowTitleBarAction } from \"./WindowTitleBar\";\nimport {\n createMenuItems,\n createRefreshMenuItem,\n REFRESH_LABEL,\n type RegisteredWindowMenuItem,\n type RegisteredWindowRefreshMenuItem,\n type WindowRefreshMenuItem,\n} from \"./windowMenuRegistrations\";\n\ninterface WindowRefreshMenuItemInput {\n disabled?: boolean;\n label?: string;\n onRefresh: () => unknown;\n priority?: number;\n refreshing?: boolean;\n}\n\ninterface WindowFileMenuItemInput {\n disabled?: boolean;\n id: string;\n label: string;\n onClick: () => unknown;\n priority?: number;\n}\n\nfunction createRegisteredMenuItem(\n item: WindowFileMenuItemInput,\n onClick: () => unknown,\n): RegisteredWindowMenuItem {\n return {\n disabled: item.disabled ?? false,\n id: item.id,\n label: item.label,\n onClick,\n priority: item.priority ?? 0,\n };\n}\n\nfunction createRegisteredRefreshMenuItem(\n item: WindowRefreshMenuItemInput,\n onRefresh: () => unknown,\n): RegisteredWindowRefreshMenuItem {\n return {\n disabled: item.disabled ?? false,\n label: item.label ?? REFRESH_LABEL,\n onRefresh,\n priority: item.priority ?? 0,\n refreshing: item.refreshing ?? false,\n };\n}\n\ninterface WindowMenuContextValue {\n fileMenuItems: WindowMenuItem[];\n viewMenuItems: WindowMenuItem[];\n /**\n * The winning refresh registration, also folded into `viewMenuItems` for the\n * windowed menu bar. Exposed on its own for the Refresh button shared by the\n * windowed toolbar and routed app bar.\n */\n refreshMenuItem: WindowRefreshMenuItem | null;\n titleBarActions: WindowTitleBarAction[];\n backAction: WindowBackAction | null;\n toolbarReserved: boolean;\n toolbarReservationReleased: boolean;\n registerFileMenuItem: (id: object, item: RegisteredWindowMenuItem) => void;\n unregisterFileMenuItem: (id: object) => void;\n registerViewMenuItem: (id: object, item: RegisteredWindowMenuItem) => void;\n unregisterViewMenuItem: (id: object) => void;\n registerTitleBarAction: (\n id: object,\n item: RegisteredWindowTitleBarAction,\n ) => void;\n unregisterTitleBarAction: (id: object) => void;\n registerBackAction: (id: object, item: RegisteredWindowBackAction) => void;\n unregisterBackAction: (id: object) => void;\n registerRefreshMenuItem: (\n id: object,\n item: RegisteredWindowRefreshMenuItem,\n ) => void;\n unregisterRefreshMenuItem: (id: object) => void;\n registerToolbarReservation: (id: object, reserved: boolean) => void;\n unregisterToolbarReservation: (id: object) => void;\n}\n\nconst WindowMenuContext = createContext<WindowMenuContextValue>({\n fileMenuItems: [],\n viewMenuItems: [],\n refreshMenuItem: null,\n titleBarActions: [],\n backAction: null,\n toolbarReserved: false,\n toolbarReservationReleased: false,\n registerFileMenuItem: () => {},\n unregisterFileMenuItem: () => {},\n registerViewMenuItem: () => {},\n unregisterViewMenuItem: () => {},\n registerTitleBarAction: () => {},\n unregisterTitleBarAction: () => {},\n registerBackAction: () => {},\n unregisterBackAction: () => {},\n registerRefreshMenuItem: () => {},\n unregisterRefreshMenuItem: () => {},\n registerToolbarReservation: () => {},\n unregisterToolbarReservation: () => {},\n});\n\nfunction useWindowMenuContextValue(): WindowMenuContextValue {\n const fileMenu =\n useWindowItemRegistry<RegisteredWindowMenuItem>(sameWindowItem);\n const viewMenu =\n useWindowItemRegistry<RegisteredWindowMenuItem>(sameWindowItem);\n const titleBar =\n useWindowItemRegistry<RegisteredWindowTitleBarAction>(sameWindowItem);\n const back =\n useWindowItemRegistry<RegisteredWindowBackAction>(sameWindowItem);\n const refresh =\n useWindowItemRegistry<RegisteredWindowRefreshMenuItem>(sameWindowItem);\n const toolbarReservation = useWindowToolbarReservationRegistry();\n\n const fileMenuItemList = useMemo(\n () => createMenuItems(fileMenu.items),\n [fileMenu.items],\n );\n const refreshMenuItem = useMemo(\n () => createRefreshMenuItem(selectHighestPriorityItem(refresh.items)),\n [refresh.items],\n );\n const viewMenuItemList = useMemo(\n () => [\n ...createMenuItems(viewMenu.items),\n ...(refreshMenuItem ? [refreshMenuItem] : []),\n ],\n [refreshMenuItem, viewMenu.items],\n );\n const titleBarActionList = useMemo(\n () => createTitleBarActions(titleBar.items),\n [titleBar.items],\n );\n const backAction = useMemo(\n () => createBackAction(selectHighestPriorityItem(back.items)),\n [back.items],\n );\n\n const value = useMemo(\n () => ({\n fileMenuItems: fileMenuItemList,\n viewMenuItems: viewMenuItemList,\n refreshMenuItem,\n titleBarActions: titleBarActionList,\n backAction,\n toolbarReserved: toolbarReservation.reserved,\n toolbarReservationReleased: toolbarReservation.released,\n registerFileMenuItem: fileMenu.registerItem,\n unregisterFileMenuItem: fileMenu.unregisterItem,\n registerViewMenuItem: viewMenu.registerItem,\n unregisterViewMenuItem: viewMenu.unregisterItem,\n registerTitleBarAction: titleBar.registerItem,\n unregisterTitleBarAction: titleBar.unregisterItem,\n registerBackAction: back.registerItem,\n unregisterBackAction: back.unregisterItem,\n registerRefreshMenuItem: refresh.registerItem,\n unregisterRefreshMenuItem: refresh.unregisterItem,\n registerToolbarReservation: toolbarReservation.register,\n unregisterToolbarReservation: toolbarReservation.unregister,\n }),\n [\n fileMenuItemList,\n viewMenuItemList,\n refreshMenuItem,\n titleBarActionList,\n backAction,\n toolbarReservation,\n fileMenu.registerItem,\n fileMenu.unregisterItem,\n viewMenu.registerItem,\n viewMenu.unregisterItem,\n titleBar.registerItem,\n titleBar.unregisterItem,\n back.registerItem,\n back.unregisterItem,\n refresh.registerItem,\n refresh.unregisterItem,\n ],\n );\n\n return value;\n}\n\nexport function WindowMenuProvider({ children }: PropsWithChildren) {\n const value = useWindowMenuContextValue();\n\n return (\n <WindowMenuContext.Provider value={value}>\n {children}\n </WindowMenuContext.Provider>\n );\n}\n\nexport function useWindowFileMenuItems(): WindowMenuItem[] {\n return useContext(WindowMenuContext).fileMenuItems;\n}\n\nexport function useWindowViewMenuItems(): WindowMenuItem[] {\n return useContext(WindowMenuContext).viewMenuItems;\n}\n\nexport function useWindowRefreshMenuItemValue(): WindowRefreshMenuItem | null {\n return useContext(WindowMenuContext).refreshMenuItem;\n}\n\nexport function useWindowTitleBarActions(): WindowTitleBarAction[] {\n return useContext(WindowMenuContext).titleBarActions;\n}\n\nexport function useWindowBackActionValue(): WindowBackAction | null {\n return useContext(WindowMenuContext).backAction;\n}\n\nexport function useWindowToolbarReserved(): boolean {\n return useContext(WindowMenuContext).toolbarReserved;\n}\n\nexport function useWindowToolbarReservationReleased(): boolean {\n return useContext(WindowMenuContext).toolbarReservationReleased;\n}\n\nfunction useRegisteredWindowMenuItem(\n item: WindowFileMenuItemInput | null,\n registerMenuItem: (id: object, item: RegisteredWindowMenuItem) => void,\n unregisterMenuItem: (id: object) => void,\n): void {\n useWindowItemRegistration({\n action: item?.onClick ?? null,\n createRegisteredItem: createRegisteredMenuItem,\n input: item,\n registerItem: registerMenuItem,\n unregisterItem: unregisterMenuItem,\n });\n}\n\nexport function useWindowFileMenuItem(\n item: WindowFileMenuItemInput | null,\n): void {\n const { registerFileMenuItem, unregisterFileMenuItem } =\n useContext(WindowMenuContext);\n useRegisteredWindowMenuItem(\n item,\n registerFileMenuItem,\n unregisterFileMenuItem,\n );\n}\n\nexport function useWindowViewMenuItem(\n item: WindowFileMenuItemInput | null,\n): void {\n const { registerViewMenuItem, unregisterViewMenuItem } =\n useContext(WindowMenuContext);\n useRegisteredWindowMenuItem(\n item,\n registerViewMenuItem,\n unregisterViewMenuItem,\n );\n}\n\n/**\n * Registers an action in the current window's toolbar.\n *\n * Keep `icon` and `buttonProps` reference-stable (for example with `useMemo`)\n * so context updates do not continuously re-register the action.\n */\nexport function useWindowTitleBarAction(\n item: WindowTitleBarActionInput | null,\n): void {\n const { registerTitleBarAction, unregisterTitleBarAction } =\n useContext(WindowMenuContext);\n useWindowItemRegistration({\n action: item?.onClick ?? null,\n createRegisteredItem: createRegisteredTitleBarAction,\n input: item,\n registerItem: registerTitleBarAction,\n unregisterItem: unregisterTitleBarAction,\n });\n}\n\nexport function useWindowBackAction(item: WindowBackActionInput | null): void {\n const { registerBackAction, unregisterBackAction } =\n useContext(WindowMenuContext);\n useWindowItemRegistration({\n action: item?.onClick ?? null,\n createRegisteredItem: createRegisteredBackAction,\n input: item,\n registerItem: registerBackAction,\n unregisterItem: unregisterBackAction,\n });\n}\n\n/**\n * Keeps this window's toolbar row reserved (rendered) while the caller is\n * mounted, even when it registers no title-bar or back actions. A mini-app that\n * wants explorer-style chrome on every route — a blank bar on the routes that\n * have no actions rather than a collapsing/reappearing row — calls this once.\n * Pass `reserve = false` to release the reservation without unmounting.\n */\nexport function useWindowToolbarReservation(reserve = true): void {\n const { registerToolbarReservation, unregisterToolbarReservation } =\n useContext(WindowMenuContext);\n const idRef = useRef<object>({});\n const hasEverReservedRef = useRef(false);\n\n useEffect(() => {\n const id = idRef.current;\n\n if (reserve) {\n hasEverReservedRef.current = true;\n registerToolbarReservation(id, true);\n return () => unregisterToolbarReservation(id);\n }\n\n if (!hasEverReservedRef.current) {\n return;\n }\n\n // A caller that previously reserved the row is now explicitly releasing it.\n // This lets WindowToolBar clear its latched blank row while callers that\n // never opted into reservations keep the older latch-once behavior.\n registerToolbarReservation(id, false);\n return () => unregisterToolbarReservation(id);\n }, [reserve, registerToolbarReservation, unregisterToolbarReservation]);\n}\n\nexport function useWindowRefreshMenuItem(\n item: WindowRefreshMenuItemInput | null,\n): void {\n const { registerRefreshMenuItem, unregisterRefreshMenuItem } =\n useContext(WindowMenuContext);\n useWindowItemRegistration({\n action: item?.onRefresh ?? null,\n createRegisteredItem: createRegisteredRefreshMenuItem,\n input: item,\n registerItem: registerRefreshMenuItem,\n unregisterItem: unregisterRefreshMenuItem,\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"WindowMenuContext.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowMenuContext.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAEb,WAAW,EACX,UAAU,EACV,SAAS,EACT,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AAC,CAAC;IAChC,uEAAuE;IACvE,0DAA0D;IAC1D,MAAM,QAAQ,GAAG,IAAI,EAAE,QAAQ,IAAI,IAAI,CAAC;IACxC,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnC,eAAe,CAAC,GAAG,EAAE;QACnB,SAAS,CAAC,OAAO,GAAG,QAAQ,CAAC;IAC/B,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IACf,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAClE,yBAAyB,CAAC;QACxB,MAAM,EAAE,IAAI,EAAE,SAAS,IAAI,IAAI;QAC/B,oBAAoB,EAAE,CAAC,KAAiC,EAAE,SAAS,EAAE,EAAE,CACrE,+BAA+B,CAAC,KAAK,EAAE,SAAS,EAAE,YAAY,CAAC;QACjE,KAAK,EAAE,IAAI;QACX,YAAY,EAAE,uBAAuB;QACrC,cAAc,EAAE,yBAAyB;KAC1C,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n createContext,\n type PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport { useWindowItemRegistration } from \"./useWindowItemRegistration\";\nimport {\n sameWindowItem,\n selectHighestPriorityItem,\n useWindowItemRegistry,\n} from \"./useWindowItemRegistry\";\nimport { useWindowToolbarReservationRegistry } from \"./useWindowToolbarReservationRegistry\";\nimport {\n createBackAction,\n createRegisteredBackAction,\n createRegisteredTitleBarAction,\n createTitleBarActions,\n type RegisteredWindowBackAction,\n type RegisteredWindowTitleBarAction,\n type WindowBackAction,\n type WindowBackActionInput,\n type WindowTitleBarActionInput,\n} from \"./WindowChromeActions\";\nimport type { WindowMenuItem } from \"./WindowMenuBar\";\nimport type { WindowTitleBarAction } from \"./WindowTitleBar\";\nimport {\n createMenuItems,\n createRefreshMenuItem,\n REFRESH_LABEL,\n type RegisteredWindowMenuItem,\n type RegisteredWindowRefreshMenuItem,\n type WindowRefreshMenuItem,\n} from \"./windowMenuRegistrations\";\n\ninterface WindowRefreshMenuItemInput {\n disabled?: boolean;\n label?: string;\n /**\n * Cancels the running refresh. While `refreshing`, the Refresh button\n * offers it in a context menu, by right-click or touch long press.\n */\n onCancel?: (() => unknown) | undefined;\n onRefresh: () => unknown;\n priority?: number;\n refreshing?: boolean;\n}\n\ninterface WindowFileMenuItemInput {\n disabled?: boolean;\n id: string;\n label: string;\n onClick: () => unknown;\n priority?: number;\n}\n\nfunction createRegisteredMenuItem(\n item: WindowFileMenuItemInput,\n onClick: () => unknown,\n): RegisteredWindowMenuItem {\n return {\n disabled: item.disabled ?? false,\n id: item.id,\n label: item.label,\n onClick,\n priority: item.priority ?? 0,\n };\n}\n\nfunction createRegisteredRefreshMenuItem(\n item: WindowRefreshMenuItemInput,\n onRefresh: () => unknown,\n onCancel: (() => unknown) | null,\n): RegisteredWindowRefreshMenuItem {\n return {\n disabled: item.disabled ?? false,\n label: item.label ?? REFRESH_LABEL,\n onCancel: item.onCancel ? onCancel : null,\n onRefresh,\n priority: item.priority ?? 0,\n refreshing: item.refreshing ?? false,\n };\n}\n\ninterface WindowMenuContextValue {\n fileMenuItems: WindowMenuItem[];\n viewMenuItems: WindowMenuItem[];\n /**\n * The winning refresh registration, also folded into `viewMenuItems` for the\n * windowed menu bar. Exposed on its own for the Refresh button shared by the\n * windowed toolbar and routed app bar.\n */\n refreshMenuItem: WindowRefreshMenuItem | null;\n titleBarActions: WindowTitleBarAction[];\n backAction: WindowBackAction | null;\n toolbarReserved: boolean;\n toolbarReservationReleased: boolean;\n registerFileMenuItem: (id: object, item: RegisteredWindowMenuItem) => void;\n unregisterFileMenuItem: (id: object) => void;\n registerViewMenuItem: (id: object, item: RegisteredWindowMenuItem) => void;\n unregisterViewMenuItem: (id: object) => void;\n registerTitleBarAction: (\n id: object,\n item: RegisteredWindowTitleBarAction,\n ) => void;\n unregisterTitleBarAction: (id: object) => void;\n registerBackAction: (id: object, item: RegisteredWindowBackAction) => void;\n unregisterBackAction: (id: object) => void;\n registerRefreshMenuItem: (\n id: object,\n item: RegisteredWindowRefreshMenuItem,\n ) => void;\n unregisterRefreshMenuItem: (id: object) => void;\n registerToolbarReservation: (id: object, reserved: boolean) => void;\n unregisterToolbarReservation: (id: object) => void;\n}\n\nconst WindowMenuContext = createContext<WindowMenuContextValue>({\n fileMenuItems: [],\n viewMenuItems: [],\n refreshMenuItem: null,\n titleBarActions: [],\n backAction: null,\n toolbarReserved: false,\n toolbarReservationReleased: false,\n registerFileMenuItem: () => {},\n unregisterFileMenuItem: () => {},\n registerViewMenuItem: () => {},\n unregisterViewMenuItem: () => {},\n registerTitleBarAction: () => {},\n unregisterTitleBarAction: () => {},\n registerBackAction: () => {},\n unregisterBackAction: () => {},\n registerRefreshMenuItem: () => {},\n unregisterRefreshMenuItem: () => {},\n registerToolbarReservation: () => {},\n unregisterToolbarReservation: () => {},\n});\n\nfunction useWindowMenuContextValue(): WindowMenuContextValue {\n const fileMenu =\n useWindowItemRegistry<RegisteredWindowMenuItem>(sameWindowItem);\n const viewMenu =\n useWindowItemRegistry<RegisteredWindowMenuItem>(sameWindowItem);\n const titleBar =\n useWindowItemRegistry<RegisteredWindowTitleBarAction>(sameWindowItem);\n const back =\n useWindowItemRegistry<RegisteredWindowBackAction>(sameWindowItem);\n const refresh =\n useWindowItemRegistry<RegisteredWindowRefreshMenuItem>(sameWindowItem);\n const toolbarReservation = useWindowToolbarReservationRegistry();\n\n const fileMenuItemList = useMemo(\n () => createMenuItems(fileMenu.items),\n [fileMenu.items],\n );\n const refreshMenuItem = useMemo(\n () => createRefreshMenuItem(selectHighestPriorityItem(refresh.items)),\n [refresh.items],\n );\n const viewMenuItemList = useMemo(\n () => [\n ...createMenuItems(viewMenu.items),\n ...(refreshMenuItem ? [refreshMenuItem] : []),\n ],\n [refreshMenuItem, viewMenu.items],\n );\n const titleBarActionList = useMemo(\n () => createTitleBarActions(titleBar.items),\n [titleBar.items],\n );\n const backAction = useMemo(\n () => createBackAction(selectHighestPriorityItem(back.items)),\n [back.items],\n );\n\n const value = useMemo(\n () => ({\n fileMenuItems: fileMenuItemList,\n viewMenuItems: viewMenuItemList,\n refreshMenuItem,\n titleBarActions: titleBarActionList,\n backAction,\n toolbarReserved: toolbarReservation.reserved,\n toolbarReservationReleased: toolbarReservation.released,\n registerFileMenuItem: fileMenu.registerItem,\n unregisterFileMenuItem: fileMenu.unregisterItem,\n registerViewMenuItem: viewMenu.registerItem,\n unregisterViewMenuItem: viewMenu.unregisterItem,\n registerTitleBarAction: titleBar.registerItem,\n unregisterTitleBarAction: titleBar.unregisterItem,\n registerBackAction: back.registerItem,\n unregisterBackAction: back.unregisterItem,\n registerRefreshMenuItem: refresh.registerItem,\n unregisterRefreshMenuItem: refresh.unregisterItem,\n registerToolbarReservation: toolbarReservation.register,\n unregisterToolbarReservation: toolbarReservation.unregister,\n }),\n [\n fileMenuItemList,\n viewMenuItemList,\n refreshMenuItem,\n titleBarActionList,\n backAction,\n toolbarReservation,\n fileMenu.registerItem,\n fileMenu.unregisterItem,\n viewMenu.registerItem,\n viewMenu.unregisterItem,\n titleBar.registerItem,\n titleBar.unregisterItem,\n back.registerItem,\n back.unregisterItem,\n refresh.registerItem,\n refresh.unregisterItem,\n ],\n );\n\n return value;\n}\n\nexport function WindowMenuProvider({ children }: PropsWithChildren) {\n const value = useWindowMenuContextValue();\n\n return (\n <WindowMenuContext.Provider value={value}>\n {children}\n </WindowMenuContext.Provider>\n );\n}\n\nexport function useWindowFileMenuItems(): WindowMenuItem[] {\n return useContext(WindowMenuContext).fileMenuItems;\n}\n\nexport function useWindowViewMenuItems(): WindowMenuItem[] {\n return useContext(WindowMenuContext).viewMenuItems;\n}\n\nexport function useWindowRefreshMenuItemValue(): WindowRefreshMenuItem | null {\n return useContext(WindowMenuContext).refreshMenuItem;\n}\n\nexport function useWindowTitleBarActions(): WindowTitleBarAction[] {\n return useContext(WindowMenuContext).titleBarActions;\n}\n\nexport function useWindowBackActionValue(): WindowBackAction | null {\n return useContext(WindowMenuContext).backAction;\n}\n\nexport function useWindowToolbarReserved(): boolean {\n return useContext(WindowMenuContext).toolbarReserved;\n}\n\nexport function useWindowToolbarReservationReleased(): boolean {\n return useContext(WindowMenuContext).toolbarReservationReleased;\n}\n\nfunction useRegisteredWindowMenuItem(\n item: WindowFileMenuItemInput | null,\n registerMenuItem: (id: object, item: RegisteredWindowMenuItem) => void,\n unregisterMenuItem: (id: object) => void,\n): void {\n useWindowItemRegistration({\n action: item?.onClick ?? null,\n createRegisteredItem: createRegisteredMenuItem,\n input: item,\n registerItem: registerMenuItem,\n unregisterItem: unregisterMenuItem,\n });\n}\n\nexport function useWindowFileMenuItem(\n item: WindowFileMenuItemInput | null,\n): void {\n const { registerFileMenuItem, unregisterFileMenuItem } =\n useContext(WindowMenuContext);\n useRegisteredWindowMenuItem(\n item,\n registerFileMenuItem,\n unregisterFileMenuItem,\n );\n}\n\nexport function useWindowViewMenuItem(\n item: WindowFileMenuItemInput | null,\n): void {\n const { registerViewMenuItem, unregisterViewMenuItem } =\n useContext(WindowMenuContext);\n useRegisteredWindowMenuItem(\n item,\n registerViewMenuItem,\n unregisterViewMenuItem,\n );\n}\n\n/**\n * Registers an action in the current window's toolbar.\n *\n * Keep `icon` and `buttonProps` reference-stable (for example with `useMemo`)\n * so context updates do not continuously re-register the action.\n */\nexport function useWindowTitleBarAction(\n item: WindowTitleBarActionInput | null,\n): void {\n const { registerTitleBarAction, unregisterTitleBarAction } =\n useContext(WindowMenuContext);\n useWindowItemRegistration({\n action: item?.onClick ?? null,\n createRegisteredItem: createRegisteredTitleBarAction,\n input: item,\n registerItem: registerTitleBarAction,\n unregisterItem: unregisterTitleBarAction,\n });\n}\n\nexport function useWindowBackAction(item: WindowBackActionInput | null): void {\n const { registerBackAction, unregisterBackAction } =\n useContext(WindowMenuContext);\n useWindowItemRegistration({\n action: item?.onClick ?? null,\n createRegisteredItem: createRegisteredBackAction,\n input: item,\n registerItem: registerBackAction,\n unregisterItem: unregisterBackAction,\n });\n}\n\n/**\n * Keeps this window's toolbar row reserved (rendered) while the caller is\n * mounted, even when it registers no title-bar or back actions. A mini-app that\n * wants explorer-style chrome on every route — a blank bar on the routes that\n * have no actions rather than a collapsing/reappearing row — calls this once.\n * Pass `reserve = false` to release the reservation without unmounting.\n */\nexport function useWindowToolbarReservation(reserve = true): void {\n const { registerToolbarReservation, unregisterToolbarReservation } =\n useContext(WindowMenuContext);\n const idRef = useRef<object>({});\n const hasEverReservedRef = useRef(false);\n\n useEffect(() => {\n const id = idRef.current;\n\n if (reserve) {\n hasEverReservedRef.current = true;\n registerToolbarReservation(id, true);\n return () => unregisterToolbarReservation(id);\n }\n\n if (!hasEverReservedRef.current) {\n return;\n }\n\n // A caller that previously reserved the row is now explicitly releasing it.\n // This lets WindowToolBar clear its latched blank row while callers that\n // never opted into reservations keep the older latch-once behavior.\n registerToolbarReservation(id, false);\n return () => unregisterToolbarReservation(id);\n }, [reserve, registerToolbarReservation, unregisterToolbarReservation]);\n}\n\nexport function useWindowRefreshMenuItem(\n item: WindowRefreshMenuItemInput | null,\n): void {\n const { registerRefreshMenuItem, unregisterRefreshMenuItem } =\n useContext(WindowMenuContext);\n // The registration compares items by value, so cancel goes through one\n // stable handler that calls the caller's latest callback.\n const onCancel = item?.onCancel ?? null;\n const cancelRef = useRef(onCancel);\n useLayoutEffect(() => {\n cancelRef.current = onCancel;\n }, [onCancel]);\n const handleCancel = useCallback(() => cancelRef.current?.(), []);\n useWindowItemRegistration({\n action: item?.onRefresh ?? null,\n createRegisteredItem: (input: WindowRefreshMenuItemInput, onRefresh) =>\n createRegisteredRefreshMenuItem(input, onRefresh, handleCancel),\n input: item,\n registerItem: registerRefreshMenuItem,\n unregisterItem: unregisterRefreshMenuItem,\n });\n}\n"]}
|
|
@@ -2,7 +2,10 @@ import type { WindowRefreshMenuItem } from "./windowMenuRegistrations.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* The registered refresh action shared by floating and routed toolbars. While
|
|
4
4
|
* the refresh runs, a turning ring replaces the icon so a long refresh reads
|
|
5
|
-
* as work in progress rather than as a disabled button.
|
|
5
|
+
* as work in progress rather than as a disabled button. When that refresh can
|
|
6
|
+
* be cancelled, the button stays reachable, though inert to a click, and its
|
|
7
|
+
* context menu (right-click, the context-menu key, or a touch long press)
|
|
8
|
+
* offers Cancel Refresh.
|
|
6
9
|
*/
|
|
7
10
|
export declare function WindowRefreshButton({ className, item, }: {
|
|
8
11
|
className: string;
|
|
@@ -1,13 +1,33 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { ArrowsClockwiseIcon } from "@phosphor-icons/react/dist/csr/ArrowsClockwise";
|
|
3
|
+
import { useEffect } from "react";
|
|
3
4
|
import "./WindowRefreshButton.css";
|
|
5
|
+
import { Menu } from "../menu/Menu.js";
|
|
6
|
+
import { MenuItem } from "../menu/MenuItem.js";
|
|
7
|
+
import { useContextMenuState } from "../menu/useContextMenuState.js";
|
|
8
|
+
import { useLongPress } from "../menu/useLongPress.js";
|
|
9
|
+
const CANCEL_HINT = "Right-click or long-press to cancel.";
|
|
4
10
|
/**
|
|
5
11
|
* The registered refresh action shared by floating and routed toolbars. While
|
|
6
12
|
* the refresh runs, a turning ring replaces the icon so a long refresh reads
|
|
7
|
-
* as work in progress rather than as a disabled button.
|
|
13
|
+
* as work in progress rather than as a disabled button. When that refresh can
|
|
14
|
+
* be cancelled, the button stays reachable, though inert to a click, and its
|
|
15
|
+
* context menu (right-click, the context-menu key, or a touch long press)
|
|
16
|
+
* offers Cancel Refresh.
|
|
8
17
|
*/
|
|
9
18
|
export function WindowRefreshButton({ className, item, }) {
|
|
10
|
-
|
|
19
|
+
const cancel = item.onCancel;
|
|
20
|
+
const { closeContextMenu, contextMenu, openContextMenu } = useContextMenuState();
|
|
21
|
+
const longPress = useLongPress(cancel !== null);
|
|
22
|
+
// The refresh can settle while its menu is open; the menu goes with it.
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!cancel)
|
|
25
|
+
closeContextMenu();
|
|
26
|
+
}, [cancel, closeContextMenu]);
|
|
27
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { ...longPress, "aria-busy": item.refreshing, "aria-disabled": cancel ? true : undefined, "aria-haspopup": cancel ? "menu" : undefined, "aria-label": item.label, className: className, disabled: cancel ? false : item.disabled, title: cancel ? `${item.label} ${CANCEL_HINT}` : item.label, type: "button", onClick: cancel ? undefined : item.onClick, onContextMenu: cancel ? (event) => openContextMenu(event, "cancel") : undefined, children: item.refreshing ? (_jsx(RefreshSpinner, {})) : (_jsx(ArrowsClockwiseIcon, { "aria-hidden": true, size: 18 })) }), contextMenu && cancel && (_jsx(Menu, { direction: "down", onClose: closeContextMenu, position: contextMenu.position, children: _jsx(MenuItem, { label: "Cancel Refresh", onClick: () => {
|
|
28
|
+
cancel();
|
|
29
|
+
closeContextMenu();
|
|
30
|
+
} }) }))] }));
|
|
11
31
|
}
|
|
12
32
|
// An open ring on the icon set's 256-unit grid and 16-unit stroke, so each
|
|
13
33
|
// toolbar's icon sizing applies to it exactly as to the icon it replaces.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WindowRefreshButton.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowRefreshButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AACrF,OAAO,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"WindowRefreshButton.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowRefreshButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AACrF,OAAO,EAAE,SA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C,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAC1C,aAAa,EACX,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,YAGjE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CACjB,KAAC,cAAc,KAAG,CACnB,CAAC,CAAC,CAAC,CACF,KAAC,mBAAmB,yBAAa,IAAI,EAAE,EAAE,GAAI,CAC9C,GACM,EACR,WAAW,IAAI,MAAM,IAAI,CACxB,KAAC,IAAI,IACH,SAAS,EAAC,MAAM,EAChB,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,WAAW,CAAC,QAAQ,YAE9B,KAAC,QAAQ,IACP,KAAK,EAAC,gBAAgB,EACtB,OAAO,EAAE,GAAG,EAAE;wBACZ,MAAM,EAAE,CAAC;wBACT,gBAAgB,EAAE,CAAC;oBACrB,CAAC,GACD,GACG,CACR,IACA,CACJ,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,0EAA0E;AAC1E,SAAS,cAAc;IACrB,OAAO,CACL,mCAEE,SAAS,EAAC,wBAAwB,EAClC,MAAM,EAAE,EAAE,EACV,OAAO,EAAC,aAAa,EACrB,KAAK,EAAE,EAAE,YAET,iBACE,EAAE,EAAE,GAAG,EACP,EAAE,EAAE,GAAG,EACP,IAAI,EAAC,MAAM,EACX,UAAU,EAAE,CAAC,EACb,CAAC,EAAE,EAAE,EACL,MAAM,EAAC,cAAc,EACrB,eAAe,EAAC,KAAK,EACrB,aAAa,EAAC,OAAO,EACrB,WAAW,EAAE,EAAE,GACf,GACE,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { ArrowsClockwiseIcon } from \"@phosphor-icons/react/dist/csr/ArrowsClockwise\";\nimport { useEffect } from \"react\";\nimport \"./WindowRefreshButton.css\";\nimport { Menu } from \"../menu/Menu\";\nimport { MenuItem } from \"../menu/MenuItem\";\nimport { useContextMenuState } from \"../menu/useContextMenuState\";\nimport { useLongPress } from \"../menu/useLongPress\";\nimport type { WindowRefreshMenuItem } from \"./windowMenuRegistrations\";\n\nconst CANCEL_HINT = \"Right-click or long-press to cancel.\";\n\n/**\n * The registered refresh action shared by floating and routed toolbars. While\n * the refresh runs, a turning ring replaces the icon so a long refresh reads\n * as work in progress rather than as a disabled button. When that refresh can\n * be cancelled, the button stays reachable, though inert to a click, and its\n * context menu (right-click, the context-menu key, or a touch long press)\n * offers Cancel Refresh.\n */\nexport function WindowRefreshButton({\n className,\n item,\n}: {\n className: string;\n item: WindowRefreshMenuItem;\n}) {\n const cancel = item.onCancel;\n const { closeContextMenu, contextMenu, openContextMenu } =\n useContextMenuState<\"cancel\">();\n const longPress = useLongPress(cancel !== null);\n\n // The refresh can settle while its menu is open; the menu goes with it.\n useEffect(() => {\n if (!cancel) closeContextMenu();\n }, [cancel, closeContextMenu]);\n\n return (\n <>\n <button\n {...longPress}\n aria-busy={item.refreshing}\n aria-disabled={cancel ? true : undefined}\n aria-haspopup={cancel ? \"menu\" : undefined}\n aria-label={item.label}\n className={className}\n disabled={cancel ? false : item.disabled}\n title={cancel ? `${item.label} ${CANCEL_HINT}` : item.label}\n type=\"button\"\n onClick={cancel ? undefined : item.onClick}\n onContextMenu={\n cancel ? (event) => openContextMenu(event, \"cancel\") : undefined\n }\n >\n {item.refreshing ? (\n <RefreshSpinner />\n ) : (\n <ArrowsClockwiseIcon aria-hidden size={18} />\n )}\n </button>\n {contextMenu && cancel && (\n <Menu\n direction=\"down\"\n onClose={closeContextMenu}\n position={contextMenu.position}\n >\n <MenuItem\n label=\"Cancel Refresh\"\n onClick={() => {\n cancel();\n closeContextMenu();\n }}\n />\n </Menu>\n )}\n </>\n );\n}\n\n// An open ring on the icon set's 256-unit grid and 16-unit stroke, so each\n// toolbar's icon sizing applies to it exactly as to the icon it replaces.\nfunction RefreshSpinner() {\n return (\n <svg\n aria-hidden\n className=\"window-refresh-spinner\"\n height={18}\n viewBox=\"0 0 256 256\"\n width={18}\n >\n <circle\n cx={128}\n cy={128}\n fill=\"none\"\n pathLength={4}\n r={96}\n stroke=\"currentColor\"\n strokeDasharray=\"3 1\"\n strokeLinecap=\"round\"\n strokeWidth={16}\n />\n </svg>\n );\n}\n"]}
|
|
@@ -10,12 +10,15 @@ export interface RegisteredWindowMenuItem {
|
|
|
10
10
|
export interface RegisteredWindowRefreshMenuItem {
|
|
11
11
|
disabled: boolean;
|
|
12
12
|
label: string;
|
|
13
|
+
onCancel: (() => unknown) | null;
|
|
13
14
|
onRefresh: () => unknown;
|
|
14
15
|
priority: number;
|
|
15
16
|
refreshing: boolean;
|
|
16
17
|
}
|
|
17
18
|
/** The winning refresh registration as the toolbars and View menu draw it. */
|
|
18
19
|
export interface WindowRefreshMenuItem extends WindowMenuItem {
|
|
20
|
+
/** Set only while a refresh that can be cancelled is running. */
|
|
21
|
+
onCancel: (() => void) | null;
|
|
19
22
|
refreshing: boolean;
|
|
20
23
|
}
|
|
21
24
|
export declare function createMenuItems(items: ReadonlyMap<object, RegisteredWindowMenuItem>): WindowMenuItem[];
|
|
@@ -26,6 +26,11 @@ export function createRefreshMenuItem(item) {
|
|
|
26
26
|
disabled: item.disabled || item.refreshing,
|
|
27
27
|
id: "window-refresh",
|
|
28
28
|
label: item.refreshing ? REFRESHING_LABEL : item.label,
|
|
29
|
+
onCancel: item.refreshing && item.onCancel
|
|
30
|
+
? () => {
|
|
31
|
+
void item.onCancel?.();
|
|
32
|
+
}
|
|
33
|
+
: null,
|
|
29
34
|
onClick: () => {
|
|
30
35
|
void item.onRefresh();
|
|
31
36
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"windowMenuRegistrations.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/windowMenuRegistrations.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AACvC,MAAM,gBAAgB,GAAG,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"windowMenuRegistrations.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/windowMenuRegistrations.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AACvC,MAAM,gBAAgB,GAAG,eAAe,CAAC;AA0BzC,MAAM,UAAU,eAAe,CAC7B,KAAoD;IAEpD,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;SAC9B,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;SACrD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACd,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,OAAO,EAAE,GAAG,EAAE;YACZ,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;QACtB,CAAC;KACF,CAAC,CAAC,CAAC;AACR,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,IAA4C;IAE5C,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU;QAC1C,EAAE,EAAE,gBAAgB;QACpB,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK;QACtD,QAAQ,EACN,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,QAAQ;YAC9B,CAAC,CAAC,GAAG,EAAE;gBACH,KAAK,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;YACzB,CAAC;YACH,CAAC,CAAC,IAAI;QACV,OAAO,EAAE,GAAG,EAAE;YACZ,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;QACxB,CAAC;QACD,UAAU,EAAE,IAAI,CAAC,UAAU;KAC5B,CAAC;AACJ,CAAC","sourcesContent":["import type { WindowMenuItem } from \"./WindowMenuBar\";\n\n/*\n * The shapes a mini-app's menu registration takes, and the pure projections\n * from a registry map to the items a menu bar (or the routed app bar) renders.\n * The React seams — the context, the provider, and the register/read hooks —\n * live in WindowMenuContext.tsx.\n */\n\nexport const REFRESH_LABEL = \"Refresh\";\nconst REFRESHING_LABEL = \"Refreshing...\";\n\nexport interface RegisteredWindowMenuItem {\n disabled: boolean;\n id: string;\n label: string;\n onClick: () => unknown;\n priority: number;\n}\n\nexport interface RegisteredWindowRefreshMenuItem {\n disabled: boolean;\n label: string;\n onCancel: (() => unknown) | null;\n onRefresh: () => unknown;\n priority: number;\n refreshing: boolean;\n}\n\n/** The winning refresh registration as the toolbars and View menu draw it. */\nexport interface WindowRefreshMenuItem extends WindowMenuItem {\n /** Set only while a refresh that can be cancelled is running. */\n onCancel: (() => void) | null;\n refreshing: boolean;\n}\n\nexport function createMenuItems(\n items: ReadonlyMap<object, RegisteredWindowMenuItem>,\n): WindowMenuItem[] {\n return Array.from(items.values())\n .sort((left, right) => right.priority - left.priority)\n .map((item) => ({\n disabled: item.disabled,\n id: item.id,\n label: item.label,\n onClick: () => {\n void item.onClick();\n },\n }));\n}\n\nexport function createRefreshMenuItem(\n item: RegisteredWindowRefreshMenuItem | null,\n): WindowRefreshMenuItem | null {\n if (!item) {\n return null;\n }\n\n return {\n disabled: item.disabled || item.refreshing,\n id: \"window-refresh\",\n label: item.refreshing ? REFRESHING_LABEL : item.label,\n onCancel:\n item.refreshing && item.onCancel\n ? () => {\n void item.onCancel?.();\n }\n : null,\n onClick: () => {\n void item.onRefresh();\n },\n refreshing: item.refreshing,\n };\n}\n"]}
|