@tearleads/windowing 0.2.31 → 0.2.33
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/launcher.md +31 -8
- package/docs/windows.md +4 -0
- package/index.d.ts +3 -1
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/launcher/LauncherNavigationProvider.d.ts +8 -19
- package/launcher/LauncherNavigationProvider.js +18 -31
- package/launcher/LauncherNavigationProvider.js.map +1 -1
- package/launcher/launcherDefinition.d.ts +7 -5
- package/launcher/launcherDefinition.js.map +1 -1
- package/launcher/openMiniAppWindow.d.ts +54 -0
- package/launcher/openMiniAppWindow.js +37 -0
- package/launcher/openMiniAppWindow.js.map +1 -0
- package/launcher/useDefaultWindow.d.ts +4 -1
- package/launcher/useDefaultWindow.js +11 -4
- package/launcher/useDefaultWindow.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/launcher.md
CHANGED
|
@@ -39,7 +39,8 @@ and a `close` callback. Tearleads' footer does this in
|
|
|
39
39
|
A launcher application is a set of mini-apps, defined once and shown either in
|
|
40
40
|
windows on a desktop or one at a time in the routed shell. A
|
|
41
41
|
`LauncherDefinition` lists the apps by id, the order the launchers show them in,
|
|
42
|
-
and the app the routed shell shows at
|
|
42
|
+
the windows the desktop opens on entry, and the app the routed shell shows at
|
|
43
|
+
the root route:
|
|
43
44
|
|
|
44
45
|
```tsx
|
|
45
46
|
import type { LauncherDefinition } from "@tearleads/windowing";
|
|
@@ -58,7 +59,7 @@ const LAUNCHER: LauncherDefinition<"notes" | "contacts"> = {
|
|
|
58
59
|
title: "Notes",
|
|
59
60
|
},
|
|
60
61
|
},
|
|
61
|
-
|
|
62
|
+
defaultWindowAppIds: ["contacts", "notes"],
|
|
62
63
|
homeAppId: "notes",
|
|
63
64
|
order: ["notes", "contacts"],
|
|
64
65
|
};
|
|
@@ -72,12 +73,34 @@ or raises the one already open; in `routed` mode it pushes the app's route,
|
|
|
72
73
|
each window with `MiniAppWindow`, whose `AppBoundary` slot wraps the app (for
|
|
73
74
|
example in an error boundary).
|
|
74
75
|
|
|
75
|
-
Optional `
|
|
76
|
-
including mount
|
|
77
|
-
leaves it empty until the next mode entry. The
|
|
78
|
-
defers that entry while false (e.g. hidden
|
|
79
|
-
already initialized desktop preserves it,
|
|
80
|
-
manage startup yourself; `homeAppId` only sets
|
|
76
|
+
Optional `defaultWindowAppIds` open, in order, on entering an empty windowed
|
|
77
|
+
desktop, including mount, so the last opens in front. Minimized windows count
|
|
78
|
+
as open. Closing the last window leaves it empty until the next mode entry. The
|
|
79
|
+
provider's `defaultWindowEnabled` defers that entry while false (e.g. hidden
|
|
80
|
+
workspaces). Hiding and showing an already initialized desktop preserves it,
|
|
81
|
+
even if empty. Omit the list to manage startup yourself; `homeAppId` only sets
|
|
82
|
+
the routed home.
|
|
83
|
+
|
|
84
|
+
A new window opens at the request's `position`, or `DEFAULT_MINI_APP_POSITION`,
|
|
85
|
+
at the app's `windowSize`. A host that places its apps itself passes the
|
|
86
|
+
provider a `placeWindow` callback. It receives each request that opens a new
|
|
87
|
+
window and returns a `MiniAppWindowPlacement`: the window's `position`, in
|
|
88
|
+
viewport pixels like the request's, its `size`, and `fitToContent` to open it
|
|
89
|
+
fitted (see [Geometry and input](./windows.md#geometry-and-input)). A field it
|
|
90
|
+
leaves out keeps the default. Default windows, desktop icons, and every other
|
|
91
|
+
`openMiniApp` call open through it:
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
<LauncherNavigationProvider
|
|
95
|
+
definition={LAUNCHER}
|
|
96
|
+
mode={mode}
|
|
97
|
+
placeWindow={({ appId }) =>
|
|
98
|
+
appId === "notes"
|
|
99
|
+
? { fitToContent: true, position: { x: 120, y: 40 } }
|
|
100
|
+
: {}
|
|
101
|
+
}
|
|
102
|
+
>
|
|
103
|
+
```
|
|
81
104
|
|
|
82
105
|
A mini-app reads and sets its own route with `useMiniAppRouteSegments(appId)`,
|
|
83
106
|
or `useMiniAppRouteState` for a parsed route: the browser route in the routed
|
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
|
@@ -7,13 +7,14 @@ 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 {
|
|
10
|
+
export { type LauncherNavigationActions, LauncherNavigationProvider, type LauncherNavigationState, useLauncherNavigationActions, useLauncherNavigationState, useMiniAppRouteSegments, useOptionalLauncherNavigationState, } from "./launcher/LauncherNavigationProvider.js";
|
|
11
11
|
export { isLauncherAppId, type LauncherDefinition, type MiniAppDefinition, resolveLauncherHomeAppId, resolveLauncherOrder, } from "./launcher/launcherDefinition.js";
|
|
12
12
|
export { MiniAppRouteSegmentsProvider, useMiniAppWindowRouteSegments, } from "./launcher/MiniAppRouteSegmentsContext.js";
|
|
13
13
|
export { type MiniAppBoundary, MiniAppWindow } from "./launcher/MiniAppWindow.js";
|
|
14
14
|
export { NavigationModeOverrideProvider, useNavigationModeOverride, useOptionalNavigationModeOverride, } from "./launcher/NavigationModeOverrideProvider.js";
|
|
15
15
|
export { NavigationModeSwitch } from "./launcher/NavigationModeSwitch.js";
|
|
16
16
|
export { isWindowedLayoutEligible, type NavigationEnvironment, type NavigationMode, readNavigationEnvironment, resolveNavigationMode, } from "./launcher/navigationMode.js";
|
|
17
|
+
export { DEFAULT_MINI_APP_POSITION, type MiniAppWindowPlacement, type OpenMiniAppRequest, type PlaceMiniAppWindow, } from "./launcher/openMiniAppWindow.js";
|
|
17
18
|
export { buildMiniAppPath, type LauncherRoute, parseLauncherRoute, } from "./launcher/routePaths.js";
|
|
18
19
|
export { resolveActiveLauncherRoute, useActiveLauncherRoute, } from "./launcher/useActiveLauncherRoute.js";
|
|
19
20
|
export { useCompactRoutedMode } from "./launcher/useCompactRoutedMode.js";
|
|
@@ -26,6 +27,7 @@ export { Menu, type MenuPosition } from "./menu/Menu.js";
|
|
|
26
27
|
export { MenuItem, type MenuItemProps } from "./menu/MenuItem.js";
|
|
27
28
|
export { StartMenu, type StartMenuItem, type StartMenuProps, } from "./menu/StartMenu.js";
|
|
28
29
|
export { type ContextMenuState, useContextMenuPositionState, useContextMenuState, } from "./menu/useContextMenuState.js";
|
|
30
|
+
export { useLongPress } from "./menu/useLongPress.js";
|
|
29
31
|
export { RoutedPane, type RoutedPaneProps } from "./routed/RoutedPane.js";
|
|
30
32
|
export { RoutedPaneOverlayHostProvider, type RoutedPaneOverlayHostValue, useRoutedPaneOverlayHost, } from "./routed/RoutedPaneOverlayHost.js";
|
|
31
33
|
export type { SubscribeKeyboardVisibility } from "./routed/useMobileKeyboardVisible.js";
|
package/index.js
CHANGED
|
@@ -11,13 +11,14 @@ export { createMemoryDesktopStateStorage, createOpfsDesktopStateStorage, } from
|
|
|
11
11
|
export { DisplayProperties } from "./display/DisplayProperties.js";
|
|
12
12
|
export { WindowingIconsProvider, } from "./icons/WindowingIcons.js";
|
|
13
13
|
export { ROUTED_TABLET_BREAKPOINT_PX, ROUTED_TABLET_QUERY, WINDOWED_LAYOUT_MIN_WIDTH_PX, } from "./launcher/breakpoints.js";
|
|
14
|
-
export {
|
|
14
|
+
export { LauncherNavigationProvider, useLauncherNavigationActions, useLauncherNavigationState, useMiniAppRouteSegments, useOptionalLauncherNavigationState, } from "./launcher/LauncherNavigationProvider.js";
|
|
15
15
|
export { isLauncherAppId, resolveLauncherHomeAppId, resolveLauncherOrder, } from "./launcher/launcherDefinition.js";
|
|
16
16
|
export { MiniAppRouteSegmentsProvider, useMiniAppWindowRouteSegments, } from "./launcher/MiniAppRouteSegmentsContext.js";
|
|
17
17
|
export { MiniAppWindow } from "./launcher/MiniAppWindow.js";
|
|
18
18
|
export { NavigationModeOverrideProvider, useNavigationModeOverride, useOptionalNavigationModeOverride, } from "./launcher/NavigationModeOverrideProvider.js";
|
|
19
19
|
export { NavigationModeSwitch } from "./launcher/NavigationModeSwitch.js";
|
|
20
20
|
export { isWindowedLayoutEligible, readNavigationEnvironment, resolveNavigationMode, } from "./launcher/navigationMode.js";
|
|
21
|
+
export { DEFAULT_MINI_APP_POSITION, } from "./launcher/openMiniAppWindow.js";
|
|
21
22
|
export { buildMiniAppPath, parseLauncherRoute, } from "./launcher/routePaths.js";
|
|
22
23
|
export { resolveActiveLauncherRoute, useActiveLauncherRoute, } from "./launcher/useActiveLauncherRoute.js";
|
|
23
24
|
export { useCompactRoutedMode } from "./launcher/useCompactRoutedMode.js";
|
|
@@ -30,6 +31,7 @@ export { Menu } from "./menu/Menu.js";
|
|
|
30
31
|
export { MenuItem } from "./menu/MenuItem.js";
|
|
31
32
|
export { StartMenu, } from "./menu/StartMenu.js";
|
|
32
33
|
export { useContextMenuPositionState, useContextMenuState, } from "./menu/useContextMenuState.js";
|
|
34
|
+
export { useLongPress } from "./menu/useLongPress.js";
|
|
33
35
|
export { RoutedPane } from "./routed/RoutedPane.js";
|
|
34
36
|
export { RoutedPaneOverlayHostProvider, useRoutedPaneOverlayHost, } from "./routed/RoutedPaneOverlayHost.js";
|
|
35
37
|
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;AAChE,OAAO,EAEL,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,
|
|
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;A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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 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 { 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"]}
|
|
@@ -2,24 +2,8 @@ import { type PropsWithChildren } from "react";
|
|
|
2
2
|
import type { LauncherDefinition } from "./launcherDefinition.js";
|
|
3
3
|
import { type NavigationHistoryAvailability } from "./navigationHistory.js";
|
|
4
4
|
import type { NavigationMode } from "./navigationMode.js";
|
|
5
|
+
import { type OpenMiniAppRequest, type PlaceMiniAppWindow } from "./openMiniAppWindow.js";
|
|
5
6
|
import { type LauncherRoute } from "./routePaths.js";
|
|
6
|
-
/** Where a new window opens when a request names no position. */
|
|
7
|
-
export declare const DEFAULT_MINI_APP_POSITION: {
|
|
8
|
-
x: number;
|
|
9
|
-
y: number;
|
|
10
|
-
};
|
|
11
|
-
/** A request to show an app: in a window, or as the routed shell's page. */
|
|
12
|
-
export interface OpenMiniAppRequest<AppId extends string = string> {
|
|
13
|
-
appId: AppId;
|
|
14
|
-
pathSegments?: ReadonlyArray<string> | undefined;
|
|
15
|
-
/** Where a new window opens. */
|
|
16
|
-
position?: {
|
|
17
|
-
x: number;
|
|
18
|
-
y: number;
|
|
19
|
-
} | undefined;
|
|
20
|
-
/** Raise the app's open window instead of opening another. Defaults to true. */
|
|
21
|
-
reuseExisting?: boolean | undefined;
|
|
22
|
-
}
|
|
23
7
|
export interface LauncherNavigationActions<AppId extends string = string> {
|
|
24
8
|
getMiniAppHref: (appId: AppId, pathSegments?: ReadonlyArray<string> | undefined) => string;
|
|
25
9
|
goBack: () => void;
|
|
@@ -41,10 +25,15 @@ export interface LauncherNavigationState<AppId extends string = string> {
|
|
|
41
25
|
route: LauncherRoute<AppId>;
|
|
42
26
|
}
|
|
43
27
|
interface LauncherNavigationProviderProps extends PropsWithChildren {
|
|
44
|
-
/** Defers the default
|
|
28
|
+
/** Defers the default windows while false, for example in a hidden workspace. */
|
|
45
29
|
defaultWindowEnabled?: boolean | undefined;
|
|
46
30
|
definition: LauncherDefinition;
|
|
47
31
|
mode: NavigationMode;
|
|
32
|
+
/**
|
|
33
|
+
* Places each new window, for a host that opens its apps at their own
|
|
34
|
+
* positions or sizes. Read when a window opens.
|
|
35
|
+
*/
|
|
36
|
+
placeWindow?: PlaceMiniAppWindow | undefined;
|
|
48
37
|
}
|
|
49
38
|
/**
|
|
50
39
|
* Navigation for a launcher's mini-apps, in either mode. In `windowed` mode,
|
|
@@ -52,7 +41,7 @@ interface LauncherNavigationProviderProps extends PropsWithChildren {
|
|
|
52
41
|
* {@link WindowStateProvider}); in `routed` mode it navigates the browser to
|
|
53
42
|
* the app's route, `/app/<app id>/…`, which the routed shell shows.
|
|
54
43
|
*/
|
|
55
|
-
export declare function LauncherNavigationProvider({ children, defaultWindowEnabled, definition, mode, }: LauncherNavigationProviderProps): import("react").JSX.Element;
|
|
44
|
+
export declare function LauncherNavigationProvider({ children, defaultWindowEnabled, definition, mode, placeWindow, }: LauncherNavigationProviderProps): import("react").JSX.Element;
|
|
56
45
|
export declare const useLauncherNavigationActions: () => LauncherNavigationActions<string>;
|
|
57
46
|
export declare const useLauncherNavigationState: () => LauncherNavigationState<string>;
|
|
58
47
|
export declare const useOptionalLauncherNavigationState: () => LauncherNavigationState<string> | null;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
|
|
3
3
|
import { createRequiredContext } from "../createRequiredContext.js";
|
|
4
|
-
import {
|
|
4
|
+
import { useWindowActions, useWindowStateData, } from "../window/WindowStateProvider/index.js";
|
|
5
5
|
import { useMiniAppWindowRouteSegments } from "./MiniAppRouteSegmentsContext.js";
|
|
6
6
|
import { DEFAULT_NAVIGATION_HISTORY_CURSOR, getNavigationHistoryAvailability, readNavigationHistoryCursor, } from "./navigationHistory.js";
|
|
7
|
+
import { openMiniAppWindow, } from "./openMiniAppWindow.js";
|
|
7
8
|
import { replaceWindowHistoryCursor, useRoutedPathNavigator, } from "./routedPathNavigator.js";
|
|
8
9
|
import { buildMiniAppPath, LAUNCHER_HOME_PATH, parseLauncherRoute, } from "./routePaths.js";
|
|
9
10
|
import { useDefaultWindow } from "./useDefaultWindow.js";
|
|
10
|
-
/** Where a new window opens when a request names no position. */
|
|
11
|
-
export const DEFAULT_MINI_APP_POSITION = { x: 200, y: 160 };
|
|
12
11
|
const launcherNavigationActionsContext = createRequiredContext("useLauncherNavigationActions requires LauncherNavigationProvider.");
|
|
13
12
|
const launcherNavigationStateContext = createRequiredContext("useLauncherNavigationState requires LauncherNavigationProvider.");
|
|
14
13
|
const EMPTY_ROUTE_SEGMENTS = [];
|
|
@@ -26,7 +25,7 @@ function ensureWindowHistoryCursor() {
|
|
|
26
25
|
}
|
|
27
26
|
return cursor;
|
|
28
27
|
}
|
|
29
|
-
function LauncherNavigationWindowRuntimeBridge({ defaultWindowEnabled, definition, mode, openMiniApp, runtimeRef, }) {
|
|
28
|
+
function LauncherNavigationWindowRuntimeBridge({ defaultWindowEnabled, definition, mode, openMiniApp, placeWindow, runtimeRef, }) {
|
|
30
29
|
const { bringToFront, create, restore, updateRoute } = useWindowActions();
|
|
31
30
|
const { windows } = useWindowStateData();
|
|
32
31
|
useEffect(() => {
|
|
@@ -34,6 +33,7 @@ function LauncherNavigationWindowRuntimeBridge({ defaultWindowEnabled, definitio
|
|
|
34
33
|
actions: { bringToFront, create, restore, updateRoute },
|
|
35
34
|
definition,
|
|
36
35
|
mode,
|
|
36
|
+
placeWindow,
|
|
37
37
|
windows,
|
|
38
38
|
};
|
|
39
39
|
}, [
|
|
@@ -41,6 +41,7 @@ function LauncherNavigationWindowRuntimeBridge({ defaultWindowEnabled, definitio
|
|
|
41
41
|
create,
|
|
42
42
|
definition,
|
|
43
43
|
mode,
|
|
44
|
+
placeWindow,
|
|
44
45
|
restore,
|
|
45
46
|
runtimeRef,
|
|
46
47
|
updateRoute,
|
|
@@ -127,34 +128,19 @@ function useLauncherRouteController({ definition, mode, runtimeRef, }) {
|
|
|
127
128
|
};
|
|
128
129
|
}
|
|
129
130
|
function useLauncherNavigationActionValue(runtimeRef, goBack, goForward, navigateHome, navigateMiniAppRoute) {
|
|
130
|
-
const openMiniApp = useCallback((
|
|
131
|
-
const { actions, definition, mode
|
|
132
|
-
if (
|
|
131
|
+
const openMiniApp = useCallback((request) => {
|
|
132
|
+
const { actions, definition, mode, placeWindow, windows } = runtimeRef.current;
|
|
133
|
+
if (mode === "routed") {
|
|
134
|
+
const { appId, pathSegments } = request;
|
|
133
135
|
navigateMiniAppRoute({ appId, pathSegments });
|
|
134
136
|
return null;
|
|
135
137
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
actions.restore(existingWindow.id);
|
|
143
|
-
actions.bringToFront(existingWindow.id);
|
|
144
|
-
if (pathSegments) {
|
|
145
|
-
actions.updateRoute(existingWindow.id, pathSegments);
|
|
146
|
-
}
|
|
147
|
-
return existingWindow.id;
|
|
148
|
-
}
|
|
149
|
-
const app = definition.apps[appId];
|
|
150
|
-
if (!app) {
|
|
151
|
-
throw new Error(`Unknown mini-app: ${appId}`);
|
|
152
|
-
}
|
|
153
|
-
return actions.create(app.title, position.x, position.y, app.createComponent(), {
|
|
154
|
-
appId,
|
|
155
|
-
initialShowSidebar: app.initialShowSidebar,
|
|
156
|
-
...(pathSegments ? { pathSegments } : {}),
|
|
157
|
-
...(app.windowSize ? { size: app.windowSize } : {}),
|
|
138
|
+
return openMiniAppWindow({
|
|
139
|
+
actions,
|
|
140
|
+
definition,
|
|
141
|
+
placeWindow,
|
|
142
|
+
request,
|
|
143
|
+
windows,
|
|
158
144
|
});
|
|
159
145
|
}, [navigateMiniAppRoute, runtimeRef]);
|
|
160
146
|
const getMiniAppHref = useCallback(buildMiniAppPath, []);
|
|
@@ -180,7 +166,7 @@ function useLauncherNavigationActionValue(runtimeRef, goBack, goForward, navigat
|
|
|
180
166
|
* {@link WindowStateProvider}); in `routed` mode it navigates the browser to
|
|
181
167
|
* the app's route, `/app/<app id>/…`, which the routed shell shows.
|
|
182
168
|
*/
|
|
183
|
-
export function LauncherNavigationProvider({ children, defaultWindowEnabled = true, definition, mode, }) {
|
|
169
|
+
export function LauncherNavigationProvider({ children, defaultWindowEnabled = true, definition, mode, placeWindow, }) {
|
|
184
170
|
const runtimeRef = useRef({
|
|
185
171
|
actions: {
|
|
186
172
|
bringToFront: () => { },
|
|
@@ -190,6 +176,7 @@ export function LauncherNavigationProvider({ children, defaultWindowEnabled = tr
|
|
|
190
176
|
},
|
|
191
177
|
definition,
|
|
192
178
|
mode,
|
|
179
|
+
placeWindow,
|
|
193
180
|
windows: [],
|
|
194
181
|
});
|
|
195
182
|
const { goBack, goForward, history, navigateHome, navigateMiniAppRoute, route, } = useLauncherRouteController({
|
|
@@ -199,7 +186,7 @@ export function LauncherNavigationProvider({ children, defaultWindowEnabled = tr
|
|
|
199
186
|
});
|
|
200
187
|
const actions = useLauncherNavigationActionValue(runtimeRef, goBack, goForward, navigateHome, navigateMiniAppRoute);
|
|
201
188
|
const state = useMemo(() => ({ definition, history, mode, route }), [definition, history, mode, route]);
|
|
202
|
-
return (_jsx(launcherNavigationActionsContext.context.Provider, { value: actions, children: _jsxs(launcherNavigationStateContext.context.Provider, { value: state, children: [_jsx(LauncherNavigationWindowRuntimeBridge, { defaultWindowEnabled: defaultWindowEnabled, definition: definition, mode: mode, openMiniApp: actions.openMiniApp, runtimeRef: runtimeRef }), children] }) }));
|
|
189
|
+
return (_jsx(launcherNavigationActionsContext.context.Provider, { value: actions, children: _jsxs(launcherNavigationStateContext.context.Provider, { value: state, children: [_jsx(LauncherNavigationWindowRuntimeBridge, { defaultWindowEnabled: defaultWindowEnabled, definition: definition, mode: mode, openMiniApp: actions.openMiniApp, placeWindow: placeWindow, runtimeRef: runtimeRef }), children] }) }));
|
|
203
190
|
}
|
|
204
191
|
// The context names apps by their string ids. The actions accept a host's own
|
|
205
192
|
// narrower id type as they are; a host narrows the route's id with
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LauncherNavigationProvider.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/LauncherNavigationProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAGL,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,GAGnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,EACL,iCAAiC,EACjC,gCAAgC,EAGhC,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAElB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAo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AK;gBACL,YAAY,EAAE,gBAAgB;gBAC9B,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS;oBAC/B,CAAC,CAAC,EAAE;oBACJ,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;aAClC,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,qBAAqB,EAAE,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC,EACD,CAAC,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,qBAAqB,CAAC,CACxD,CAAC;IACF,6EAA6E;IAC7E,6EAA6E;IAC7E,0EAA0E;IAC1E,8EAA8E;IAC9E,kBAAkB;IAClB,MAAM,YAAY,GAAG,WAAW,EAAE,MAAM,CAAC;IACzC,MAAM,SAAS,GAAG,cAAc;QAC9B,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS;QACzB,CAAC,CAAC,CAAC,WAAW,EAAE,SAAS,IAAI,KAAK,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE;QAC9B,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,EAAE,MAAM,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,YAAY,EAAE,EAAE,CAAC;IACnB,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC;IAE5C,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,SAAS;QACT,MAAM;QACN,QAAQ;QACR,YAAY;QACZ,eAAe;KAChB,CAAC,EACF,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,CAAC,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["import {\n type MutableRefObject,\n type PropsWithChildren,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createRequiredContext } from \"../createRequiredContext\";\nimport {\n findTopWindow,\n useWindowActions,\n useWindowStateData,\n type WindowStateActions,\n type WindowStateData,\n} from \"../window/WindowStateProvider\";\nimport type { LauncherDefinition } from \"./launcherDefinition\";\nimport { useMiniAppWindowRouteSegments } from \"./MiniAppRouteSegmentsContext\";\nimport {\n DEFAULT_NAVIGATION_HISTORY_CURSOR,\n getNavigationHistoryAvailability,\n type NavigationHistoryAvailability,\n type NavigationHistoryCursor,\n readNavigationHistoryCursor,\n} from \"./navigationHistory\";\nimport type { NavigationMode } from \"./navigationMode\";\nimport {\n replaceWindowHistoryCursor,\n useRoutedPathNavigator,\n} from \"./routedPathNavigator\";\nimport {\n buildMiniAppPath,\n LAUNCHER_HOME_PATH,\n type LauncherRoute,\n parseLauncherRoute,\n} from \"./routePaths\";\nimport { useDefaultWindow } from \"./useDefaultWindow\";\n\n/** Where a new window opens when a request names no position. */\nexport const DEFAULT_MINI_APP_POSITION = { x: 200, y: 160 };\n\n/** A request to show an app: in a window, or as the routed shell's page. */\nexport interface OpenMiniAppRequest<AppId extends string = string> {\n appId: AppId;\n pathSegments?: ReadonlyArray<string> | undefined;\n /** Where a new window opens. */\n position?: { x: number; y: number } | undefined;\n /** Raise the app's open window instead of opening another. Defaults to true. */\n reuseExisting?: boolean | undefined;\n}\n\nexport interface LauncherNavigationActions<AppId extends string = string> {\n getMiniAppHref: (\n appId: AppId,\n pathSegments?: ReadonlyArray<string> | undefined,\n ) => string;\n goBack: () => void;\n goForward: () => void;\n navigateMiniAppRoute: (input: {\n appId: AppId;\n pathSegments?: ReadonlyArray<string> | undefined;\n replace?: boolean | undefined;\n }) => void;\n navigateHome: (input?: { replace?: boolean | undefined }) => void;\n // Returns the window the app opened in or was raised to, or null when the\n // routed shell shows it instead.\n openMiniApp: (request: OpenMiniAppRequest<AppId>) => string | null;\n}\n\nexport interface LauncherNavigationState<AppId extends string = string> {\n definition: LauncherDefinition<AppId>;\n history: NavigationHistoryAvailability;\n mode: NavigationMode;\n route: LauncherRoute<AppId>;\n}\n\ninterface LauncherNavigationProviderProps extends PropsWithChildren {\n /** Defers the default window while false, for example in a hidden workspace. */\n defaultWindowEnabled?: boolean | undefined;\n definition: LauncherDefinition;\n mode: NavigationMode;\n}\n\ninterface LauncherNavigationRuntime {\n actions: Pick<\n WindowStateActions,\n \"bringToFront\" | \"create\" | \"restore\" | \"updateRoute\"\n >;\n definition: LauncherDefinition;\n mode: NavigationMode;\n windows: WindowStateData[\"windows\"];\n}\n\nconst launcherNavigationActionsContext =\n createRequiredContext<LauncherNavigationActions>(\n \"useLauncherNavigationActions requires LauncherNavigationProvider.\",\n );\nconst launcherNavigationStateContext =\n createRequiredContext<LauncherNavigationState>(\n \"useLauncherNavigationState requires LauncherNavigationProvider.\",\n );\nconst EMPTY_ROUTE_SEGMENTS: ReadonlyArray<string> = [];\n\nfunction readCurrentRoute(definition: LauncherDefinition): LauncherRoute {\n return parseLauncherRoute(window.location.pathname, definition);\n}\n\nfunction readWindowHistoryCursor(): NavigationHistoryCursor {\n return (\n readNavigationHistoryCursor(window.history.state) ??\n DEFAULT_NAVIGATION_HISTORY_CURSOR\n );\n}\n\nfunction ensureWindowHistoryCursor(): NavigationHistoryCursor {\n const cursor = readWindowHistoryCursor();\n if (readNavigationHistoryCursor(window.history.state) === null) {\n replaceWindowHistoryCursor(cursor);\n }\n\n return cursor;\n}\n\nfunction LauncherNavigationWindowRuntimeBridge({\n defaultWindowEnabled,\n definition,\n mode,\n openMiniApp,\n runtimeRef,\n}: {\n defaultWindowEnabled: boolean;\n definition: LauncherDefinition;\n mode: NavigationMode;\n openMiniApp: LauncherNavigationActions[\"openMiniApp\"];\n runtimeRef: MutableRefObject<LauncherNavigationRuntime>;\n}) {\n const { bringToFront, create, restore, updateRoute } = useWindowActions();\n const { windows } = useWindowStateData();\n\n useEffect(() => {\n runtimeRef.current = {\n actions: { bringToFront, create, restore, updateRoute },\n definition,\n mode,\n windows,\n };\n }, [\n bringToFront,\n create,\n definition,\n mode,\n restore,\n runtimeRef,\n updateRoute,\n windows,\n ]);\n\n useDefaultWindow({\n definition,\n enabled: defaultWindowEnabled,\n mode,\n openMiniApp,\n windowCount: windows.length,\n });\n\n return null;\n}\n\nfunction useLauncherRouteController({\n definition,\n mode,\n runtimeRef,\n}: {\n definition: LauncherDefinition;\n mode: NavigationMode;\n runtimeRef: MutableRefObject<LauncherNavigationRuntime>;\n}) {\n const [route, setRoute] = useState<LauncherRoute>(() =>\n readCurrentRoute(definition),\n );\n const [historyCursor, setHistoryCursorState] =\n useState<NavigationHistoryCursor>(readWindowHistoryCursor);\n const historyCursorRef = useRef(historyCursor);\n const setHistoryCursor = useCallback((cursor: NavigationHistoryCursor) => {\n historyCursorRef.current = cursor;\n setHistoryCursorState(cursor);\n }, []);\n const navigateRoutedPath = useRoutedPathNavigator({\n historyCursorRef,\n runtimeRef,\n setHistoryCursor,\n setRoute,\n });\n\n useEffect(() => {\n if (mode !== \"routed\") {\n return;\n }\n\n const handlePopState = (event: PopStateEvent) => {\n setHistoryCursor(\n readNavigationHistoryCursor(event.state) ??\n DEFAULT_NAVIGATION_HISTORY_CURSOR,\n );\n setRoute(readCurrentRoute(runtimeRef.current.definition));\n };\n\n setHistoryCursor(ensureWindowHistoryCursor());\n setRoute(readCurrentRoute(runtimeRef.current.definition));\n window.addEventListener(\"popstate\", handlePopState);\n return () => window.removeEventListener(\"popstate\", handlePopState);\n }, [mode, runtimeRef, setHistoryCursor]);\n\n const navigateMiniAppRoute = useCallback(\n ({\n appId,\n pathSegments = [],\n replace = false,\n }: {\n appId: string;\n pathSegments?: ReadonlyArray<string> | undefined;\n replace?: boolean | undefined;\n }) => {\n navigateRoutedPath({\n path: buildMiniAppPath(appId, pathSegments),\n replace,\n route: { appId, pathSegments: [...pathSegments] },\n });\n },\n [navigateRoutedPath],\n );\n const navigateHome = useCallback(\n ({ replace = false }: { replace?: boolean | undefined } = {}) => {\n navigateRoutedPath({\n path: LAUNCHER_HOME_PATH,\n replace,\n route: { appId: null, pathSegments: [] },\n });\n },\n [navigateRoutedPath],\n );\n\n const goBack = useCallback(() => {\n if (historyCursorRef.current.index > 0) {\n setHistoryCursor({\n ...historyCursorRef.current,\n index: historyCursorRef.current.index - 1,\n });\n window.history.back();\n }\n }, [setHistoryCursor]);\n const goForward = useCallback(() => {\n const { entries, index } = historyCursorRef.current;\n if (index < entries - 1) {\n setHistoryCursor({\n ...historyCursorRef.current,\n index: index + 1,\n });\n window.history.forward();\n }\n }, [setHistoryCursor]);\n const history = useMemo(\n () => getNavigationHistoryAvailability(historyCursor),\n [historyCursor],\n );\n\n return {\n goBack,\n goForward,\n history,\n navigateHome,\n navigateMiniAppRoute,\n route,\n };\n}\n\nfunction useLauncherNavigationActionValue(\n runtimeRef: MutableRefObject<LauncherNavigationRuntime>,\n goBack: LauncherNavigationActions[\"goBack\"],\n goForward: LauncherNavigationActions[\"goForward\"],\n navigateHome: LauncherNavigationActions[\"navigateHome\"],\n navigateMiniAppRoute: LauncherNavigationActions[\"navigateMiniAppRoute\"],\n): LauncherNavigationActions {\n const openMiniApp = useCallback(\n ({\n appId,\n pathSegments,\n position = DEFAULT_MINI_APP_POSITION,\n reuseExisting = true,\n }: OpenMiniAppRequest) => {\n const {\n actions,\n definition,\n mode: currentMode,\n windows: currentWindows,\n } = runtimeRef.current;\n\n if (currentMode === \"routed\") {\n navigateMiniAppRoute({ appId, pathSegments });\n return null;\n }\n\n const existingWindow = reuseExisting\n ? findTopWindow(currentWindows, (windowEntry) => {\n return windowEntry.appId === appId;\n })\n : null;\n if (existingWindow) {\n actions.restore(existingWindow.id);\n actions.bringToFront(existingWindow.id);\n if (pathSegments) {\n actions.updateRoute(existingWindow.id, pathSegments);\n }\n return existingWindow.id;\n }\n\n const app = definition.apps[appId];\n if (!app) {\n throw new Error(`Unknown mini-app: ${appId}`);\n }\n return actions.create(\n app.title,\n position.x,\n position.y,\n app.createComponent(),\n {\n appId,\n initialShowSidebar: app.initialShowSidebar,\n ...(pathSegments ? { pathSegments } : {}),\n ...(app.windowSize ? { size: app.windowSize } : {}),\n },\n );\n },\n [navigateMiniAppRoute, runtimeRef],\n );\n const getMiniAppHref = useCallback(buildMiniAppPath, []);\n return useMemo<LauncherNavigationActions>(\n () => ({\n getMiniAppHref,\n goBack,\n goForward,\n navigateHome,\n navigateMiniAppRoute,\n openMiniApp,\n }),\n [\n getMiniAppHref,\n goBack,\n goForward,\n navigateHome,\n navigateMiniAppRoute,\n openMiniApp,\n ],\n );\n}\n\n/**\n * Navigation for a launcher's mini-apps, in either mode. In `windowed` mode,\n * opening an app opens or raises its window (inside a\n * {@link WindowStateProvider}); in `routed` mode it navigates the browser to\n * the app's route, `/app/<app id>/…`, which the routed shell shows.\n */\nexport function LauncherNavigationProvider({\n children,\n defaultWindowEnabled = true,\n definition,\n mode,\n}: LauncherNavigationProviderProps) {\n const runtimeRef = useRef<LauncherNavigationRuntime>({\n actions: {\n bringToFront: () => {},\n create: () => \"\",\n restore: () => {},\n updateRoute: () => {},\n },\n definition,\n mode,\n windows: [],\n });\n const {\n goBack,\n goForward,\n history,\n navigateHome,\n navigateMiniAppRoute,\n route,\n } = useLauncherRouteController({\n definition,\n mode,\n runtimeRef,\n });\n const actions = useLauncherNavigationActionValue(\n runtimeRef,\n goBack,\n goForward,\n navigateHome,\n navigateMiniAppRoute,\n );\n const state = useMemo<LauncherNavigationState>(\n () => ({ definition, history, mode, route }),\n [definition, history, mode, route],\n );\n\n return (\n <launcherNavigationActionsContext.context.Provider value={actions}>\n <launcherNavigationStateContext.context.Provider value={state}>\n <LauncherNavigationWindowRuntimeBridge\n defaultWindowEnabled={defaultWindowEnabled}\n definition={definition}\n mode={mode}\n openMiniApp={actions.openMiniApp}\n runtimeRef={runtimeRef}\n />\n {children}\n </launcherNavigationStateContext.context.Provider>\n </launcherNavigationActionsContext.context.Provider>\n );\n}\n\n// The context names apps by their string ids. The actions accept a host's own\n// narrower id type as they are; a host narrows the route's id with\n// isLauncherAppId (or its own guard) to read it back as that type.\nexport const useLauncherNavigationActions =\n launcherNavigationActionsContext.useRequired;\n\nexport const useLauncherNavigationState =\n launcherNavigationStateContext.useRequired;\n\nexport const useOptionalLauncherNavigationState =\n launcherNavigationStateContext.useOptional;\n\n/**\n * The route of `appId` where it is hosted: the browser route in the routed\n * shell, or its window's own route and Back stack in a window. Mini-apps read\n * this rather than branching on navigation mode.\n */\nexport function useMiniAppRouteSegments(appId: string) {\n const actions = launcherNavigationActionsContext.useOptional();\n const state = launcherNavigationStateContext.useOptional();\n const windowRoute = useMiniAppWindowRouteSegments(appId);\n const isGlobalRouted = actions !== null && state?.mode === \"routed\";\n const isRouted = isGlobalRouted || windowRoute !== null;\n const pathSegments =\n isGlobalRouted && state.route.appId === appId\n ? state.route.pathSegments\n : (windowRoute?.pathSegments ?? EMPTY_ROUTE_SEGMENTS);\n const windowSetPathSegments = windowRoute?.setPathSegments;\n const setPathSegments = useCallback(\n (\n nextPathSegments: ReadonlyArray<string>,\n options: { replace?: boolean | undefined } = {},\n ) => {\n if (isGlobalRouted) {\n actions?.navigateMiniAppRoute({\n appId,\n pathSegments: nextPathSegments,\n ...(options.replace === undefined\n ? {}\n : { replace: options.replace }),\n });\n return;\n }\n\n windowSetPathSegments?.(nextPathSegments, options);\n },\n [actions, appId, isGlobalRouted, windowSetPathSegments],\n );\n // \"Can this mini-app step back where it is hosted?\" — browser history in the\n // routed shell, the window's own Back stack in a window. Mini-apps read this\n // rather than branching on navigation mode, so a detail surface that must\n // yield to a real Back affordance asks one question and gets the right answer\n // in both shells.\n const windowGoBack = windowRoute?.goBack;\n const canGoBack = isGlobalRouted\n ? state.history.canGoBack\n : (windowRoute?.canGoBack ?? false);\n const goBack = useCallback(() => {\n if (isGlobalRouted) {\n actions?.goBack();\n return;\n }\n\n windowGoBack?.();\n }, [actions, isGlobalRouted, windowGoBack]);\n\n return useMemo(\n () => ({\n canGoBack,\n goBack,\n isRouted,\n pathSegments,\n setPathSegments,\n }),\n [canGoBack, goBack, isRouted, pathSegments, setPathSegments],\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"LauncherNavigationProvider.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/LauncherNavigationProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAGL,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,gBAAgB,EAChB,kBAAkB,GAGnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,EACL,iCAAiC,EACjC,gCAAgC,EAGhC,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAEL,iBAAiB,GAElB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAElB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAkDtD,MAAM,gCAAgC,GACpC,qBAAqB,CACnB,mEAAmE,CACpE,CAAC;AACJ,MAAM,8BAA8B,GAClC,qBAAqB,CACnB,iEAAiE,CAClE,CAAC;AACJ,MAAM,oBAAoB,GAA0B,EAAE,CAAC;AAEvD,SAAS,gBAAgB,CAAC,UAA8B;IACtD,OAAO,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,uBAAuB;IAC9B,OAAO,CACL,2BAA2B,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;QACjD,iCAAiC,CAClC,CAAC;AACJ,CAAC;AAED,SAAS,yBAAyB;IAChC,MAAM,MAAM,GAAG,uBAAuB,EAAE,CAAC;IACzC,IAAI,2BAA2B,CAAC,MAAM,CAAC,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EAA6E;IAC7E,6EAA6E;IAC7E,0EAA0E;IAC1E,8EAA8E;IAC9E,kBAAkB;IAClB,MAAM,YAAY,GAAG,WAAW,EAAE,MAAM,CAAC;IACzC,MAAM,SAAS,GAAG,cAAc;QAC9B,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS;QACzB,CAAC,CAAC,CAAC,WAAW,EAAE,SAAS,IAAI,KAAK,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE;QAC9B,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,EAAE,MAAM,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,YAAY,EAAE,EAAE,CAAC;IACnB,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC;IAE5C,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,SAAS;QACT,MAAM;QACN,QAAQ;QACR,YAAY;QACZ,eAAe;KAChB,CAAC,EACF,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,CAAC,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["import {\n type MutableRefObject,\n type PropsWithChildren,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createRequiredContext } from \"../createRequiredContext\";\nimport {\n useWindowActions,\n useWindowStateData,\n type WindowStateActions,\n type WindowStateData,\n} from \"../window/WindowStateProvider\";\nimport type { LauncherDefinition } from \"./launcherDefinition\";\nimport { useMiniAppWindowRouteSegments } from \"./MiniAppRouteSegmentsContext\";\nimport {\n DEFAULT_NAVIGATION_HISTORY_CURSOR,\n getNavigationHistoryAvailability,\n type NavigationHistoryAvailability,\n type NavigationHistoryCursor,\n readNavigationHistoryCursor,\n} from \"./navigationHistory\";\nimport type { NavigationMode } from \"./navigationMode\";\nimport {\n type OpenMiniAppRequest,\n openMiniAppWindow,\n type PlaceMiniAppWindow,\n} from \"./openMiniAppWindow\";\nimport {\n replaceWindowHistoryCursor,\n useRoutedPathNavigator,\n} from \"./routedPathNavigator\";\nimport {\n buildMiniAppPath,\n LAUNCHER_HOME_PATH,\n type LauncherRoute,\n parseLauncherRoute,\n} from \"./routePaths\";\nimport { useDefaultWindow } from \"./useDefaultWindow\";\n\nexport interface LauncherNavigationActions<AppId extends string = string> {\n getMiniAppHref: (\n appId: AppId,\n pathSegments?: ReadonlyArray<string> | undefined,\n ) => string;\n goBack: () => void;\n goForward: () => void;\n navigateMiniAppRoute: (input: {\n appId: AppId;\n pathSegments?: ReadonlyArray<string> | undefined;\n replace?: boolean | undefined;\n }) => void;\n navigateHome: (input?: { replace?: boolean | undefined }) => void;\n // Returns the window the app opened in or was raised to, or null when the\n // routed shell shows it instead.\n openMiniApp: (request: OpenMiniAppRequest<AppId>) => string | null;\n}\n\nexport interface LauncherNavigationState<AppId extends string = string> {\n definition: LauncherDefinition<AppId>;\n history: NavigationHistoryAvailability;\n mode: NavigationMode;\n route: LauncherRoute<AppId>;\n}\n\ninterface LauncherNavigationProviderProps extends PropsWithChildren {\n /** Defers the default windows while false, for example in a hidden workspace. */\n defaultWindowEnabled?: boolean | undefined;\n definition: LauncherDefinition;\n mode: NavigationMode;\n /**\n * Places each new window, for a host that opens its apps at their own\n * positions or sizes. Read when a window opens.\n */\n placeWindow?: PlaceMiniAppWindow | undefined;\n}\n\ninterface LauncherNavigationRuntime {\n actions: Pick<\n WindowStateActions,\n \"bringToFront\" | \"create\" | \"restore\" | \"updateRoute\"\n >;\n definition: LauncherDefinition;\n mode: NavigationMode;\n placeWindow: PlaceMiniAppWindow | undefined;\n windows: WindowStateData[\"windows\"];\n}\n\nconst launcherNavigationActionsContext =\n createRequiredContext<LauncherNavigationActions>(\n \"useLauncherNavigationActions requires LauncherNavigationProvider.\",\n );\nconst launcherNavigationStateContext =\n createRequiredContext<LauncherNavigationState>(\n \"useLauncherNavigationState requires LauncherNavigationProvider.\",\n );\nconst EMPTY_ROUTE_SEGMENTS: ReadonlyArray<string> = [];\n\nfunction readCurrentRoute(definition: LauncherDefinition): LauncherRoute {\n return parseLauncherRoute(window.location.pathname, definition);\n}\n\nfunction readWindowHistoryCursor(): NavigationHistoryCursor {\n return (\n readNavigationHistoryCursor(window.history.state) ??\n DEFAULT_NAVIGATION_HISTORY_CURSOR\n );\n}\n\nfunction ensureWindowHistoryCursor(): NavigationHistoryCursor {\n const cursor = readWindowHistoryCursor();\n if (readNavigationHistoryCursor(window.history.state) === null) {\n replaceWindowHistoryCursor(cursor);\n }\n\n return cursor;\n}\n\nfunction LauncherNavigationWindowRuntimeBridge({\n defaultWindowEnabled,\n definition,\n mode,\n openMiniApp,\n placeWindow,\n runtimeRef,\n}: {\n defaultWindowEnabled: boolean;\n definition: LauncherDefinition;\n mode: NavigationMode;\n openMiniApp: LauncherNavigationActions[\"openMiniApp\"];\n placeWindow: PlaceMiniAppWindow | undefined;\n runtimeRef: MutableRefObject<LauncherNavigationRuntime>;\n}) {\n const { bringToFront, create, restore, updateRoute } = useWindowActions();\n const { windows } = useWindowStateData();\n\n useEffect(() => {\n runtimeRef.current = {\n actions: { bringToFront, create, restore, updateRoute },\n definition,\n mode,\n placeWindow,\n windows,\n };\n }, [\n bringToFront,\n create,\n definition,\n mode,\n placeWindow,\n restore,\n runtimeRef,\n updateRoute,\n windows,\n ]);\n\n useDefaultWindow({\n definition,\n enabled: defaultWindowEnabled,\n mode,\n openMiniApp,\n windowCount: windows.length,\n });\n\n return null;\n}\n\nfunction useLauncherRouteController({\n definition,\n mode,\n runtimeRef,\n}: {\n definition: LauncherDefinition;\n mode: NavigationMode;\n runtimeRef: MutableRefObject<LauncherNavigationRuntime>;\n}) {\n const [route, setRoute] = useState<LauncherRoute>(() =>\n readCurrentRoute(definition),\n );\n const [historyCursor, setHistoryCursorState] =\n useState<NavigationHistoryCursor>(readWindowHistoryCursor);\n const historyCursorRef = useRef(historyCursor);\n const setHistoryCursor = useCallback((cursor: NavigationHistoryCursor) => {\n historyCursorRef.current = cursor;\n setHistoryCursorState(cursor);\n }, []);\n const navigateRoutedPath = useRoutedPathNavigator({\n historyCursorRef,\n runtimeRef,\n setHistoryCursor,\n setRoute,\n });\n\n useEffect(() => {\n if (mode !== \"routed\") {\n return;\n }\n\n const handlePopState = (event: PopStateEvent) => {\n setHistoryCursor(\n readNavigationHistoryCursor(event.state) ??\n DEFAULT_NAVIGATION_HISTORY_CURSOR,\n );\n setRoute(readCurrentRoute(runtimeRef.current.definition));\n };\n\n setHistoryCursor(ensureWindowHistoryCursor());\n setRoute(readCurrentRoute(runtimeRef.current.definition));\n window.addEventListener(\"popstate\", handlePopState);\n return () => window.removeEventListener(\"popstate\", handlePopState);\n }, [mode, runtimeRef, setHistoryCursor]);\n\n const navigateMiniAppRoute = useCallback(\n ({\n appId,\n pathSegments = [],\n replace = false,\n }: {\n appId: string;\n pathSegments?: ReadonlyArray<string> | undefined;\n replace?: boolean | undefined;\n }) => {\n navigateRoutedPath({\n path: buildMiniAppPath(appId, pathSegments),\n replace,\n route: { appId, pathSegments: [...pathSegments] },\n });\n },\n [navigateRoutedPath],\n );\n const navigateHome = useCallback(\n ({ replace = false }: { replace?: boolean | undefined } = {}) => {\n navigateRoutedPath({\n path: LAUNCHER_HOME_PATH,\n replace,\n route: { appId: null, pathSegments: [] },\n });\n },\n [navigateRoutedPath],\n );\n\n const goBack = useCallback(() => {\n if (historyCursorRef.current.index > 0) {\n setHistoryCursor({\n ...historyCursorRef.current,\n index: historyCursorRef.current.index - 1,\n });\n window.history.back();\n }\n }, [setHistoryCursor]);\n const goForward = useCallback(() => {\n const { entries, index } = historyCursorRef.current;\n if (index < entries - 1) {\n setHistoryCursor({\n ...historyCursorRef.current,\n index: index + 1,\n });\n window.history.forward();\n }\n }, [setHistoryCursor]);\n const history = useMemo(\n () => getNavigationHistoryAvailability(historyCursor),\n [historyCursor],\n );\n\n return {\n goBack,\n goForward,\n history,\n navigateHome,\n navigateMiniAppRoute,\n route,\n };\n}\n\nfunction useLauncherNavigationActionValue(\n runtimeRef: MutableRefObject<LauncherNavigationRuntime>,\n goBack: LauncherNavigationActions[\"goBack\"],\n goForward: LauncherNavigationActions[\"goForward\"],\n navigateHome: LauncherNavigationActions[\"navigateHome\"],\n navigateMiniAppRoute: LauncherNavigationActions[\"navigateMiniAppRoute\"],\n): LauncherNavigationActions {\n const openMiniApp = useCallback(\n (request: OpenMiniAppRequest) => {\n const { actions, definition, mode, placeWindow, windows } =\n runtimeRef.current;\n if (mode === \"routed\") {\n const { appId, pathSegments } = request;\n navigateMiniAppRoute({ appId, pathSegments });\n return null;\n }\n return openMiniAppWindow({\n actions,\n definition,\n placeWindow,\n request,\n windows,\n });\n },\n [navigateMiniAppRoute, runtimeRef],\n );\n const getMiniAppHref = useCallback(buildMiniAppPath, []);\n return useMemo<LauncherNavigationActions>(\n () => ({\n getMiniAppHref,\n goBack,\n goForward,\n navigateHome,\n navigateMiniAppRoute,\n openMiniApp,\n }),\n [\n getMiniAppHref,\n goBack,\n goForward,\n navigateHome,\n navigateMiniAppRoute,\n openMiniApp,\n ],\n );\n}\n\n/**\n * Navigation for a launcher's mini-apps, in either mode. In `windowed` mode,\n * opening an app opens or raises its window (inside a\n * {@link WindowStateProvider}); in `routed` mode it navigates the browser to\n * the app's route, `/app/<app id>/…`, which the routed shell shows.\n */\nexport function LauncherNavigationProvider({\n children,\n defaultWindowEnabled = true,\n definition,\n mode,\n placeWindow,\n}: LauncherNavigationProviderProps) {\n const runtimeRef = useRef<LauncherNavigationRuntime>({\n actions: {\n bringToFront: () => {},\n create: () => \"\",\n restore: () => {},\n updateRoute: () => {},\n },\n definition,\n mode,\n placeWindow,\n windows: [],\n });\n const {\n goBack,\n goForward,\n history,\n navigateHome,\n navigateMiniAppRoute,\n route,\n } = useLauncherRouteController({\n definition,\n mode,\n runtimeRef,\n });\n const actions = useLauncherNavigationActionValue(\n runtimeRef,\n goBack,\n goForward,\n navigateHome,\n navigateMiniAppRoute,\n );\n const state = useMemo<LauncherNavigationState>(\n () => ({ definition, history, mode, route }),\n [definition, history, mode, route],\n );\n\n return (\n <launcherNavigationActionsContext.context.Provider value={actions}>\n <launcherNavigationStateContext.context.Provider value={state}>\n <LauncherNavigationWindowRuntimeBridge\n defaultWindowEnabled={defaultWindowEnabled}\n definition={definition}\n mode={mode}\n openMiniApp={actions.openMiniApp}\n placeWindow={placeWindow}\n runtimeRef={runtimeRef}\n />\n {children}\n </launcherNavigationStateContext.context.Provider>\n </launcherNavigationActionsContext.context.Provider>\n );\n}\n\n// The context names apps by their string ids. The actions accept a host's own\n// narrower id type as they are; a host narrows the route's id with\n// isLauncherAppId (or its own guard) to read it back as that type.\nexport const useLauncherNavigationActions =\n launcherNavigationActionsContext.useRequired;\n\nexport const useLauncherNavigationState =\n launcherNavigationStateContext.useRequired;\n\nexport const useOptionalLauncherNavigationState =\n launcherNavigationStateContext.useOptional;\n\n/**\n * The route of `appId` where it is hosted: the browser route in the routed\n * shell, or its window's own route and Back stack in a window. Mini-apps read\n * this rather than branching on navigation mode.\n */\nexport function useMiniAppRouteSegments(appId: string) {\n const actions = launcherNavigationActionsContext.useOptional();\n const state = launcherNavigationStateContext.useOptional();\n const windowRoute = useMiniAppWindowRouteSegments(appId);\n const isGlobalRouted = actions !== null && state?.mode === \"routed\";\n const isRouted = isGlobalRouted || windowRoute !== null;\n const pathSegments =\n isGlobalRouted && state.route.appId === appId\n ? state.route.pathSegments\n : (windowRoute?.pathSegments ?? EMPTY_ROUTE_SEGMENTS);\n const windowSetPathSegments = windowRoute?.setPathSegments;\n const setPathSegments = useCallback(\n (\n nextPathSegments: ReadonlyArray<string>,\n options: { replace?: boolean | undefined } = {},\n ) => {\n if (isGlobalRouted) {\n actions?.navigateMiniAppRoute({\n appId,\n pathSegments: nextPathSegments,\n ...(options.replace === undefined\n ? {}\n : { replace: options.replace }),\n });\n return;\n }\n\n windowSetPathSegments?.(nextPathSegments, options);\n },\n [actions, appId, isGlobalRouted, windowSetPathSegments],\n );\n // \"Can this mini-app step back where it is hosted?\" — browser history in the\n // routed shell, the window's own Back stack in a window. Mini-apps read this\n // rather than branching on navigation mode, so a detail surface that must\n // yield to a real Back affordance asks one question and gets the right answer\n // in both shells.\n const windowGoBack = windowRoute?.goBack;\n const canGoBack = isGlobalRouted\n ? state.history.canGoBack\n : (windowRoute?.canGoBack ?? false);\n const goBack = useCallback(() => {\n if (isGlobalRouted) {\n actions?.goBack();\n return;\n }\n\n windowGoBack?.();\n }, [actions, isGlobalRouted, windowGoBack]);\n\n return useMemo(\n () => ({\n canGoBack,\n goBack,\n isRouted,\n pathSegments,\n setPathSegments,\n }),\n [canGoBack, goBack, isRouted, pathSegments, setPathSegments],\n );\n}\n"]}
|
|
@@ -25,16 +25,18 @@ export interface MiniAppDefinition {
|
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* A launcher application: the mini-apps it can open, the order its launchers
|
|
28
|
-
* list them in,
|
|
28
|
+
* list them in, the ones the windowed desktop opens on entry, and the one the
|
|
29
|
+
* routed shell shows at the root route.
|
|
29
30
|
*/
|
|
30
31
|
export interface LauncherDefinition<AppId extends string = string> {
|
|
31
32
|
apps: Readonly<Record<AppId, MiniAppDefinition>>;
|
|
32
33
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
34
|
+
* Open, in this order, when entering windowed mode with no windows,
|
|
35
|
+
* including on mount, so the last opens in front. Closing the last window
|
|
36
|
+
* leaves the desktop empty until the next entry. Omit to leave window
|
|
37
|
+
* startup to the host. Unknown app ids are skipped.
|
|
36
38
|
*/
|
|
37
|
-
|
|
39
|
+
defaultWindowAppIds?: ReadonlyArray<AppId> | undefined;
|
|
38
40
|
/** Shown at the root route. Defaults to the first app in `order`. */
|
|
39
41
|
homeAppId?: AppId | undefined;
|
|
40
42
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"launcherDefinition.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/launcherDefinition.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"launcherDefinition.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/launcherDefinition.ts"],"names":[],"mappings":"AAkDA,sEAAsE;AACtE,MAAM,UAAU,eAAe,CAC7B,UAAqC,EACrC,KAAgC;IAEhC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC5E,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,oBAAoB,CAClC,UAAqC;IAErC,MAAM,KAAK,GACT,UAAU,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACnD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC;AACrE,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,wBAAwB,CACtC,UAAqC;IAErC,IACE,UAAU,CAAC,SAAS,KAAK,SAAS;QAClC,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,SAAS,CAAC,EACjD,CAAC;QACD,OAAO,UAAU,CAAC,SAAS,CAAC;IAC9B,CAAC;IACD,OAAO,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AACrD,CAAC","sourcesContent":["import type { ComponentType } from \"react\";\nimport type { WindowingIcon } from \"../icons/windowingIcon\";\nimport type { WindowSize } from \"../window/WindowStateProvider\";\n\n/** One app a launcher opens: in a window, or as the routed shell's page. */\nexport interface MiniAppDefinition {\n /**\n * Builds the app's component. A window calls it when it opens, and the\n * routed shell when it shows the app, so each gets its own component.\n */\n createComponent: () => ComponentType;\n /** The app's glyph in the launchers and the taskbar. */\n icon?: WindowingIcon | undefined;\n /**\n * Whether the app's sidebar starts shown, in a new window and on the routed\n * shell's tablet tier. Defaults to shown. The phone tier always starts with\n * the sidebar hidden.\n */\n initialShowSidebar?: boolean | undefined;\n title: string;\n /**\n * The size a new window opens at, in CSS pixels. Defaults to the\n * stylesheet's window size.\n */\n windowSize?: WindowSize | undefined;\n}\n\n/**\n * A launcher application: the mini-apps it can open, the order its launchers\n * list them in, the ones the windowed desktop opens on entry, and the one the\n * routed shell shows at the root route.\n */\nexport interface LauncherDefinition<AppId extends string = string> {\n apps: Readonly<Record<AppId, MiniAppDefinition>>;\n /**\n * Open, in this order, when entering windowed mode with no windows,\n * including on mount, so the last opens in front. Closing the last window\n * leaves the desktop empty until the next entry. Omit to leave window\n * startup to the host. Unknown app ids are skipped.\n */\n defaultWindowAppIds?: ReadonlyArray<AppId> | undefined;\n /** Shown at the root route. Defaults to the first app in `order`. */\n homeAppId?: AppId | undefined;\n /**\n * The order the launchers list the apps in. Ids with no app in `apps` are\n * skipped. Defaults to the order of `apps`' keys.\n */\n order?: ReadonlyArray<AppId> | undefined;\n}\n\n/** Narrows an opaque window `appId` to one of the launcher's apps. */\nexport function isLauncherAppId<AppId extends string>(\n definition: LauncherDefinition<AppId>,\n value: string | null | undefined,\n): value is AppId {\n return typeof value === \"string\" && Object.hasOwn(definition.apps, value);\n}\n\n/** The launcher's apps in the order its launchers list them. */\nexport function resolveLauncherOrder<AppId extends string>(\n definition: LauncherDefinition<AppId>,\n): ReadonlyArray<AppId> {\n const order: ReadonlyArray<string> =\n definition.order ?? Object.keys(definition.apps);\n return order.filter((appId) => isLauncherAppId(definition, appId));\n}\n\n/** The app the routed shell shows at the root route, if the launcher has any. */\nexport function resolveLauncherHomeAppId<AppId extends string>(\n definition: LauncherDefinition<AppId>,\n): AppId | null {\n if (\n definition.homeAppId !== undefined &&\n isLauncherAppId(definition, definition.homeAppId)\n ) {\n return definition.homeAppId;\n }\n return resolveLauncherOrder(definition)[0] ?? null;\n}\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type WindowSize, type WindowStateActions, type WindowStateData } from "../window/WindowStateProvider/index.js";
|
|
2
|
+
import type { LauncherDefinition } from "./launcherDefinition.js";
|
|
3
|
+
/** Where a new window opens when a request names no position. */
|
|
4
|
+
export declare const DEFAULT_MINI_APP_POSITION: {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
};
|
|
8
|
+
/** A request to show an app: in a window, or as the routed shell's page. */
|
|
9
|
+
export interface OpenMiniAppRequest<AppId extends string = string> {
|
|
10
|
+
appId: AppId;
|
|
11
|
+
pathSegments?: ReadonlyArray<string> | undefined;
|
|
12
|
+
/** Where a new window opens. */
|
|
13
|
+
position?: {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
} | undefined;
|
|
17
|
+
/** Raise the app's open window instead of opening another. Defaults to true. */
|
|
18
|
+
reuseExisting?: boolean | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** Where a host opens a new window for an app, and how. */
|
|
21
|
+
export interface MiniAppWindowPlacement {
|
|
22
|
+
/**
|
|
23
|
+
* Open the window fitted to its content, once the content has loaded, as
|
|
24
|
+
* `create`'s `fitToContent` does.
|
|
25
|
+
*/
|
|
26
|
+
fitToContent?: boolean | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Where the window opens, in viewport pixels like a request's `position`.
|
|
29
|
+
* Defaults to the request's position.
|
|
30
|
+
*/
|
|
31
|
+
position?: {
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
} | undefined;
|
|
35
|
+
/** The window's size. Defaults to the app's `windowSize`. */
|
|
36
|
+
size?: WindowSize | undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Places a new window: the host's own geometry for the app a request opens,
|
|
40
|
+
* read when the window opens.
|
|
41
|
+
*/
|
|
42
|
+
export type PlaceMiniAppWindow = (request: OpenMiniAppRequest) => MiniAppWindowPlacement;
|
|
43
|
+
/**
|
|
44
|
+
* Raises the app's open window or opens a new one where `placeWindow` puts
|
|
45
|
+
* it, else at the request's position or {@link DEFAULT_MINI_APP_POSITION},
|
|
46
|
+
* sized by the app's `windowSize`. Returns the window's id.
|
|
47
|
+
*/
|
|
48
|
+
export declare function openMiniAppWindow({ actions, definition, placeWindow, request, windows, }: {
|
|
49
|
+
actions: Pick<WindowStateActions, "bringToFront" | "create" | "restore" | "updateRoute">;
|
|
50
|
+
definition: LauncherDefinition;
|
|
51
|
+
placeWindow: PlaceMiniAppWindow | undefined;
|
|
52
|
+
request: OpenMiniAppRequest;
|
|
53
|
+
windows: WindowStateData["windows"];
|
|
54
|
+
}): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { findTopWindow, } from "../window/WindowStateProvider/index.js";
|
|
2
|
+
/** Where a new window opens when a request names no position. */
|
|
3
|
+
export const DEFAULT_MINI_APP_POSITION = { x: 200, y: 160 };
|
|
4
|
+
/**
|
|
5
|
+
* Raises the app's open window or opens a new one where `placeWindow` puts
|
|
6
|
+
* it, else at the request's position or {@link DEFAULT_MINI_APP_POSITION},
|
|
7
|
+
* sized by the app's `windowSize`. Returns the window's id.
|
|
8
|
+
*/
|
|
9
|
+
export function openMiniAppWindow({ actions, definition, placeWindow, request, windows, }) {
|
|
10
|
+
const { appId, pathSegments, reuseExisting = true } = request;
|
|
11
|
+
const existingWindow = reuseExisting
|
|
12
|
+
? findTopWindow(windows, (windowEntry) => windowEntry.appId === appId)
|
|
13
|
+
: null;
|
|
14
|
+
if (existingWindow) {
|
|
15
|
+
actions.restore(existingWindow.id);
|
|
16
|
+
actions.bringToFront(existingWindow.id);
|
|
17
|
+
if (pathSegments) {
|
|
18
|
+
actions.updateRoute(existingWindow.id, pathSegments);
|
|
19
|
+
}
|
|
20
|
+
return existingWindow.id;
|
|
21
|
+
}
|
|
22
|
+
const app = definition.apps[appId];
|
|
23
|
+
if (!app) {
|
|
24
|
+
throw new Error(`Unknown mini-app: ${appId}`);
|
|
25
|
+
}
|
|
26
|
+
const placement = placeWindow?.(request) ?? {};
|
|
27
|
+
const position = placement.position ?? request.position ?? DEFAULT_MINI_APP_POSITION;
|
|
28
|
+
const size = placement.size ?? app.windowSize;
|
|
29
|
+
return actions.create(app.title, position.x, position.y, app.createComponent(), {
|
|
30
|
+
appId,
|
|
31
|
+
initialShowSidebar: app.initialShowSidebar,
|
|
32
|
+
...(placement.fitToContent ? { fitToContent: true } : {}),
|
|
33
|
+
...(pathSegments ? { pathSegments } : {}),
|
|
34
|
+
...(size ? { size } : {}),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=openMiniAppWindow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openMiniAppWindow.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/openMiniAppWindow.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAId,MAAM,+BAA+B,CAAC;AAGvC,iEAAiE;AACjE,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;AAoC5D;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAChC,OAAO,EACP,UAAU,EACV,WAAW,EACX,OAAO,EACP,OAAO,GAUR;IACC,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,aAAa,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAC9D,MAAM,cAAc,GAAG,aAAa;QAClC,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,KAAK,KAAK,CAAC;QACtE,CAAC,CAAC,IAAI,CAAC;IACT,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;QACnC,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;QACxC,IAAI,YAAY,EAAE,CAAC;YACjB,OAAO,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,cAAc,CAAC,EAAE,CAAC;IAC3B,CAAC;IAED,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,qBAAqB,KAAK,EAAE,CAAC,CAAC;IAChD,CAAC;IACD,MAAM,SAAS,GAAG,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/C,MAAM,QAAQ,GACZ,SAAS,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,IAAI,yBAAyB,CAAC;IACtE,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,IAAI,GAAG,CAAC,UAAU,CAAC;IAC9C,OAAO,OAAO,CAAC,MAAM,CACnB,GAAG,CAAC,KAAK,EACT,QAAQ,CAAC,CAAC,EACV,QAAQ,CAAC,CAAC,EACV,GAAG,CAAC,eAAe,EAAE,EACrB;QACE,KAAK;QACL,kBAAkB,EAAE,GAAG,CAAC,kBAAkB;QAC1C,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzD,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1B,CACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n findTopWindow,\n type WindowSize,\n type WindowStateActions,\n type WindowStateData,\n} from \"../window/WindowStateProvider\";\nimport type { LauncherDefinition } from \"./launcherDefinition\";\n\n/** Where a new window opens when a request names no position. */\nexport const DEFAULT_MINI_APP_POSITION = { x: 200, y: 160 };\n\n/** A request to show an app: in a window, or as the routed shell's page. */\nexport interface OpenMiniAppRequest<AppId extends string = string> {\n appId: AppId;\n pathSegments?: ReadonlyArray<string> | undefined;\n /** Where a new window opens. */\n position?: { x: number; y: number } | undefined;\n /** Raise the app's open window instead of opening another. Defaults to true. */\n reuseExisting?: boolean | undefined;\n}\n\n/** Where a host opens a new window for an app, and how. */\nexport interface MiniAppWindowPlacement {\n /**\n * Open the window fitted to its content, once the content has loaded, as\n * `create`'s `fitToContent` does.\n */\n fitToContent?: boolean | undefined;\n /**\n * Where the window opens, in viewport pixels like a request's `position`.\n * Defaults to the request's position.\n */\n position?: { x: number; y: number } | undefined;\n /** The window's size. Defaults to the app's `windowSize`. */\n size?: WindowSize | undefined;\n}\n\n/**\n * Places a new window: the host's own geometry for the app a request opens,\n * read when the window opens.\n */\nexport type PlaceMiniAppWindow = (\n request: OpenMiniAppRequest,\n) => MiniAppWindowPlacement;\n\n/**\n * Raises the app's open window or opens a new one where `placeWindow` puts\n * it, else at the request's position or {@link DEFAULT_MINI_APP_POSITION},\n * sized by the app's `windowSize`. Returns the window's id.\n */\nexport function openMiniAppWindow({\n actions,\n definition,\n placeWindow,\n request,\n windows,\n}: {\n actions: Pick<\n WindowStateActions,\n \"bringToFront\" | \"create\" | \"restore\" | \"updateRoute\"\n >;\n definition: LauncherDefinition;\n placeWindow: PlaceMiniAppWindow | undefined;\n request: OpenMiniAppRequest;\n windows: WindowStateData[\"windows\"];\n}): string {\n const { appId, pathSegments, reuseExisting = true } = request;\n const existingWindow = reuseExisting\n ? findTopWindow(windows, (windowEntry) => windowEntry.appId === appId)\n : null;\n if (existingWindow) {\n actions.restore(existingWindow.id);\n actions.bringToFront(existingWindow.id);\n if (pathSegments) {\n actions.updateRoute(existingWindow.id, pathSegments);\n }\n return existingWindow.id;\n }\n\n const app = definition.apps[appId];\n if (!app) {\n throw new Error(`Unknown mini-app: ${appId}`);\n }\n const placement = placeWindow?.(request) ?? {};\n const position =\n placement.position ?? request.position ?? DEFAULT_MINI_APP_POSITION;\n const size = placement.size ?? app.windowSize;\n return actions.create(\n app.title,\n position.x,\n position.y,\n app.createComponent(),\n {\n appId,\n initialShowSidebar: app.initialShowSidebar,\n ...(placement.fitToContent ? { fitToContent: true } : {}),\n ...(pathSegments ? { pathSegments } : {}),\n ...(size ? { size } : {}),\n },\n );\n}\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type LauncherDefinition } from "./launcherDefinition.js";
|
|
2
2
|
import type { NavigationMode } from "./navigationMode.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Opens the host's default windows, in order so the last is in front, once
|
|
5
|
+
* per entry into an empty windowed desktop.
|
|
6
|
+
*/
|
|
4
7
|
export declare function useDefaultWindow({ definition, enabled, mode, openMiniApp, windowCount, }: {
|
|
5
8
|
definition: LauncherDefinition;
|
|
6
9
|
enabled: boolean;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { useEffect, useRef } from "react";
|
|
2
2
|
import { isLauncherAppId } from "./launcherDefinition.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Opens the host's default windows, in order so the last is in front, once
|
|
5
|
+
* per entry into an empty windowed desktop.
|
|
6
|
+
*/
|
|
4
7
|
export function useDefaultWindow({ definition, enabled, mode, openMiniApp, windowCount, }) {
|
|
5
8
|
const handledWindowedEntry = useRef(false);
|
|
6
9
|
useEffect(() => {
|
|
@@ -12,9 +15,13 @@ export function useDefaultWindow({ definition, enabled, mode, openMiniApp, windo
|
|
|
12
15
|
return;
|
|
13
16
|
// Record the entry before opening, including across StrictMode effects.
|
|
14
17
|
handledWindowedEntry.current = true;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
if (windowCount > 0)
|
|
19
|
+
return;
|
|
20
|
+
// Each app once: the launcher's open requests within this pass cannot see
|
|
21
|
+
// the windows the earlier ones created.
|
|
22
|
+
for (const appId of new Set(definition.defaultWindowAppIds)) {
|
|
23
|
+
if (isLauncherAppId(definition, appId))
|
|
24
|
+
openMiniApp({ appId });
|
|
18
25
|
}
|
|
19
26
|
}, [definition, enabled, mode, openMiniApp, windowCount]);
|
|
20
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDefaultWindow.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/useDefaultWindow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,eAAe,EAA2B,MAAM,sBAAsB,CAAC;AAGhF
|
|
1
|
+
{"version":3,"file":"useDefaultWindow.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/useDefaultWindow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,eAAe,EAA2B,MAAM,sBAAsB,CAAC;AAGhF;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,UAAU,EACV,OAAO,EACP,IAAI,EACJ,WAAW,EACX,WAAW,GAOZ;IACC,MAAM,oBAAoB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAE3C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;YACxB,oBAAoB,CAAC,OAAO,GAAG,KAAK,CAAC;YACrC,OAAO;QACT,CAAC;QACD,IAAI,CAAC,OAAO,IAAI,oBAAoB,CAAC,OAAO;YAAE,OAAO;QACrD,wEAAwE;QACxE,oBAAoB,CAAC,OAAO,GAAG,IAAI,CAAC;QACpC,IAAI,WAAW,GAAG,CAAC;YAAE,OAAO;QAC5B,0EAA0E;QAC1E,wCAAwC;QACxC,KAAK,MAAM,KAAK,IAAI,IAAI,GAAG,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE,CAAC;YAC5D,IAAI,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC;gBAAE,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QACjE,CAAC;IACH,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { isLauncherAppId, type LauncherDefinition } from \"./launcherDefinition\";\nimport type { NavigationMode } from \"./navigationMode\";\n\n/**\n * Opens the host's default windows, in order so the last is in front, once\n * per entry into an empty windowed desktop.\n */\nexport function useDefaultWindow({\n definition,\n enabled,\n mode,\n openMiniApp,\n windowCount,\n}: {\n definition: LauncherDefinition;\n enabled: boolean;\n mode: NavigationMode;\n openMiniApp: (request: { appId: string }) => string | null;\n windowCount: number;\n}) {\n const handledWindowedEntry = useRef(false);\n\n useEffect(() => {\n if (mode !== \"windowed\") {\n handledWindowedEntry.current = false;\n return;\n }\n if (!enabled || handledWindowedEntry.current) return;\n // Record the entry before opening, including across StrictMode effects.\n handledWindowedEntry.current = true;\n if (windowCount > 0) return;\n // Each app once: the launcher's open requests within this pass cannot see\n // the windows the earlier ones created.\n for (const appId of new Set(definition.defaultWindowAppIds)) {\n if (isLauncherAppId(definition, appId)) openMiniApp({ appId });\n }\n }, [definition, enabled, mode, openMiniApp, windowCount]);\n}\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;Q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st 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.33",
|
|
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,0BA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AChE,UAAU,CAAC,iBAAiB,CAAC,CAAC;IAChC,MAAM,KAAK,GAAG,MAAM,CAAS,EAAE,CAAC,CAAC;IACjC,MAAM,kBAAkB,GAAG,MAAM,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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E,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,IAAuC;IAEvC,MAAM,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,GAC1D,UAAU,CAAC,iBAAiB,CAAC,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/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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"]}
|