@tearleads/windowing 0.2.11 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +93 -1
  2. package/index.d.ts +19 -0
  3. package/index.js +20 -1
  4. package/index.js.map +1 -1
  5. package/launcher/LauncherNavigationProvider.d.ts +71 -0
  6. package/launcher/LauncherNavigationProvider.js +253 -0
  7. package/launcher/LauncherNavigationProvider.js.map +1 -0
  8. package/launcher/MiniAppRouteSegmentsContext.d.ts +19 -0
  9. package/launcher/MiniAppRouteSegmentsContext.js +26 -0
  10. package/launcher/MiniAppRouteSegmentsContext.js.map +1 -0
  11. package/launcher/MiniAppWindow.d.ts +18 -0
  12. package/launcher/MiniAppWindow.js +41 -0
  13. package/launcher/MiniAppWindow.js.map +1 -0
  14. package/launcher/NavigationModeOverrideProvider.d.ts +23 -0
  15. package/launcher/NavigationModeOverrideProvider.js +31 -0
  16. package/launcher/NavigationModeOverrideProvider.js.map +1 -0
  17. package/launcher/NavigationModeSwitch.css +22 -0
  18. package/launcher/NavigationModeSwitch.d.ts +24 -0
  19. package/launcher/NavigationModeSwitch.js +40 -0
  20. package/launcher/NavigationModeSwitch.js.map +1 -0
  21. package/launcher/breakpoints.d.ts +17 -0
  22. package/launcher/breakpoints.js +18 -0
  23. package/launcher/breakpoints.js.map +1 -0
  24. package/launcher/launcherDefinition.d.ts +39 -0
  25. package/launcher/launcherDefinition.js +18 -0
  26. package/launcher/launcherDefinition.js.map +1 -0
  27. package/launcher/navigationHistory.d.ts +16 -0
  28. package/launcher/navigationHistory.js +48 -0
  29. package/launcher/navigationHistory.js.map +1 -0
  30. package/launcher/navigationMode.d.ts +31 -0
  31. package/launcher/navigationMode.js +35 -0
  32. package/launcher/navigationMode.js.map +1 -0
  33. package/launcher/routePaths.d.ts +17 -0
  34. package/launcher/routePaths.js +46 -0
  35. package/launcher/routePaths.js.map +1 -0
  36. package/launcher/routedPathNavigator.d.ts +20 -0
  37. package/launcher/routedPathNavigator.js +36 -0
  38. package/launcher/routedPathNavigator.js.map +1 -0
  39. package/launcher/storedPreference.d.ts +7 -0
  40. package/launcher/storedPreference.js +43 -0
  41. package/launcher/storedPreference.js.map +1 -0
  42. package/launcher/useActiveLauncherRoute.d.ts +14 -0
  43. package/launcher/useActiveLauncherRoute.js +41 -0
  44. package/launcher/useActiveLauncherRoute.js.map +1 -0
  45. package/launcher/useCompactRoutedMode.d.ts +2 -0
  46. package/launcher/useCompactRoutedMode.js +9 -0
  47. package/launcher/useCompactRoutedMode.js.map +1 -0
  48. package/launcher/useMiniAppRouteState.d.ts +14 -0
  49. package/launcher/useMiniAppRouteState.js +15 -0
  50. package/launcher/useMiniAppRouteState.js.map +1 -0
  51. package/launcher/useNavigationMode.d.ts +23 -0
  52. package/launcher/useNavigationMode.js +34 -0
  53. package/launcher/useNavigationMode.js.map +1 -0
  54. package/launcher/useNavigationModeDocumentAttribute.d.ts +16 -0
  55. package/launcher/useNavigationModeDocumentAttribute.js +24 -0
  56. package/launcher/useNavigationModeDocumentAttribute.js.map +1 -0
  57. package/launcher/useRoutedLayoutActive.d.ts +25 -0
  58. package/launcher/useRoutedLayoutActive.js +69 -0
  59. package/launcher/useRoutedLayoutActive.js.map +1 -0
  60. package/launcher/useRoutedLayoutTier.d.ts +17 -0
  61. package/launcher/useRoutedLayoutTier.js +24 -0
  62. package/launcher/useRoutedLayoutTier.js.map +1 -0
  63. package/package.json +1 -1
  64. package/routed/RoutedPane.css +393 -0
  65. package/routed/RoutedPane.d.ts +63 -0
  66. package/routed/RoutedPane.js +91 -0
  67. package/routed/RoutedPane.js.map +1 -0
  68. package/routed/RoutedPaneAppBar.d.ts +8 -0
  69. package/routed/RoutedPaneAppBar.js +23 -0
  70. package/routed/RoutedPaneAppBar.js.map +1 -0
  71. package/routed/RoutedPaneMain.d.ts +15 -0
  72. package/routed/RoutedPaneMain.js +27 -0
  73. package/routed/RoutedPaneMain.js.map +1 -0
  74. package/routed/RoutedPaneNav.css +298 -0
  75. package/routed/RoutedPaneNav.d.ts +20 -0
  76. package/routed/RoutedPaneNav.js +106 -0
  77. package/routed/RoutedPaneNav.js.map +1 -0
  78. package/routed/RoutedPaneOverlayHost.d.ts +37 -0
  79. package/routed/RoutedPaneOverlayHost.js +29 -0
  80. package/routed/RoutedPaneOverlayHost.js.map +1 -0
  81. package/routed/RoutedPanePlacementButton.d.ts +5 -0
  82. package/routed/RoutedPanePlacementButton.js +10 -0
  83. package/routed/RoutedPanePlacementButton.js.map +1 -0
  84. package/routed/RoutedPaneSidebar.css +61 -0
  85. package/routed/RoutedPaneSidebar.d.ts +7 -0
  86. package/routed/RoutedPaneSidebar.js +18 -0
  87. package/routed/RoutedPaneSidebar.js.map +1 -0
  88. package/routed/RoutedPaneTaskBar.d.ts +24 -0
  89. package/routed/RoutedPaneTaskBar.js +24 -0
  90. package/routed/RoutedPaneTaskBar.js.map +1 -0
  91. package/routed/classNames.d.ts +2 -0
  92. package/routed/classNames.js +6 -0
  93. package/routed/classNames.js.map +1 -0
  94. package/routed/launcherPlacement.d.ts +7 -0
  95. package/routed/launcherPlacement.js +8 -0
  96. package/routed/launcherPlacement.js.map +1 -0
  97. package/routed/useMobileKeyboardVisible.d.ts +7 -0
  98. package/routed/useMobileKeyboardVisible.js +78 -0
  99. package/routed/useMobileKeyboardVisible.js.map +1 -0
  100. package/routed/useMobileSheetDrag.d.ts +10 -0
  101. package/routed/useMobileSheetDrag.js +83 -0
  102. package/routed/useMobileSheetDrag.js.map +1 -0
  103. package/routed/useRoutedPaneOverlays.d.ts +25 -0
  104. package/routed/useRoutedPaneOverlays.js +72 -0
  105. package/routed/useRoutedPaneOverlays.js.map +1 -0
  106. package/tokens.css +24 -0
package/README.md CHANGED
@@ -3,7 +3,9 @@
3
3
  App-agnostic window management for React: window state (open, focus order,
4
4
  minimize/maximize, a per-window route and Back stack), window chrome (title
5
5
  bar, menu bar, toolbar, sidebar, status bar, resize handles), the menu and
6
- sidebar primitives that chrome renders with, and a taskbar's start menu.
6
+ sidebar primitives that chrome renders with, a taskbar's start menu, and a
7
+ launcher that runs a set of mini-apps in windows or in the routed (iPad /
8
+ phone) shell.
7
9
 
8
10
  The package knows nothing about the applications that run inside its windows.
9
11
  It depends only on React, react-dom, and Phosphor icons, which draw the
@@ -185,6 +187,93 @@ host's own button styles apply alone. A menu that needs more than a list passes
185
187
  and a `close` callback. Tearleads' footer does this in
186
188
  `packages/app/src/shell/pane/footer/PaneFooter.tsx`.
187
189
 
190
+ ## Launching mini-apps
191
+
192
+ A launcher application is a set of mini-apps, defined once and shown either in
193
+ windows on a desktop or one at a time in the routed shell. A
194
+ `LauncherDefinition` lists the apps by id, the order the launchers show them in,
195
+ and the app the routed shell shows at the root route:
196
+
197
+ ```tsx
198
+ import type { LauncherDefinition } from "@tearleads/windowing";
199
+
200
+ const LAUNCHER: LauncherDefinition<"notes" | "contacts"> = {
201
+ apps: {
202
+ contacts: {
203
+ createComponent: () => ContactsApp,
204
+ icon: AddressBookIcon,
205
+ title: "Contacts",
206
+ },
207
+ notes: {
208
+ createComponent: () => NotesApp,
209
+ icon: NoteIcon,
210
+ initialShowSidebar: false,
211
+ title: "Notes",
212
+ },
213
+ },
214
+ homeAppId: "notes",
215
+ order: ["notes", "contacts"],
216
+ };
217
+ ```
218
+
219
+ `LauncherNavigationProvider` takes the definition and a `NavigationMode`, and
220
+ goes inside a `WindowStateProvider`. In `windowed` mode
221
+ `useLauncherNavigationActions().openMiniApp({ appId })` opens the app's window,
222
+ or raises the one already open; in `routed` mode it pushes the app's route,
223
+ `/app/<app id>/…`, onto browser history, and Back and Forward walk it. Render
224
+ each window with `MiniAppWindow`, whose `AppBoundary` slot wraps the app (for
225
+ example in an error boundary).
226
+
227
+ A mini-app reads and sets its own route with `useMiniAppRouteSegments(appId)`,
228
+ or `useMiniAppRouteState` for a parsed route: the browser route in the routed
229
+ shell, its window's own route and Back stack in a window. It registers its
230
+ sidebar and toolbar actions with the window hooks, and both shells show them.
231
+
232
+ `useNavigationMode` picks the mode: the user's choice from
233
+ `NavigationModeOverrideProvider` (which persists it under a `storageKey`)
234
+ first, while that choice suits the screen; then a host's `forcedMode`; then
235
+ `preferredMode`, which defaults to `routed`.
236
+ `NavigationModeSwitch`, for a taskbar's corner, records that choice: given the
237
+ layout showing it, it offers the other ("Switch to iPad / mobile layout"). Windowed
238
+ applies only where windows suit the screen: at least 1024px wide, with a fine
239
+ pointer, and not an iPad. Pass the mode to
240
+ `useNavigationModeDocumentAttribute`, which stamps
241
+ `<html data-navigation-mode>`; the routed touch sizes key off it (see
242
+ [Styles](#styles)), and `useRoutedLayoutActive` reads it back.
243
+
244
+ ## Routed shell
245
+
246
+ `RoutedPane` is the routed shell, the iPad / phone layout: one mini-app at a
247
+ time, chosen by the route, under an app bar with Back, Forward, the app's
248
+ sidebar toggle, its title, and its toolbar actions, above a taskbar. Below 760px
249
+ (`ROUTED_TABLET_BREAKPOINT_PX`) it is a phone layout whose launcher is a bottom
250
+ sheet of app tiles; at or above it, a tablet layout whose launcher is a left
251
+ rail or, at the user's choice, the same sheet. Mini-apps put their actions in
252
+ the toolbar: the routed shell has no menu bar.
253
+
254
+ ```tsx
255
+ <WindowStateProvider>
256
+ <LauncherNavigationProvider definition={LAUNCHER} mode="routed">
257
+ <RoutedPane
258
+ AppBoundary={AppErrorBoundary}
259
+ menuIcon={<Logo />}
260
+ taskbarTray={<ModeSwitch />}
261
+ />
262
+ </LauncherNavigationProvider>
263
+ </WindowStateProvider>
264
+ ```
265
+
266
+ The host fills its chrome: `menuIcon` is the taskbar's centered launcher
267
+ button, `taskbarTray` its end-aligned tray, `contentTop` rides above the active
268
+ app, and `renderAboveTaskbar` draws a strip above the taskbar, told whether the
269
+ phone's software keyboard is open. `appIds` narrows the apps the launcher
270
+ offers, such as to those the session may see, and
271
+ `subscribeKeyboardVisibility` reports a native keyboard a WebView hides.
272
+ Overlays that should fill the content pane rather than the screen portal into
273
+ `useRoutedPaneOverlayHost().host`. The shell sizes to the box its host gives
274
+ `.routed-pane`, as a grid item or a block with a height. Tearleads dresses it in
275
+ `packages/app/src/shell/layout/routed/AppRoutedPane.tsx`.
276
+
188
277
  ## Styles
189
278
 
190
279
  Each component imports its own stylesheet, so a bundler that handles CSS imports
@@ -199,6 +288,9 @@ entry imports `tokens.css`, which defines every one of them under
199
288
  window. That rule has zero specificity: any `:root` rule, theme, or scoped block
200
289
  the host writes overrides it. Tearleads overrides them with its own themes in
201
290
  `packages/ui/src/styles.css` and `packages/app/src/shell/layout/AppChrome.css`.
291
+ The routed shell also reads the screen's safe areas (`--safe-area-*`) and, under
292
+ `:root[data-navigation-mode="routed"]`, a 44px `--control-height` and 24px
293
+ `--control-icon-size`, which `tokens.css` defines the same way.
202
294
 
203
295
  Several defaults derive from `--color-dark`, the foreground: the window edge
204
296
  (`--border-strong-color`), the hover and selection chip (`--emphasis-surface`
package/index.d.ts CHANGED
@@ -1,10 +1,29 @@
1
1
  export { createRequiredContext, type RequiredContext, } from "./createRequiredContext.js";
2
2
  export { type WindowingIcons, WindowingIconsProvider, } from "./icons/WindowingIcons.js";
3
3
  export type { WindowingIcon, WindowingIconProps } from "./icons/windowingIcon.js";
4
+ export { ROUTED_TABLET_BREAKPOINT_PX, ROUTED_TABLET_QUERY, WINDOWED_LAYOUT_MIN_WIDTH_PX, } from "./launcher/breakpoints.js";
5
+ export { DEFAULT_MINI_APP_POSITION, type LauncherNavigationActions, LauncherNavigationProvider, type LauncherNavigationState, type OpenMiniAppRequest, useLauncherNavigationActions, useLauncherNavigationState, useMiniAppRouteSegments, useOptionalLauncherNavigationState, } from "./launcher/LauncherNavigationProvider.js";
6
+ export { isLauncherAppId, type LauncherDefinition, type MiniAppDefinition, resolveLauncherHomeAppId, resolveLauncherOrder, } from "./launcher/launcherDefinition.js";
7
+ export { MiniAppRouteSegmentsProvider, useMiniAppWindowRouteSegments, } from "./launcher/MiniAppRouteSegmentsContext.js";
8
+ export { type MiniAppBoundary, MiniAppWindow } from "./launcher/MiniAppWindow.js";
9
+ export { NavigationModeOverrideProvider, useNavigationModeOverride, useOptionalNavigationModeOverride, } from "./launcher/NavigationModeOverrideProvider.js";
10
+ export { NavigationModeSwitch } from "./launcher/NavigationModeSwitch.js";
11
+ export { isWindowedLayoutEligible, type NavigationEnvironment, type NavigationMode, readNavigationEnvironment, resolveNavigationMode, } from "./launcher/navigationMode.js";
12
+ export { buildMiniAppPath, type LauncherRoute, parseLauncherRoute, } from "./launcher/routePaths.js";
13
+ export { resolveActiveLauncherRoute, useActiveLauncherRoute, } from "./launcher/useActiveLauncherRoute.js";
14
+ export { useCompactRoutedMode } from "./launcher/useCompactRoutedMode.js";
15
+ export { type MiniAppRouteSetOptions, useMiniAppRouteState, } from "./launcher/useMiniAppRouteState.js";
16
+ export { useNavigationMode } from "./launcher/useNavigationMode.js";
17
+ export { useNavigationModeDocumentAttribute } from "./launcher/useNavigationModeDocumentAttribute.js";
18
+ export { useRoutedLayoutActive, useWindowedLayoutActive, } from "./launcher/useRoutedLayoutActive.js";
19
+ export { type RoutedLayoutTier, useRoutedLayoutTier, } from "./launcher/useRoutedLayoutTier.js";
4
20
  export { Menu, type MenuPosition } from "./menu/Menu.js";
5
21
  export { MenuItem, type MenuItemProps } from "./menu/MenuItem.js";
6
22
  export { StartMenu, type StartMenuItem, type StartMenuProps, } from "./menu/StartMenu.js";
7
23
  export { type ContextMenuState, useContextMenuPositionState, useContextMenuState, } from "./menu/useContextMenuState.js";
24
+ export { RoutedPane, type RoutedPaneProps } from "./routed/RoutedPane.js";
25
+ export { RoutedPaneOverlayHostProvider, type RoutedPaneOverlayHostValue, useRoutedPaneOverlayHost, } from "./routed/RoutedPaneOverlayHost.js";
26
+ export type { SubscribeKeyboardVisibility } from "./routed/useMobileKeyboardVisible.js";
8
27
  export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.js";
9
28
  export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, useWindowBackground, useWindowContentSize, } from "./window/CurrentWindowContext.js";
10
29
  export { Window, type WindowContentBoundary } from "./window/Window.js";
package/index.js CHANGED
@@ -1,13 +1,32 @@
1
1
  import "./tokens.css";
2
2
  // The public windowing API: window state, window chrome and its registration
3
3
  // hooks, the menu and sidebar primitives the chrome renders with, a taskbar's
4
- // start menu, and the icons the chrome draws.
4
+ // start menu, the icons the chrome draws, and a launcher of mini-apps that
5
+ // shows them in windows or in the routed (iPad / phone) shell.
5
6
  export { createRequiredContext, } from "./createRequiredContext.js";
6
7
  export { WindowingIconsProvider, } from "./icons/WindowingIcons.js";
8
+ export { ROUTED_TABLET_BREAKPOINT_PX, ROUTED_TABLET_QUERY, WINDOWED_LAYOUT_MIN_WIDTH_PX, } from "./launcher/breakpoints.js";
9
+ export { DEFAULT_MINI_APP_POSITION, LauncherNavigationProvider, useLauncherNavigationActions, useLauncherNavigationState, useMiniAppRouteSegments, useOptionalLauncherNavigationState, } from "./launcher/LauncherNavigationProvider.js";
10
+ export { isLauncherAppId, resolveLauncherHomeAppId, resolveLauncherOrder, } from "./launcher/launcherDefinition.js";
11
+ export { MiniAppRouteSegmentsProvider, useMiniAppWindowRouteSegments, } from "./launcher/MiniAppRouteSegmentsContext.js";
12
+ export { MiniAppWindow } from "./launcher/MiniAppWindow.js";
13
+ export { NavigationModeOverrideProvider, useNavigationModeOverride, useOptionalNavigationModeOverride, } from "./launcher/NavigationModeOverrideProvider.js";
14
+ export { NavigationModeSwitch } from "./launcher/NavigationModeSwitch.js";
15
+ export { isWindowedLayoutEligible, readNavigationEnvironment, resolveNavigationMode, } from "./launcher/navigationMode.js";
16
+ export { buildMiniAppPath, parseLauncherRoute, } from "./launcher/routePaths.js";
17
+ export { resolveActiveLauncherRoute, useActiveLauncherRoute, } from "./launcher/useActiveLauncherRoute.js";
18
+ export { useCompactRoutedMode } from "./launcher/useCompactRoutedMode.js";
19
+ export { useMiniAppRouteState, } from "./launcher/useMiniAppRouteState.js";
20
+ export { useNavigationMode } from "./launcher/useNavigationMode.js";
21
+ export { useNavigationModeDocumentAttribute } from "./launcher/useNavigationModeDocumentAttribute.js";
22
+ export { useRoutedLayoutActive, useWindowedLayoutActive, } from "./launcher/useRoutedLayoutActive.js";
23
+ export { useRoutedLayoutTier, } from "./launcher/useRoutedLayoutTier.js";
7
24
  export { Menu } from "./menu/Menu.js";
8
25
  export { MenuItem } from "./menu/MenuItem.js";
9
26
  export { StartMenu, } from "./menu/StartMenu.js";
10
27
  export { useContextMenuPositionState, useContextMenuState, } from "./menu/useContextMenuState.js";
28
+ export { RoutedPane } from "./routed/RoutedPane.js";
29
+ export { RoutedPaneOverlayHostProvider, useRoutedPaneOverlayHost, } from "./routed/RoutedPaneOverlayHost.js";
11
30
  export { SidebarResizeHandle, useSidebarResize } from "./sidebar/SidebarResize.js";
12
31
  export { CurrentWindowProvider, useCurrentWindow, useSuppressWindowToolbar, useWindowBackground, useWindowContentSize, } from "./window/CurrentWindowContext.js";
13
32
  export { Window } from "./window/Window.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,8CAA8C;AAC9C,OAAO,EACL,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,IAAI,EAAqB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAsB,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EACL,SAAS,GAGV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,MAAM,EAA8B,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,6BAA6B,EAC7B,uBAAuB,EACvB,wBAAwB,EACxB,2BAA2B,EAC3B,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAQlB,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["import \"./tokens.css\";\n\n// The public windowing API: window state, window chrome and its registration\n// hooks, the menu and sidebar primitives the chrome renders with, a taskbar's\n// start menu, and the icons the chrome draws.\nexport {\n createRequiredContext,\n type RequiredContext,\n} from \"./createRequiredContext\";\nexport {\n type WindowingIcons,\n WindowingIconsProvider,\n} from \"./icons/WindowingIcons\";\nexport type { WindowingIcon, WindowingIconProps } from \"./icons/windowingIcon\";\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 { SidebarResizeHandle, useSidebarResize } from \"./sidebar/SidebarResize\";\nexport {\n CurrentWindowProvider,\n useCurrentWindow,\n useSuppressWindowToolbar,\n useWindowBackground,\n useWindowContentSize,\n} from \"./window/CurrentWindowContext\";\nexport { Window, type WindowContentBoundary } from \"./window/Window\";\nexport { WindowTitleBarActionButtons } from \"./window/WindowChromeActions\";\nexport { WindowCloseButton } from \"./window/WindowCloseButton\";\nexport {\n useWindowBackAction,\n useWindowBackActionValue,\n useWindowFileMenuItem,\n useWindowRefreshMenuItem,\n useWindowRefreshMenuItemValue,\n useWindowTitleBarAction,\n useWindowTitleBarActions,\n useWindowToolbarReservation,\n useWindowViewMenuItem,\n WindowMenuProvider,\n} from \"./window/WindowMenuContext\";\nexport {\n hasWindowSidebar,\n useRegisteredWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./window/WindowSidebarContext\";\nexport {\n findTopWindow,\n useWindowActions,\n useWindowStateData,\n type WindowCreateOptions,\n type WindowEntry,\n type WindowGeometry,\n type WindowPosition,\n type WindowSize,\n type WindowStateActions,\n type WindowStateData,\n WindowStateProvider,\n} from \"./window/WindowStateProvider\";\nexport { WindowToolBar } from \"./window/WindowToolBar\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../home/runner/work/tearleads/tearleads/packages/windowing/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,6EAA6E;AAC7E,8EAA8E;AAC9E,2EAA2E;AAC3E,+DAA+D;AAC/D,OAAO,EACL,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,yBAAyB,EAEzB,0BAA0B,EAG1B,4BAA4B,EAC5B,0BAA0B,EAC1B,uBAAuB,EACvB,kCAAkC,GACnC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,eAAe,EAGf,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;A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qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,MAAM,EAA8B,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,6BAA6B,EAC7B,uBAAuB,EACvB,wBAAwB,EACxB,2BAA2B,EAC3B,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAQlB,mBAAmB,GACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["import \"./tokens.css\";\n\n// The public windowing API: window state, window chrome and its registration\n// hooks, the menu and sidebar primitives the chrome renders with, a taskbar's\n// start menu, the icons the chrome draws, and a launcher of mini-apps that\n// shows them in windows or in the routed (iPad / phone) shell.\nexport {\n createRequiredContext,\n type RequiredContext,\n} from \"./createRequiredContext\";\nexport {\n type WindowingIcons,\n WindowingIconsProvider,\n} from \"./icons/WindowingIcons\";\nexport type { WindowingIcon, WindowingIconProps } from \"./icons/windowingIcon\";\nexport {\n ROUTED_TABLET_BREAKPOINT_PX,\n ROUTED_TABLET_QUERY,\n WINDOWED_LAYOUT_MIN_WIDTH_PX,\n} from \"./launcher/breakpoints\";\nexport {\n DEFAULT_MINI_APP_POSITION,\n type LauncherNavigationActions,\n LauncherNavigationProvider,\n type LauncherNavigationState,\n type OpenMiniAppRequest,\n useLauncherNavigationActions,\n useLauncherNavigationState,\n useMiniAppRouteSegments,\n useOptionalLauncherNavigationState,\n} from \"./launcher/LauncherNavigationProvider\";\nexport {\n isLauncherAppId,\n type LauncherDefinition,\n type MiniAppDefinition,\n resolveLauncherHomeAppId,\n resolveLauncherOrder,\n} from \"./launcher/launcherDefinition\";\nexport {\n MiniAppRouteSegmentsProvider,\n useMiniAppWindowRouteSegments,\n} from \"./launcher/MiniAppRouteSegmentsContext\";\nexport { type MiniAppBoundary, MiniAppWindow } from \"./launcher/MiniAppWindow\";\nexport {\n NavigationModeOverrideProvider,\n useNavigationModeOverride,\n useOptionalNavigationModeOverride,\n} from \"./launcher/NavigationModeOverrideProvider\";\nexport { NavigationModeSwitch } from \"./launcher/NavigationModeSwitch\";\nexport {\n isWindowedLayoutEligible,\n type NavigationEnvironment,\n type NavigationMode,\n readNavigationEnvironment,\n resolveNavigationMode,\n} from \"./launcher/navigationMode\";\nexport {\n buildMiniAppPath,\n type LauncherRoute,\n parseLauncherRoute,\n} from \"./launcher/routePaths\";\nexport {\n resolveActiveLauncherRoute,\n useActiveLauncherRoute,\n} from \"./launcher/useActiveLauncherRoute\";\nexport { useCompactRoutedMode } from \"./launcher/useCompactRoutedMode\";\nexport {\n type MiniAppRouteSetOptions,\n useMiniAppRouteState,\n} from \"./launcher/useMiniAppRouteState\";\nexport { useNavigationMode } from \"./launcher/useNavigationMode\";\nexport { useNavigationModeDocumentAttribute } from \"./launcher/useNavigationModeDocumentAttribute\";\nexport {\n useRoutedLayoutActive,\n useWindowedLayoutActive,\n} from \"./launcher/useRoutedLayoutActive\";\nexport {\n type RoutedLayoutTier,\n useRoutedLayoutTier,\n} from \"./launcher/useRoutedLayoutTier\";\nexport { Menu, type MenuPosition } from \"./menu/Menu\";\nexport { MenuItem, type MenuItemProps } from \"./menu/MenuItem\";\nexport {\n StartMenu,\n type StartMenuItem,\n type StartMenuProps,\n} from \"./menu/StartMenu\";\nexport {\n type ContextMenuState,\n useContextMenuPositionState,\n useContextMenuState,\n} from \"./menu/useContextMenuState\";\nexport { RoutedPane, type RoutedPaneProps } from \"./routed/RoutedPane\";\nexport {\n RoutedPaneOverlayHostProvider,\n type RoutedPaneOverlayHostValue,\n useRoutedPaneOverlayHost,\n} from \"./routed/RoutedPaneOverlayHost\";\nexport type { SubscribeKeyboardVisibility } from \"./routed/useMobileKeyboardVisible\";\nexport { SidebarResizeHandle, useSidebarResize } from \"./sidebar/SidebarResize\";\nexport {\n CurrentWindowProvider,\n useCurrentWindow,\n useSuppressWindowToolbar,\n useWindowBackground,\n useWindowContentSize,\n} from \"./window/CurrentWindowContext\";\nexport { Window, type WindowContentBoundary } from \"./window/Window\";\nexport { WindowTitleBarActionButtons } from \"./window/WindowChromeActions\";\nexport { WindowCloseButton } from \"./window/WindowCloseButton\";\nexport {\n useWindowBackAction,\n useWindowBackActionValue,\n useWindowFileMenuItem,\n useWindowRefreshMenuItem,\n useWindowRefreshMenuItemValue,\n useWindowTitleBarAction,\n useWindowTitleBarActions,\n useWindowToolbarReservation,\n useWindowViewMenuItem,\n WindowMenuProvider,\n} from \"./window/WindowMenuContext\";\nexport {\n hasWindowSidebar,\n useRegisteredWindowSidebar,\n useWindowSidebar,\n WindowSidebarProvider,\n} from \"./window/WindowSidebarContext\";\nexport {\n findTopWindow,\n useWindowActions,\n useWindowStateData,\n type WindowCreateOptions,\n type WindowEntry,\n type WindowGeometry,\n type WindowPosition,\n type WindowSize,\n type WindowStateActions,\n type WindowStateData,\n WindowStateProvider,\n} from \"./window/WindowStateProvider\";\nexport { WindowToolBar } from \"./window/WindowToolBar\";\n"]}
@@ -0,0 +1,71 @@
1
+ import { type PropsWithChildren } from "react";
2
+ import type { LauncherDefinition } from "./launcherDefinition.js";
3
+ import { type NavigationHistoryAvailability } from "./navigationHistory.js";
4
+ import type { NavigationMode } from "./navigationMode.js";
5
+ 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
+ export interface LauncherNavigationActions<AppId extends string = string> {
24
+ getMiniAppHref: (appId: AppId, pathSegments?: ReadonlyArray<string> | undefined) => string;
25
+ goBack: () => void;
26
+ goForward: () => void;
27
+ navigateMiniAppRoute: (input: {
28
+ appId: AppId;
29
+ pathSegments?: ReadonlyArray<string> | undefined;
30
+ replace?: boolean | undefined;
31
+ }) => void;
32
+ navigateHome: (input?: {
33
+ replace?: boolean | undefined;
34
+ }) => void;
35
+ openMiniApp: (request: OpenMiniAppRequest<AppId>) => string | null;
36
+ }
37
+ export interface LauncherNavigationState<AppId extends string = string> {
38
+ definition: LauncherDefinition<AppId>;
39
+ history: NavigationHistoryAvailability;
40
+ mode: NavigationMode;
41
+ route: LauncherRoute<AppId>;
42
+ }
43
+ interface LauncherNavigationProviderProps extends PropsWithChildren {
44
+ definition: LauncherDefinition;
45
+ mode: NavigationMode;
46
+ }
47
+ /**
48
+ * Navigation for a launcher's mini-apps, in either mode. In `windowed` mode,
49
+ * opening an app opens or raises its window (inside a
50
+ * {@link WindowStateProvider}); in `routed` mode it navigates the browser to
51
+ * the app's route, `/app/<app id>/…`, which the routed shell shows.
52
+ */
53
+ export declare function LauncherNavigationProvider({ children, definition, mode, }: LauncherNavigationProviderProps): import("react").JSX.Element;
54
+ export declare const useLauncherNavigationActions: () => LauncherNavigationActions<string>;
55
+ export declare const useLauncherNavigationState: () => LauncherNavigationState<string>;
56
+ export declare const useOptionalLauncherNavigationState: () => LauncherNavigationState<string> | null;
57
+ /**
58
+ * The route of `appId` where it is hosted: the browser route in the routed
59
+ * shell, or its window's own route and Back stack in a window. Mini-apps read
60
+ * this rather than branching on navigation mode.
61
+ */
62
+ export declare function useMiniAppRouteSegments(appId: string): {
63
+ canGoBack: boolean;
64
+ goBack: () => void;
65
+ isRouted: boolean;
66
+ pathSegments: readonly string[];
67
+ setPathSegments: (nextPathSegments: ReadonlyArray<string>, options?: {
68
+ replace?: boolean | undefined;
69
+ }) => void;
70
+ };
71
+ export {};
@@ -0,0 +1,253 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
3
+ import { createRequiredContext } from "../createRequiredContext.js";
4
+ import { findTopWindow, useWindowActions, useWindowStateData, } from "../window/WindowStateProvider/index.js";
5
+ import { useMiniAppWindowRouteSegments } from "./MiniAppRouteSegmentsContext.js";
6
+ import { DEFAULT_NAVIGATION_HISTORY_CURSOR, getNavigationHistoryAvailability, readNavigationHistoryCursor, } from "./navigationHistory.js";
7
+ import { replaceWindowHistoryCursor, useRoutedPathNavigator, } from "./routedPathNavigator.js";
8
+ import { buildMiniAppPath, LAUNCHER_HOME_PATH, parseLauncherRoute, } from "./routePaths.js";
9
+ /** Where a new window opens when a request names no position. */
10
+ export const DEFAULT_MINI_APP_POSITION = { x: 200, y: 160 };
11
+ const launcherNavigationActionsContext = createRequiredContext("useLauncherNavigationActions requires LauncherNavigationProvider.");
12
+ const launcherNavigationStateContext = createRequiredContext("useLauncherNavigationState requires LauncherNavigationProvider.");
13
+ const EMPTY_ROUTE_SEGMENTS = [];
14
+ function readCurrentRoute(definition) {
15
+ return parseLauncherRoute(window.location.pathname, definition);
16
+ }
17
+ function readWindowHistoryCursor() {
18
+ return (readNavigationHistoryCursor(window.history.state) ??
19
+ DEFAULT_NAVIGATION_HISTORY_CURSOR);
20
+ }
21
+ function ensureWindowHistoryCursor() {
22
+ const cursor = readWindowHistoryCursor();
23
+ if (readNavigationHistoryCursor(window.history.state) === null) {
24
+ replaceWindowHistoryCursor(cursor);
25
+ }
26
+ return cursor;
27
+ }
28
+ function LauncherNavigationWindowRuntimeBridge({ definition, mode, runtimeRef, }) {
29
+ const { bringToFront, create, restore, updateRoute } = useWindowActions();
30
+ const { windows } = useWindowStateData();
31
+ useEffect(() => {
32
+ runtimeRef.current = {
33
+ actions: { bringToFront, create, restore, updateRoute },
34
+ definition,
35
+ mode,
36
+ windows,
37
+ };
38
+ }, [
39
+ bringToFront,
40
+ create,
41
+ definition,
42
+ mode,
43
+ restore,
44
+ runtimeRef,
45
+ updateRoute,
46
+ windows,
47
+ ]);
48
+ return null;
49
+ }
50
+ function useLauncherRouteController({ definition, mode, runtimeRef, }) {
51
+ const [route, setRoute] = useState(() => readCurrentRoute(definition));
52
+ const [historyCursor, setHistoryCursorState] = useState(readWindowHistoryCursor);
53
+ const historyCursorRef = useRef(historyCursor);
54
+ const setHistoryCursor = useCallback((cursor) => {
55
+ historyCursorRef.current = cursor;
56
+ setHistoryCursorState(cursor);
57
+ }, []);
58
+ const navigateRoutedPath = useRoutedPathNavigator({
59
+ historyCursorRef,
60
+ runtimeRef,
61
+ setHistoryCursor,
62
+ setRoute,
63
+ });
64
+ useEffect(() => {
65
+ if (mode !== "routed") {
66
+ return;
67
+ }
68
+ const handlePopState = (event) => {
69
+ setHistoryCursor(readNavigationHistoryCursor(event.state) ??
70
+ DEFAULT_NAVIGATION_HISTORY_CURSOR);
71
+ setRoute(readCurrentRoute(runtimeRef.current.definition));
72
+ };
73
+ setHistoryCursor(ensureWindowHistoryCursor());
74
+ setRoute(readCurrentRoute(runtimeRef.current.definition));
75
+ window.addEventListener("popstate", handlePopState);
76
+ return () => window.removeEventListener("popstate", handlePopState);
77
+ }, [mode, runtimeRef, setHistoryCursor]);
78
+ const navigateMiniAppRoute = useCallback(({ appId, pathSegments = [], replace = false, }) => {
79
+ navigateRoutedPath({
80
+ path: buildMiniAppPath(appId, pathSegments),
81
+ replace,
82
+ route: { appId, pathSegments: [...pathSegments] },
83
+ });
84
+ }, [navigateRoutedPath]);
85
+ const navigateHome = useCallback(({ replace = false } = {}) => {
86
+ navigateRoutedPath({
87
+ path: LAUNCHER_HOME_PATH,
88
+ replace,
89
+ route: { appId: null, pathSegments: [] },
90
+ });
91
+ }, [navigateRoutedPath]);
92
+ const goBack = useCallback(() => {
93
+ if (historyCursorRef.current.index > 0) {
94
+ setHistoryCursor({
95
+ ...historyCursorRef.current,
96
+ index: historyCursorRef.current.index - 1,
97
+ });
98
+ window.history.back();
99
+ }
100
+ }, [setHistoryCursor]);
101
+ const goForward = useCallback(() => {
102
+ const { entries, index } = historyCursorRef.current;
103
+ if (index < entries - 1) {
104
+ setHistoryCursor({
105
+ ...historyCursorRef.current,
106
+ index: index + 1,
107
+ });
108
+ window.history.forward();
109
+ }
110
+ }, [setHistoryCursor]);
111
+ const history = useMemo(() => getNavigationHistoryAvailability(historyCursor), [historyCursor]);
112
+ return {
113
+ goBack,
114
+ goForward,
115
+ history,
116
+ navigateHome,
117
+ navigateMiniAppRoute,
118
+ route,
119
+ };
120
+ }
121
+ function useLauncherNavigationActionValue(runtimeRef, goBack, goForward, navigateHome, navigateMiniAppRoute) {
122
+ const openMiniApp = useCallback(({ appId, pathSegments, position = DEFAULT_MINI_APP_POSITION, reuseExisting = true, }) => {
123
+ const { actions, definition, mode: currentMode, windows: currentWindows, } = runtimeRef.current;
124
+ if (currentMode === "routed") {
125
+ navigateMiniAppRoute({ appId, pathSegments });
126
+ return null;
127
+ }
128
+ const existingWindow = reuseExisting
129
+ ? findTopWindow(currentWindows, (windowEntry) => {
130
+ return windowEntry.appId === appId;
131
+ })
132
+ : null;
133
+ if (existingWindow) {
134
+ actions.restore(existingWindow.id);
135
+ actions.bringToFront(existingWindow.id);
136
+ if (pathSegments) {
137
+ actions.updateRoute(existingWindow.id, pathSegments);
138
+ }
139
+ return existingWindow.id;
140
+ }
141
+ const app = definition.apps[appId];
142
+ if (!app) {
143
+ throw new Error(`Unknown mini-app: ${appId}`);
144
+ }
145
+ return actions.create(app.title, position.x, position.y, app.createComponent(), {
146
+ appId,
147
+ initialShowSidebar: app.initialShowSidebar,
148
+ ...(pathSegments ? { pathSegments } : {}),
149
+ });
150
+ }, [navigateMiniAppRoute, runtimeRef]);
151
+ const getMiniAppHref = useCallback(buildMiniAppPath, []);
152
+ return useMemo(() => ({
153
+ getMiniAppHref,
154
+ goBack,
155
+ goForward,
156
+ navigateHome,
157
+ navigateMiniAppRoute,
158
+ openMiniApp,
159
+ }), [
160
+ getMiniAppHref,
161
+ goBack,
162
+ goForward,
163
+ navigateHome,
164
+ navigateMiniAppRoute,
165
+ openMiniApp,
166
+ ]);
167
+ }
168
+ /**
169
+ * Navigation for a launcher's mini-apps, in either mode. In `windowed` mode,
170
+ * opening an app opens or raises its window (inside a
171
+ * {@link WindowStateProvider}); in `routed` mode it navigates the browser to
172
+ * the app's route, `/app/<app id>/…`, which the routed shell shows.
173
+ */
174
+ export function LauncherNavigationProvider({ children, definition, mode, }) {
175
+ const runtimeRef = useRef({
176
+ actions: {
177
+ bringToFront: () => { },
178
+ create: () => "",
179
+ restore: () => { },
180
+ updateRoute: () => { },
181
+ },
182
+ definition,
183
+ mode,
184
+ windows: [],
185
+ });
186
+ const { goBack, goForward, history, navigateHome, navigateMiniAppRoute, route, } = useLauncherRouteController({
187
+ definition,
188
+ mode,
189
+ runtimeRef,
190
+ });
191
+ const actions = useLauncherNavigationActionValue(runtimeRef, goBack, goForward, navigateHome, navigateMiniAppRoute);
192
+ const state = useMemo(() => ({ definition, history, mode, route }), [definition, history, mode, route]);
193
+ return (_jsx(launcherNavigationActionsContext.context.Provider, { value: actions, children: _jsxs(launcherNavigationStateContext.context.Provider, { value: state, children: [_jsx(LauncherNavigationWindowRuntimeBridge, { definition: definition, mode: mode, runtimeRef: runtimeRef }), children] }) }));
194
+ }
195
+ // The context names apps by their string ids. The actions accept a host's own
196
+ // narrower id type as they are; a host narrows the route's id with
197
+ // isLauncherAppId (or its own guard) to read it back as that type.
198
+ export const useLauncherNavigationActions = launcherNavigationActionsContext.useRequired;
199
+ export const useLauncherNavigationState = launcherNavigationStateContext.useRequired;
200
+ export const useOptionalLauncherNavigationState = launcherNavigationStateContext.useOptional;
201
+ /**
202
+ * The route of `appId` where it is hosted: the browser route in the routed
203
+ * shell, or its window's own route and Back stack in a window. Mini-apps read
204
+ * this rather than branching on navigation mode.
205
+ */
206
+ export function useMiniAppRouteSegments(appId) {
207
+ const actions = launcherNavigationActionsContext.useOptional();
208
+ const state = launcherNavigationStateContext.useOptional();
209
+ const windowRoute = useMiniAppWindowRouteSegments(appId);
210
+ const isGlobalRouted = actions !== null && state?.mode === "routed";
211
+ const isRouted = isGlobalRouted || windowRoute !== null;
212
+ const pathSegments = isGlobalRouted && state.route.appId === appId
213
+ ? state.route.pathSegments
214
+ : (windowRoute?.pathSegments ?? EMPTY_ROUTE_SEGMENTS);
215
+ const windowSetPathSegments = windowRoute?.setPathSegments;
216
+ const setPathSegments = useCallback((nextPathSegments, options = {}) => {
217
+ if (isGlobalRouted) {
218
+ actions?.navigateMiniAppRoute({
219
+ appId,
220
+ pathSegments: nextPathSegments,
221
+ ...(options.replace === undefined
222
+ ? {}
223
+ : { replace: options.replace }),
224
+ });
225
+ return;
226
+ }
227
+ windowSetPathSegments?.(nextPathSegments, options);
228
+ }, [actions, appId, isGlobalRouted, windowSetPathSegments]);
229
+ // "Can this mini-app step back where it is hosted?" — browser history in the
230
+ // routed shell, the window's own Back stack in a window. Mini-apps read this
231
+ // rather than branching on navigation mode, so a detail surface that must
232
+ // yield to a real Back affordance asks one question and gets the right answer
233
+ // in both shells.
234
+ const windowGoBack = windowRoute?.goBack;
235
+ const canGoBack = isGlobalRouted
236
+ ? state.history.canGoBack
237
+ : (windowRoute?.canGoBack ?? false);
238
+ const goBack = useCallback(() => {
239
+ if (isGlobalRouted) {
240
+ actions?.goBack();
241
+ return;
242
+ }
243
+ windowGoBack?.();
244
+ }, [actions, isGlobalRouted, windowGoBack]);
245
+ return useMemo(() => ({
246
+ canGoBack,
247
+ goBack,
248
+ isRouted,
249
+ pathSegments,
250
+ setPathSegments,
251
+ }), [canGoBack, goBack, isRouted, pathSegments, setPathSegments]);
252
+ }
253
+ //# sourceMappingURL=LauncherNavigationProvider.js.map
@@ -0,0 +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;AAEtB,iEAAiE;AACjE,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;AAoD5D,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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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\";\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 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 definition,\n mode,\n runtimeRef,\n}: {\n definition: LauncherDefinition;\n mode: NavigationMode;\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 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 },\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 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 definition={definition}\n mode={mode}\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"]}
@@ -0,0 +1,19 @@
1
+ import { type PropsWithChildren } from "react";
2
+ interface MiniAppRouteSegmentsContextValue {
3
+ appId: string;
4
+ canGoBack: boolean;
5
+ goBack: () => void;
6
+ pathSegments: ReadonlyArray<string>;
7
+ setPathSegments: (pathSegments: ReadonlyArray<string>, options?: {
8
+ replace?: boolean | undefined;
9
+ }) => void;
10
+ windowId: string;
11
+ }
12
+ type MiniAppRouteSegmentsProviderProps = PropsWithChildren<MiniAppRouteSegmentsContextValue>;
13
+ export declare function MiniAppRouteSegmentsProvider({ appId, canGoBack, children, goBack, pathSegments, setPathSegments, windowId, }: MiniAppRouteSegmentsProviderProps): import("react").JSX.Element;
14
+ /**
15
+ * The route of the window hosting `appId`, or `null` outside a window or in a
16
+ * window of another app.
17
+ */
18
+ export declare function useMiniAppWindowRouteSegments(appId: string): MiniAppRouteSegmentsContextValue | null;
19
+ export {};
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useMemo, } from "react";
3
+ const MiniAppRouteSegmentsContext = createContext(null);
4
+ export function MiniAppRouteSegmentsProvider({ appId, canGoBack, children, goBack, pathSegments, setPathSegments, windowId, }) {
5
+ const value = useMemo(() => ({
6
+ appId,
7
+ canGoBack,
8
+ goBack,
9
+ pathSegments,
10
+ setPathSegments,
11
+ windowId,
12
+ }), [appId, canGoBack, goBack, pathSegments, setPathSegments, windowId]);
13
+ return (_jsx(MiniAppRouteSegmentsContext.Provider, { value: value, children: children }));
14
+ }
15
+ /**
16
+ * The route of the window hosting `appId`, or `null` outside a window or in a
17
+ * window of another app.
18
+ */
19
+ export function useMiniAppWindowRouteSegments(appId) {
20
+ const context = useContext(MiniAppRouteSegmentsContext);
21
+ if (!context || context.appId !== appId) {
22
+ return null;
23
+ }
24
+ return context;
25
+ }
26
+ //# sourceMappingURL=MiniAppRouteSegmentsContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MiniAppRouteSegmentsContext.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/MiniAppRouteSegmentsContext.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAEb,UAAU,EACV,OAAO,GACR,MAAM,OAAO,CAAC;AAmBf,MAAM,2BAA2B,GAC/B,aAAa,CAA0C,IAAI,CAAC,CAAC;AAE/D,MAAM,UAAU,4BAA4B,CAAC,EAC3C,KAAK,EACL,SAAS,EACT,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,eAAe,EACf,QAAQ,GAC0B;IAClC,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC;QACL,KAAK;QACL,SAAS;QACT,MAAM;QACN,YAAY;QACZ,eAAe;QACf,QAAQ;KACT,CAAC,EACF,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,CAAC,CACpE,CAAC;IAEF,OAAO,CACL,KAAC,2BAA2B,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAC/C,QAAQ,GAC4B,CACxC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAAC,KAAa;IACzD,MAAM,OAAO,GAAG,UAAU,CAAC,2BAA2B,CAAC,CAAC;IACxD,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import {\n createContext,\n type PropsWithChildren,\n useContext,\n useMemo,\n} from \"react\";\n\ninterface MiniAppRouteSegmentsContextValue {\n appId: string;\n canGoBack: boolean;\n goBack: () => void;\n pathSegments: ReadonlyArray<string>;\n setPathSegments: (\n pathSegments: ReadonlyArray<string>,\n options?: { replace?: boolean | undefined },\n ) => void;\n // The window hosting this mini-app, so window-addressed bus messages reach\n // the window they were opened into.\n windowId: string;\n}\n\ntype MiniAppRouteSegmentsProviderProps =\n PropsWithChildren<MiniAppRouteSegmentsContextValue>;\n\nconst MiniAppRouteSegmentsContext =\n createContext<MiniAppRouteSegmentsContextValue | null>(null);\n\nexport function MiniAppRouteSegmentsProvider({\n appId,\n canGoBack,\n children,\n goBack,\n pathSegments,\n setPathSegments,\n windowId,\n}: MiniAppRouteSegmentsProviderProps) {\n const value = useMemo<MiniAppRouteSegmentsContextValue>(\n () => ({\n appId,\n canGoBack,\n goBack,\n pathSegments,\n setPathSegments,\n windowId,\n }),\n [appId, canGoBack, goBack, pathSegments, setPathSegments, windowId],\n );\n\n return (\n <MiniAppRouteSegmentsContext.Provider value={value}>\n {children}\n </MiniAppRouteSegmentsContext.Provider>\n );\n}\n\n/**\n * The route of the window hosting `appId`, or `null` outside a window or in a\n * window of another app.\n */\nexport function useMiniAppWindowRouteSegments(appId: string) {\n const context = useContext(MiniAppRouteSegmentsContext);\n if (!context || context.appId !== appId) {\n return null;\n }\n\n return context;\n}\n"]}