@tearleads/windowing 0.2.41 → 0.2.42

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 CHANGED
@@ -89,6 +89,15 @@ workspaces). Hiding and showing an already initialized desktop preserves it,
89
89
  even if empty. Omit the list to manage startup yourself; `homeAppId` only sets
90
90
  the routed home.
91
91
 
92
+ Entering windowed mode also opens the app the browser's URL names
93
+ (`/app/<app id>/…`), in front of the default windows, so a link to an app, or
94
+ a switch from the routed shell, shows that app in either mode. An app that is
95
+ already open is raised, and routed to the URL's path if it has one. While
96
+ windowed, a browser history step to another app's URL opens that app too.
97
+ Windowed mode never changes the URL. Where several launchers share a page,
98
+ pass `routeWindowEnabled` to one: a launcher with it false at the entry skips
99
+ that URL, and does not open it when enabled later.
100
+
92
101
  A new window opens at the request's `position`, or `DEFAULT_MINI_APP_POSITION`,
93
102
  at the app's `windowSize`. A host that places its apps itself passes the
94
103
  provider a `placeWindow` callback. It receives each request that opens a new
@@ -34,14 +34,20 @@ interface LauncherNavigationProviderProps extends PropsWithChildren {
34
34
  * positions or sizes. Read when a window opens.
35
35
  */
36
36
  placeWindow?: PlaceMiniAppWindow | undefined;
37
+ /**
38
+ * Whether windowed mode opens the app the browser's URL names. Defaults to
39
+ * true; a host with several launchers on one page enables it for one.
40
+ */
41
+ routeWindowEnabled?: boolean | undefined;
37
42
  }
38
43
  /**
39
44
  * Navigation for a launcher's mini-apps, in either mode. In `windowed` mode,
40
45
  * opening an app opens or raises its window (inside a
41
- * {@link WindowStateProvider}); in `routed` mode it navigates the browser to
42
- * the app's route, `/app/<app id>/…`, which the routed shell shows.
46
+ * {@link WindowStateProvider}), and entering the mode opens the app the
47
+ * browser's URL names; in `routed` mode it navigates the browser to the app's
48
+ * route, `/app/<app id>/…`, which the routed shell shows.
43
49
  */
44
- export declare function LauncherNavigationProvider({ children, defaultWindowEnabled, definition, mode, placeWindow, }: LauncherNavigationProviderProps): import("react").JSX.Element;
50
+ export declare function LauncherNavigationProvider({ children, defaultWindowEnabled, definition, mode, placeWindow, routeWindowEnabled, }: LauncherNavigationProviderProps): import("react").JSX.Element;
45
51
  export declare const useLauncherNavigationActions: () => LauncherNavigationActions<string>;
46
52
  export declare const useLauncherNavigationState: () => LauncherNavigationState<string>;
47
53
  export declare const useOptionalLauncherNavigationState: () => LauncherNavigationState<string> | null;
@@ -7,7 +7,7 @@ import { DEFAULT_NAVIGATION_HISTORY_CURSOR, getNavigationHistoryAvailability, re
7
7
  import { openMiniAppWindow, } from "./openMiniAppWindow.js";
8
8
  import { replaceWindowHistoryCursor, useRoutedPathNavigator, } from "./routedPathNavigator.js";
9
9
  import { buildMiniAppPath, LAUNCHER_HOME_PATH, parseLauncherRoute, } from "./routePaths.js";
10
- import { useDefaultWindow } from "./useDefaultWindow.js";
10
+ import { useWindowedEntryWindows } from "./useWindowedEntryWindows.js";
11
11
  const launcherNavigationActionsContext = createRequiredContext("useLauncherNavigationActions requires LauncherNavigationProvider.");
12
12
  const launcherNavigationStateContext = createRequiredContext("useLauncherNavigationState requires LauncherNavigationProvider.");
13
13
  const EMPTY_ROUTE_SEGMENTS = [];
@@ -25,7 +25,7 @@ function ensureWindowHistoryCursor() {
25
25
  }
26
26
  return cursor;
27
27
  }
28
- function LauncherNavigationWindowRuntimeBridge({ defaultWindowEnabled, definition, mode, openMiniApp, placeWindow, runtimeRef, }) {
28
+ function LauncherNavigationWindowRuntimeBridge({ defaultWindowEnabled, definition, mode, openMiniApp, placeWindow, routeWindowEnabled, runtimeRef, }) {
29
29
  const { bringToFront, create, restore, updateRoute } = useWindowActions();
30
30
  const { windows } = useWindowStateData();
31
31
  useEffect(() => {
@@ -47,11 +47,12 @@ function LauncherNavigationWindowRuntimeBridge({ defaultWindowEnabled, definitio
47
47
  updateRoute,
48
48
  windows,
49
49
  ]);
50
- useDefaultWindow({
50
+ useWindowedEntryWindows({
51
+ defaultWindowEnabled,
51
52
  definition,
52
- enabled: defaultWindowEnabled,
53
53
  mode,
54
54
  openMiniApp,
55
+ routeWindowEnabled,
55
56
  windowCount: windows.length,
56
57
  });
57
58
  return null;
@@ -163,10 +164,11 @@ function useLauncherNavigationActionValue(runtimeRef, goBack, goForward, navigat
163
164
  /**
164
165
  * Navigation for a launcher's mini-apps, in either mode. In `windowed` mode,
165
166
  * opening an app opens or raises its window (inside a
166
- * {@link WindowStateProvider}); in `routed` mode it navigates the browser to
167
- * the app's route, `/app/<app id>/…`, which the routed shell shows.
167
+ * {@link WindowStateProvider}), and entering the mode opens the app the
168
+ * browser's URL names; in `routed` mode it navigates the browser to the app's
169
+ * route, `/app/<app id>/…`, which the routed shell shows.
168
170
  */
169
- export function LauncherNavigationProvider({ children, defaultWindowEnabled = true, definition, mode, placeWindow, }) {
171
+ export function LauncherNavigationProvider({ children, defaultWindowEnabled = true, definition, mode, placeWindow, routeWindowEnabled = true, }) {
170
172
  const runtimeRef = useRef({
171
173
  actions: {
172
174
  bringToFront: () => { },
@@ -186,7 +188,7 @@ export function LauncherNavigationProvider({ children, defaultWindowEnabled = tr
186
188
  });
187
189
  const actions = useLauncherNavigationActionValue(runtimeRef, goBack, goForward, navigateHome, navigateMiniAppRoute);
188
190
  const state = useMemo(() => ({ definition, history, mode, route }), [definition, history, mode, route]);
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] }) }));
191
+ 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, routeWindowEnabled: routeWindowEnabled, runtimeRef: runtimeRef }), children] }) }));
190
192
  }
191
193
  // The context names apps by their string ids. The actions accept a host's own
192
194
  // 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,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,CA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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 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"]}
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;A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ACR,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 { useWindowedEntryWindows } from \"./useWindowedEntryWindows\";\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 * Whether windowed mode opens the app the browser's URL names. Defaults to\n * true; a host with several launchers on one page enables it for one.\n */\n routeWindowEnabled?: boolean | 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 routeWindowEnabled,\n runtimeRef,\n}: {\n defaultWindowEnabled: boolean;\n definition: LauncherDefinition;\n mode: NavigationMode;\n openMiniApp: LauncherNavigationActions[\"openMiniApp\"];\n placeWindow: PlaceMiniAppWindow | undefined;\n routeWindowEnabled: boolean;\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 useWindowedEntryWindows({\n defaultWindowEnabled,\n definition,\n mode,\n openMiniApp,\n routeWindowEnabled,\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}), and entering the mode opens the app the\n * browser's URL names; in `routed` mode it navigates the browser to the app's\n * 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 routeWindowEnabled = true,\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 routeWindowEnabled={routeWindowEnabled}\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,17 @@
1
+ import { type LauncherDefinition } from "./launcherDefinition.js";
2
+ import type { NavigationMode } from "./navigationMode.js";
3
+ import type { OpenMiniAppRequest } from "./openMiniAppWindow.js";
4
+ /**
5
+ * Opens the windows a windowed desktop starts with, once per entry into
6
+ * windowed mode: the host's default windows, in order, if the desktop is
7
+ * empty, and then the app the browser's URL names, in front. While windowed,
8
+ * a browser history step to another app's URL opens that app too.
9
+ */
10
+ export declare function useWindowedEntryWindows({ defaultWindowEnabled, definition, mode, openMiniApp, routeWindowEnabled, windowCount, }: {
11
+ defaultWindowEnabled: boolean;
12
+ definition: LauncherDefinition;
13
+ mode: NavigationMode;
14
+ openMiniApp: (request: OpenMiniAppRequest) => string | null;
15
+ routeWindowEnabled: boolean;
16
+ windowCount: number;
17
+ }): void;
@@ -0,0 +1,76 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { isLauncherAppId } from "./launcherDefinition.js";
3
+ import { parseLauncherRoute } from "./routePaths.js";
4
+ /** The request that opens the app the browser's URL names, if it names one. */
5
+ function readRouteWindowRequest(definition) {
6
+ const { appId, pathSegments } = parseLauncherRoute(window.location.pathname, definition);
7
+ if (appId === null)
8
+ return null;
9
+ // An app's root route names no place within it, so the app's open window
10
+ // is raised where it is.
11
+ return pathSegments.length > 0 ? { appId, pathSegments } : { appId };
12
+ }
13
+ /**
14
+ * The requests that open the host's default windows, each app once and
15
+ * without the URL's app, which opens after them: the launcher's open requests
16
+ * within one pass cannot see the windows the earlier ones created.
17
+ */
18
+ function readDefaultWindowRequests(definition, routeRequest) {
19
+ return [...new Set(definition.defaultWindowAppIds)]
20
+ .filter((appId) => appId !== routeRequest?.appId && isLauncherAppId(definition, appId))
21
+ .map((appId) => ({ appId }));
22
+ }
23
+ /**
24
+ * Opens the windows a windowed desktop starts with, once per entry into
25
+ * windowed mode: the host's default windows, in order, if the desktop is
26
+ * empty, and then the app the browser's URL names, in front. While windowed,
27
+ * a browser history step to another app's URL opens that app too.
28
+ */
29
+ export function useWindowedEntryWindows({ defaultWindowEnabled, definition, mode, openMiniApp, routeWindowEnabled, windowCount, }) {
30
+ const handledDefaultWindows = useRef(false);
31
+ const handledRouteWindow = useRef(false);
32
+ useEffect(() => {
33
+ if (mode !== "windowed") {
34
+ handledDefaultWindows.current = false;
35
+ handledRouteWindow.current = false;
36
+ return;
37
+ }
38
+ // The URL belongs to the entry, not to this launcher: one that is
39
+ // disabled at the entry skips it rather than opening it when enabled.
40
+ const routeRequest = routeWindowEnabled && !handledRouteWindow.current
41
+ ? readRouteWindowRequest(definition)
42
+ : null;
43
+ // Record the entry before opening, including across StrictMode effects.
44
+ handledRouteWindow.current = true;
45
+ const requests = [];
46
+ if (defaultWindowEnabled && !handledDefaultWindows.current) {
47
+ handledDefaultWindows.current = true;
48
+ if (windowCount === 0) {
49
+ requests.push(...readDefaultWindowRequests(definition, routeRequest));
50
+ }
51
+ }
52
+ if (routeRequest)
53
+ requests.push(routeRequest);
54
+ for (const request of requests)
55
+ openMiniApp(request);
56
+ }, [
57
+ defaultWindowEnabled,
58
+ definition,
59
+ mode,
60
+ openMiniApp,
61
+ routeWindowEnabled,
62
+ windowCount,
63
+ ]);
64
+ useEffect(() => {
65
+ if (mode !== "windowed" || !routeWindowEnabled)
66
+ return;
67
+ const openRouteWindow = () => {
68
+ const routeRequest = readRouteWindowRequest(definition);
69
+ if (routeRequest)
70
+ openMiniApp(routeRequest);
71
+ };
72
+ window.addEventListener("popstate", openRouteWindow);
73
+ return () => window.removeEventListener("popstate", openRouteWindow);
74
+ }, [definition, mode, openMiniApp, routeWindowEnabled]);
75
+ }
76
+ //# sourceMappingURL=useWindowedEntryWindows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWindowedEntryWindows.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/useWindowedEntryWindows.ts"],"names":[],"mappings":"AAA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,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;IACvE,CAAC,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { isLauncherAppId, type LauncherDefinition } from \"./launcherDefinition\";\nimport type { NavigationMode } from \"./navigationMode\";\nimport type { OpenMiniAppRequest } from \"./openMiniAppWindow\";\nimport { parseLauncherRoute } from \"./routePaths\";\n\n/** The request that opens the app the browser's URL names, if it names one. */\nfunction readRouteWindowRequest(\n definition: LauncherDefinition,\n): OpenMiniAppRequest | null {\n const { appId, pathSegments } = parseLauncherRoute(\n window.location.pathname,\n definition,\n );\n if (appId === null) return null;\n // An app's root route names no place within it, so the app's open window\n // is raised where it is.\n return pathSegments.length > 0 ? { appId, pathSegments } : { appId };\n}\n\n/**\n * The requests that open the host's default windows, each app once and\n * without the URL's app, which opens after them: the launcher's open requests\n * within one pass cannot see the windows the earlier ones created.\n */\nfunction readDefaultWindowRequests(\n definition: LauncherDefinition,\n routeRequest: OpenMiniAppRequest | null,\n): OpenMiniAppRequest[] {\n return [...new Set(definition.defaultWindowAppIds)]\n .filter(\n (appId) =>\n appId !== routeRequest?.appId && isLauncherAppId(definition, appId),\n )\n .map((appId) => ({ appId }));\n}\n\n/**\n * Opens the windows a windowed desktop starts with, once per entry into\n * windowed mode: the host's default windows, in order, if the desktop is\n * empty, and then the app the browser's URL names, in front. While windowed,\n * a browser history step to another app's URL opens that app too.\n */\nexport function useWindowedEntryWindows({\n defaultWindowEnabled,\n definition,\n mode,\n openMiniApp,\n routeWindowEnabled,\n windowCount,\n}: {\n defaultWindowEnabled: boolean;\n definition: LauncherDefinition;\n mode: NavigationMode;\n openMiniApp: (request: OpenMiniAppRequest) => string | null;\n routeWindowEnabled: boolean;\n windowCount: number;\n}) {\n const handledDefaultWindows = useRef(false);\n const handledRouteWindow = useRef(false);\n\n useEffect(() => {\n if (mode !== \"windowed\") {\n handledDefaultWindows.current = false;\n handledRouteWindow.current = false;\n return;\n }\n // The URL belongs to the entry, not to this launcher: one that is\n // disabled at the entry skips it rather than opening it when enabled.\n const routeRequest =\n routeWindowEnabled && !handledRouteWindow.current\n ? readRouteWindowRequest(definition)\n : null;\n // Record the entry before opening, including across StrictMode effects.\n handledRouteWindow.current = true;\n const requests: OpenMiniAppRequest[] = [];\n if (defaultWindowEnabled && !handledDefaultWindows.current) {\n handledDefaultWindows.current = true;\n if (windowCount === 0) {\n requests.push(...readDefaultWindowRequests(definition, routeRequest));\n }\n }\n if (routeRequest) requests.push(routeRequest);\n for (const request of requests) openMiniApp(request);\n }, [\n defaultWindowEnabled,\n definition,\n mode,\n openMiniApp,\n routeWindowEnabled,\n windowCount,\n ]);\n\n useEffect(() => {\n if (mode !== \"windowed\" || !routeWindowEnabled) return;\n const openRouteWindow = () => {\n const routeRequest = readRouteWindowRequest(definition);\n if (routeRequest) openMiniApp(routeRequest);\n };\n window.addEventListener(\"popstate\", openRouteWindow);\n return () => window.removeEventListener(\"popstate\", openRouteWindow);\n }, [definition, mode, openMiniApp, routeWindowEnabled]);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tearleads/windowing",
3
- "version": "0.2.41",
3
+ "version": "0.2.42",
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": {
@@ -1,15 +0,0 @@
1
- import { type LauncherDefinition } from "./launcherDefinition.js";
2
- import type { NavigationMode } from "./navigationMode.js";
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
- */
7
- export declare function useDefaultWindow({ definition, enabled, mode, openMiniApp, windowCount, }: {
8
- definition: LauncherDefinition;
9
- enabled: boolean;
10
- mode: NavigationMode;
11
- openMiniApp: (request: {
12
- appId: string;
13
- }) => string | null;
14
- windowCount: number;
15
- }): void;
@@ -1,28 +0,0 @@
1
- import { useEffect, useRef } from "react";
2
- import { isLauncherAppId } from "./launcherDefinition.js";
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
- */
7
- export function useDefaultWindow({ definition, enabled, mode, openMiniApp, windowCount, }) {
8
- const handledWindowedEntry = useRef(false);
9
- useEffect(() => {
10
- if (mode !== "windowed") {
11
- handledWindowedEntry.current = false;
12
- return;
13
- }
14
- if (!enabled || handledWindowedEntry.current)
15
- return;
16
- // Record the entry before opening, including across StrictMode effects.
17
- handledWindowedEntry.current = true;
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 });
25
- }
26
- }, [definition, enabled, mode, openMiniApp, windowCount]);
27
- }
28
- //# sourceMappingURL=useDefaultWindow.js.map
@@ -1 +0,0 @@
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"]}