@tearleads/windowing 0.2.15 → 0.2.17
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/README.md +8 -0
- package/launcher/LauncherNavigationProvider.d.ts +3 -1
- package/launcher/LauncherNavigationProvider.js +11 -3
- package/launcher/LauncherNavigationProvider.js.map +1 -1
- package/launcher/launcherDefinition.d.ts +6 -0
- package/launcher/launcherDefinition.js.map +1 -1
- package/launcher/useDefaultWindow.d.ts +12 -0
- package/launcher/useDefaultWindow.js +21 -0
- package/launcher/useDefaultWindow.js.map +1 -0
- package/package.json +1 -1
- package/routed/RoutedPane.css +8 -6
package/README.md
CHANGED
|
@@ -211,6 +211,7 @@ const LAUNCHER: LauncherDefinition<"notes" | "contacts"> = {
|
|
|
211
211
|
title: "Notes",
|
|
212
212
|
},
|
|
213
213
|
},
|
|
214
|
+
defaultWindowAppId: "notes",
|
|
214
215
|
homeAppId: "notes",
|
|
215
216
|
order: ["notes", "contacts"],
|
|
216
217
|
};
|
|
@@ -224,6 +225,13 @@ or raises the one already open; in `routed` mode it pushes the app's route,
|
|
|
224
225
|
each window with `MiniAppWindow`, whose `AppBoundary` slot wraps the app (for
|
|
225
226
|
example in an error boundary).
|
|
226
227
|
|
|
228
|
+
Optional `defaultWindowAppId` opens on entering an empty windowed desktop,
|
|
229
|
+
including mount. Minimized windows count as open. Closing the last window
|
|
230
|
+
leaves it empty until the next mode entry. The provider's `defaultWindowEnabled`
|
|
231
|
+
defers that entry while false (e.g. hidden workspaces). Hiding and showing an
|
|
232
|
+
already initialized desktop preserves it, even if empty. Omit the app id to
|
|
233
|
+
manage startup yourself; `homeAppId` only sets the routed home.
|
|
234
|
+
|
|
227
235
|
A mini-app reads and sets its own route with `useMiniAppRouteSegments(appId)`,
|
|
228
236
|
or `useMiniAppRouteState` for a parsed route: the browser route in the routed
|
|
229
237
|
shell, its window's own route and Back stack in a window. It registers its
|
|
@@ -41,6 +41,8 @@ export interface LauncherNavigationState<AppId extends string = string> {
|
|
|
41
41
|
route: LauncherRoute<AppId>;
|
|
42
42
|
}
|
|
43
43
|
interface LauncherNavigationProviderProps extends PropsWithChildren {
|
|
44
|
+
/** Defers the default window while false, for example in a hidden workspace. */
|
|
45
|
+
defaultWindowEnabled?: boolean | undefined;
|
|
44
46
|
definition: LauncherDefinition;
|
|
45
47
|
mode: NavigationMode;
|
|
46
48
|
}
|
|
@@ -50,7 +52,7 @@ interface LauncherNavigationProviderProps extends PropsWithChildren {
|
|
|
50
52
|
* {@link WindowStateProvider}); in `routed` mode it navigates the browser to
|
|
51
53
|
* the app's route, `/app/<app id>/…`, which the routed shell shows.
|
|
52
54
|
*/
|
|
53
|
-
export declare function LauncherNavigationProvider({ children, definition, mode, }: LauncherNavigationProviderProps): import("react").JSX.Element;
|
|
55
|
+
export declare function LauncherNavigationProvider({ children, defaultWindowEnabled, definition, mode, }: LauncherNavigationProviderProps): import("react").JSX.Element;
|
|
54
56
|
export declare const useLauncherNavigationActions: () => LauncherNavigationActions<string>;
|
|
55
57
|
export declare const useLauncherNavigationState: () => LauncherNavigationState<string>;
|
|
56
58
|
export declare const useOptionalLauncherNavigationState: () => LauncherNavigationState<string> | null;
|
|
@@ -6,6 +6,7 @@ import { useMiniAppWindowRouteSegments } from "./MiniAppRouteSegmentsContext.js"
|
|
|
6
6
|
import { DEFAULT_NAVIGATION_HISTORY_CURSOR, getNavigationHistoryAvailability, readNavigationHistoryCursor, } from "./navigationHistory.js";
|
|
7
7
|
import { replaceWindowHistoryCursor, useRoutedPathNavigator, } from "./routedPathNavigator.js";
|
|
8
8
|
import { buildMiniAppPath, LAUNCHER_HOME_PATH, parseLauncherRoute, } from "./routePaths.js";
|
|
9
|
+
import { useDefaultWindow } from "./useDefaultWindow.js";
|
|
9
10
|
/** Where a new window opens when a request names no position. */
|
|
10
11
|
export const DEFAULT_MINI_APP_POSITION = { x: 200, y: 160 };
|
|
11
12
|
const launcherNavigationActionsContext = createRequiredContext("useLauncherNavigationActions requires LauncherNavigationProvider.");
|
|
@@ -25,7 +26,7 @@ function ensureWindowHistoryCursor() {
|
|
|
25
26
|
}
|
|
26
27
|
return cursor;
|
|
27
28
|
}
|
|
28
|
-
function LauncherNavigationWindowRuntimeBridge({ definition, mode, runtimeRef, }) {
|
|
29
|
+
function LauncherNavigationWindowRuntimeBridge({ defaultWindowEnabled, definition, mode, openMiniApp, runtimeRef, }) {
|
|
29
30
|
const { bringToFront, create, restore, updateRoute } = useWindowActions();
|
|
30
31
|
const { windows } = useWindowStateData();
|
|
31
32
|
useEffect(() => {
|
|
@@ -45,6 +46,13 @@ function LauncherNavigationWindowRuntimeBridge({ definition, mode, runtimeRef, }
|
|
|
45
46
|
updateRoute,
|
|
46
47
|
windows,
|
|
47
48
|
]);
|
|
49
|
+
useDefaultWindow({
|
|
50
|
+
definition,
|
|
51
|
+
enabled: defaultWindowEnabled,
|
|
52
|
+
mode,
|
|
53
|
+
openMiniApp,
|
|
54
|
+
windowCount: windows.length,
|
|
55
|
+
});
|
|
48
56
|
return null;
|
|
49
57
|
}
|
|
50
58
|
function useLauncherRouteController({ definition, mode, runtimeRef, }) {
|
|
@@ -171,7 +179,7 @@ function useLauncherNavigationActionValue(runtimeRef, goBack, goForward, navigat
|
|
|
171
179
|
* {@link WindowStateProvider}); in `routed` mode it navigates the browser to
|
|
172
180
|
* the app's route, `/app/<app id>/…`, which the routed shell shows.
|
|
173
181
|
*/
|
|
174
|
-
export function LauncherNavigationProvider({ children, definition, mode, }) {
|
|
182
|
+
export function LauncherNavigationProvider({ children, defaultWindowEnabled = true, definition, mode, }) {
|
|
175
183
|
const runtimeRef = useRef({
|
|
176
184
|
actions: {
|
|
177
185
|
bringToFront: () => { },
|
|
@@ -190,7 +198,7 @@ export function LauncherNavigationProvider({ children, definition, mode, }) {
|
|
|
190
198
|
});
|
|
191
199
|
const actions = useLauncherNavigationActionValue(runtimeRef, goBack, goForward, navigateHome, navigateMiniAppRoute);
|
|
192
200
|
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] }) }));
|
|
201
|
+
return (_jsx(launcherNavigationActionsContext.context.Provider, { value: actions, children: _jsxs(launcherNavigationStateContext.context.Provider, { value: state, children: [_jsx(LauncherNavigationWindowRuntimeBridge, { defaultWindowEnabled: defaultWindowEnabled, definition: definition, mode: mode, openMiniApp: actions.openMiniApp, runtimeRef: runtimeRef }), children] }) }));
|
|
194
202
|
}
|
|
195
203
|
// The context names apps by their string ids. The actions accept a host's own
|
|
196
204
|
// narrower id type as they are; a host narrows the route's id with
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LauncherNavigationProvider.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/LauncherNavigationProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAGL,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,GAGnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,EACL,iCAAiC,EACjC,gCAAgC,EAGhC,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAElB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAEtB,iEAAiE;AACjE,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC,EAAE,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W,EAAE,MAAM,CAAC;IACzC,MAAM,SAAS,GAAG,cAAc;QAC9B,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS;QACzB,CAAC,CAAC,CAAC,WAAW,EAAE,SAAS,IAAI,KAAK,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE;QAC9B,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,EAAE,MAAM,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,YAAY,EAAE,EAAE,CAAC;IACnB,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC;IAE5C,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,SAAS;QACT,MAAM;QACN,QAAQ;QACR,YAAY;QACZ,eAAe;KAChB,CAAC,EACF,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,CAAC,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["import {\n type MutableRefObject,\n type PropsWithChildren,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createRequiredContext } from \"../createRequiredContext\";\nimport {\n findTopWindow,\n useWindowActions,\n useWindowStateData,\n type WindowStateActions,\n type WindowStateData,\n} from \"../window/WindowStateProvider\";\nimport type { LauncherDefinition } from \"./launcherDefinition\";\nimport { useMiniAppWindowRouteSegments } from \"./MiniAppRouteSegmentsContext\";\nimport {\n DEFAULT_NAVIGATION_HISTORY_CURSOR,\n getNavigationHistoryAvailability,\n type NavigationHistoryAvailability,\n type NavigationHistoryCursor,\n readNavigationHistoryCursor,\n} from \"./navigationHistory\";\nimport type { NavigationMode } from \"./navigationMode\";\nimport {\n replaceWindowHistoryCursor,\n useRoutedPathNavigator,\n} from \"./routedPathNavigator\";\nimport {\n buildMiniAppPath,\n LAUNCHER_HOME_PATH,\n type LauncherRoute,\n parseLauncherRoute,\n} from \"./routePaths\";\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"]}
|
|
1
|
+
{"version":3,"file":"LauncherNavigationProvider.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/LauncherNavigationProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAGL,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,GAGnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,EACL,iCAAiC,EACjC,gCAAgC,EAGhC,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAElB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,iEAAiE;AACjE,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;AAsD5D,MAAM,gCAAgC,GACpC,qBAAq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,EACD,CAAC,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,qBAAqB,CAAC,CACxD,CAAC;IACF,6EAA6E;IAC7E,6EAA6E;IAC7E,0EAA0E;IAC1E,8EAA8E;IAC9E,kBAAkB;IAClB,MAAM,YAAY,GAAG,WAAW,EAAE,MAAM,CAAC;IACzC,MAAM,SAAS,GAAG,cAAc;QAC9B,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS;QACzB,CAAC,CAAC,CAAC,WAAW,EAAE,SAAS,IAAI,KAAK,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE;QAC9B,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,EAAE,MAAM,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,YAAY,EAAE,EAAE,CAAC;IACnB,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC;IAE5C,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,SAAS;QACT,MAAM;QACN,QAAQ;QACR,YAAY;QACZ,eAAe;KAChB,CAAC,EACF,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,CAAC,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["import {\n type MutableRefObject,\n type PropsWithChildren,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createRequiredContext } from \"../createRequiredContext\";\nimport {\n findTopWindow,\n useWindowActions,\n useWindowStateData,\n type WindowStateActions,\n type WindowStateData,\n} from \"../window/WindowStateProvider\";\nimport type { LauncherDefinition } from \"./launcherDefinition\";\nimport { useMiniAppWindowRouteSegments } from \"./MiniAppRouteSegmentsContext\";\nimport {\n DEFAULT_NAVIGATION_HISTORY_CURSOR,\n getNavigationHistoryAvailability,\n type NavigationHistoryAvailability,\n type NavigationHistoryCursor,\n readNavigationHistoryCursor,\n} from \"./navigationHistory\";\nimport type { NavigationMode } from \"./navigationMode\";\nimport {\n replaceWindowHistoryCursor,\n useRoutedPathNavigator,\n} from \"./routedPathNavigator\";\nimport {\n buildMiniAppPath,\n LAUNCHER_HOME_PATH,\n type LauncherRoute,\n parseLauncherRoute,\n} from \"./routePaths\";\nimport { useDefaultWindow } from \"./useDefaultWindow\";\n\n/** Where a new window opens when a request names no position. */\nexport const DEFAULT_MINI_APP_POSITION = { x: 200, y: 160 };\n\n/** A request to show an app: in a window, or as the routed shell's page. */\nexport interface OpenMiniAppRequest<AppId extends string = string> {\n appId: AppId;\n pathSegments?: ReadonlyArray<string> | undefined;\n /** Where a new window opens. */\n position?: { x: number; y: number } | undefined;\n /** Raise the app's open window instead of opening another. Defaults to true. */\n reuseExisting?: boolean | undefined;\n}\n\nexport interface LauncherNavigationActions<AppId extends string = string> {\n getMiniAppHref: (\n appId: AppId,\n pathSegments?: ReadonlyArray<string> | undefined,\n ) => string;\n goBack: () => void;\n goForward: () => void;\n navigateMiniAppRoute: (input: {\n appId: AppId;\n pathSegments?: ReadonlyArray<string> | undefined;\n replace?: boolean | undefined;\n }) => void;\n navigateHome: (input?: { replace?: boolean | undefined }) => void;\n // Returns the window the app opened in or was raised to, or null when the\n // routed shell shows it instead.\n openMiniApp: (request: OpenMiniAppRequest<AppId>) => string | null;\n}\n\nexport interface LauncherNavigationState<AppId extends string = string> {\n definition: LauncherDefinition<AppId>;\n history: NavigationHistoryAvailability;\n mode: NavigationMode;\n route: LauncherRoute<AppId>;\n}\n\ninterface LauncherNavigationProviderProps extends PropsWithChildren {\n /** Defers the default window while false, for example in a hidden workspace. */\n defaultWindowEnabled?: boolean | undefined;\n definition: LauncherDefinition;\n mode: NavigationMode;\n}\n\ninterface LauncherNavigationRuntime {\n actions: Pick<\n WindowStateActions,\n \"bringToFront\" | \"create\" | \"restore\" | \"updateRoute\"\n >;\n definition: LauncherDefinition;\n mode: NavigationMode;\n windows: WindowStateData[\"windows\"];\n}\n\nconst launcherNavigationActionsContext =\n createRequiredContext<LauncherNavigationActions>(\n \"useLauncherNavigationActions requires LauncherNavigationProvider.\",\n );\nconst launcherNavigationStateContext =\n createRequiredContext<LauncherNavigationState>(\n \"useLauncherNavigationState requires LauncherNavigationProvider.\",\n );\nconst EMPTY_ROUTE_SEGMENTS: ReadonlyArray<string> = [];\n\nfunction readCurrentRoute(definition: LauncherDefinition): LauncherRoute {\n return parseLauncherRoute(window.location.pathname, definition);\n}\n\nfunction readWindowHistoryCursor(): NavigationHistoryCursor {\n return (\n readNavigationHistoryCursor(window.history.state) ??\n DEFAULT_NAVIGATION_HISTORY_CURSOR\n );\n}\n\nfunction ensureWindowHistoryCursor(): NavigationHistoryCursor {\n const cursor = readWindowHistoryCursor();\n if (readNavigationHistoryCursor(window.history.state) === null) {\n replaceWindowHistoryCursor(cursor);\n }\n\n return cursor;\n}\n\nfunction LauncherNavigationWindowRuntimeBridge({\n defaultWindowEnabled,\n definition,\n mode,\n openMiniApp,\n runtimeRef,\n}: {\n defaultWindowEnabled: boolean;\n definition: LauncherDefinition;\n mode: NavigationMode;\n openMiniApp: LauncherNavigationActions[\"openMiniApp\"];\n runtimeRef: MutableRefObject<LauncherNavigationRuntime>;\n}) {\n const { bringToFront, create, restore, updateRoute } = useWindowActions();\n const { windows } = useWindowStateData();\n\n useEffect(() => {\n runtimeRef.current = {\n actions: { bringToFront, create, restore, updateRoute },\n definition,\n mode,\n windows,\n };\n }, [\n bringToFront,\n create,\n definition,\n mode,\n restore,\n runtimeRef,\n updateRoute,\n windows,\n ]);\n\n useDefaultWindow({\n definition,\n enabled: defaultWindowEnabled,\n mode,\n openMiniApp,\n windowCount: windows.length,\n });\n\n return null;\n}\n\nfunction useLauncherRouteController({\n definition,\n mode,\n runtimeRef,\n}: {\n definition: LauncherDefinition;\n mode: NavigationMode;\n runtimeRef: MutableRefObject<LauncherNavigationRuntime>;\n}) {\n const [route, setRoute] = useState<LauncherRoute>(() =>\n readCurrentRoute(definition),\n );\n const [historyCursor, setHistoryCursorState] =\n useState<NavigationHistoryCursor>(readWindowHistoryCursor);\n const historyCursorRef = useRef(historyCursor);\n const setHistoryCursor = useCallback((cursor: NavigationHistoryCursor) => {\n historyCursorRef.current = cursor;\n setHistoryCursorState(cursor);\n }, []);\n const navigateRoutedPath = useRoutedPathNavigator({\n historyCursorRef,\n runtimeRef,\n setHistoryCursor,\n setRoute,\n });\n\n useEffect(() => {\n if (mode !== \"routed\") {\n return;\n }\n\n const handlePopState = (event: PopStateEvent) => {\n setHistoryCursor(\n readNavigationHistoryCursor(event.state) ??\n DEFAULT_NAVIGATION_HISTORY_CURSOR,\n );\n setRoute(readCurrentRoute(runtimeRef.current.definition));\n };\n\n setHistoryCursor(ensureWindowHistoryCursor());\n setRoute(readCurrentRoute(runtimeRef.current.definition));\n window.addEventListener(\"popstate\", handlePopState);\n return () => window.removeEventListener(\"popstate\", handlePopState);\n }, [mode, runtimeRef, setHistoryCursor]);\n\n const navigateMiniAppRoute = useCallback(\n ({\n appId,\n pathSegments = [],\n replace = false,\n }: {\n appId: string;\n pathSegments?: ReadonlyArray<string> | undefined;\n replace?: boolean | undefined;\n }) => {\n navigateRoutedPath({\n path: buildMiniAppPath(appId, pathSegments),\n replace,\n route: { appId, pathSegments: [...pathSegments] },\n });\n },\n [navigateRoutedPath],\n );\n const navigateHome = useCallback(\n ({ replace = false }: { replace?: boolean | undefined } = {}) => {\n navigateRoutedPath({\n path: LAUNCHER_HOME_PATH,\n replace,\n route: { appId: null, pathSegments: [] },\n });\n },\n [navigateRoutedPath],\n );\n\n const goBack = useCallback(() => {\n if (historyCursorRef.current.index > 0) {\n setHistoryCursor({\n ...historyCursorRef.current,\n index: historyCursorRef.current.index - 1,\n });\n window.history.back();\n }\n }, [setHistoryCursor]);\n const goForward = useCallback(() => {\n const { entries, index } = historyCursorRef.current;\n if (index < entries - 1) {\n setHistoryCursor({\n ...historyCursorRef.current,\n index: index + 1,\n });\n window.history.forward();\n }\n }, [setHistoryCursor]);\n const history = useMemo(\n () => getNavigationHistoryAvailability(historyCursor),\n [historyCursor],\n );\n\n return {\n goBack,\n goForward,\n history,\n navigateHome,\n navigateMiniAppRoute,\n route,\n };\n}\n\nfunction useLauncherNavigationActionValue(\n runtimeRef: MutableRefObject<LauncherNavigationRuntime>,\n goBack: LauncherNavigationActions[\"goBack\"],\n goForward: LauncherNavigationActions[\"goForward\"],\n navigateHome: LauncherNavigationActions[\"navigateHome\"],\n navigateMiniAppRoute: LauncherNavigationActions[\"navigateMiniAppRoute\"],\n): LauncherNavigationActions {\n const openMiniApp = useCallback(\n ({\n appId,\n pathSegments,\n position = DEFAULT_MINI_APP_POSITION,\n reuseExisting = true,\n }: OpenMiniAppRequest) => {\n const {\n actions,\n definition,\n mode: currentMode,\n windows: currentWindows,\n } = runtimeRef.current;\n\n if (currentMode === \"routed\") {\n navigateMiniAppRoute({ appId, pathSegments });\n return null;\n }\n\n const existingWindow = reuseExisting\n ? findTopWindow(currentWindows, (windowEntry) => {\n return windowEntry.appId === appId;\n })\n : null;\n if (existingWindow) {\n actions.restore(existingWindow.id);\n actions.bringToFront(existingWindow.id);\n if (pathSegments) {\n actions.updateRoute(existingWindow.id, pathSegments);\n }\n return existingWindow.id;\n }\n\n const app = definition.apps[appId];\n if (!app) {\n throw new Error(`Unknown mini-app: ${appId}`);\n }\n return actions.create(\n app.title,\n position.x,\n position.y,\n app.createComponent(),\n {\n appId,\n initialShowSidebar: app.initialShowSidebar,\n ...(pathSegments ? { pathSegments } : {}),\n },\n );\n },\n [navigateMiniAppRoute, runtimeRef],\n );\n const getMiniAppHref = useCallback(buildMiniAppPath, []);\n return useMemo<LauncherNavigationActions>(\n () => ({\n getMiniAppHref,\n goBack,\n goForward,\n navigateHome,\n navigateMiniAppRoute,\n openMiniApp,\n }),\n [\n getMiniAppHref,\n goBack,\n goForward,\n navigateHome,\n navigateMiniAppRoute,\n openMiniApp,\n ],\n );\n}\n\n/**\n * Navigation for a launcher's mini-apps, in either mode. In `windowed` mode,\n * opening an app opens or raises its window (inside a\n * {@link WindowStateProvider}); in `routed` mode it navigates the browser to\n * the app's route, `/app/<app id>/…`, which the routed shell shows.\n */\nexport function LauncherNavigationProvider({\n children,\n defaultWindowEnabled = true,\n definition,\n mode,\n}: LauncherNavigationProviderProps) {\n const runtimeRef = useRef<LauncherNavigationRuntime>({\n actions: {\n bringToFront: () => {},\n create: () => \"\",\n restore: () => {},\n updateRoute: () => {},\n },\n definition,\n mode,\n windows: [],\n });\n const {\n goBack,\n goForward,\n history,\n navigateHome,\n navigateMiniAppRoute,\n route,\n } = useLauncherRouteController({\n definition,\n mode,\n runtimeRef,\n });\n const actions = useLauncherNavigationActionValue(\n runtimeRef,\n goBack,\n goForward,\n navigateHome,\n navigateMiniAppRoute,\n );\n const state = useMemo<LauncherNavigationState>(\n () => ({ definition, history, mode, route }),\n [definition, history, mode, route],\n );\n\n return (\n <launcherNavigationActionsContext.context.Provider value={actions}>\n <launcherNavigationStateContext.context.Provider value={state}>\n <LauncherNavigationWindowRuntimeBridge\n defaultWindowEnabled={defaultWindowEnabled}\n definition={definition}\n mode={mode}\n openMiniApp={actions.openMiniApp}\n runtimeRef={runtimeRef}\n />\n {children}\n </launcherNavigationStateContext.context.Provider>\n </launcherNavigationActionsContext.context.Provider>\n );\n}\n\n// The context names apps by their string ids. The actions accept a host's own\n// narrower id type as they are; a host narrows the route's id with\n// isLauncherAppId (or its own guard) to read it back as that type.\nexport const useLauncherNavigationActions =\n launcherNavigationActionsContext.useRequired;\n\nexport const useLauncherNavigationState =\n launcherNavigationStateContext.useRequired;\n\nexport const useOptionalLauncherNavigationState =\n launcherNavigationStateContext.useOptional;\n\n/**\n * The route of `appId` where it is hosted: the browser route in the routed\n * shell, or its window's own route and Back stack in a window. Mini-apps read\n * this rather than branching on navigation mode.\n */\nexport function useMiniAppRouteSegments(appId: string) {\n const actions = launcherNavigationActionsContext.useOptional();\n const state = launcherNavigationStateContext.useOptional();\n const windowRoute = useMiniAppWindowRouteSegments(appId);\n const isGlobalRouted = actions !== null && state?.mode === \"routed\";\n const isRouted = isGlobalRouted || windowRoute !== null;\n const pathSegments =\n isGlobalRouted && state.route.appId === appId\n ? state.route.pathSegments\n : (windowRoute?.pathSegments ?? EMPTY_ROUTE_SEGMENTS);\n const windowSetPathSegments = windowRoute?.setPathSegments;\n const setPathSegments = useCallback(\n (\n nextPathSegments: ReadonlyArray<string>,\n options: { replace?: boolean | undefined } = {},\n ) => {\n if (isGlobalRouted) {\n actions?.navigateMiniAppRoute({\n appId,\n pathSegments: nextPathSegments,\n ...(options.replace === undefined\n ? {}\n : { replace: options.replace }),\n });\n return;\n }\n\n windowSetPathSegments?.(nextPathSegments, options);\n },\n [actions, appId, isGlobalRouted, windowSetPathSegments],\n );\n // \"Can this mini-app step back where it is hosted?\" — browser history in the\n // routed shell, the window's own Back stack in a window. Mini-apps read this\n // rather than branching on navigation mode, so a detail surface that must\n // yield to a real Back affordance asks one question and gets the right answer\n // in both shells.\n const windowGoBack = windowRoute?.goBack;\n const canGoBack = isGlobalRouted\n ? state.history.canGoBack\n : (windowRoute?.canGoBack ?? false);\n const goBack = useCallback(() => {\n if (isGlobalRouted) {\n actions?.goBack();\n return;\n }\n\n windowGoBack?.();\n }, [actions, isGlobalRouted, windowGoBack]);\n\n return useMemo(\n () => ({\n canGoBack,\n goBack,\n isRouted,\n pathSegments,\n setPathSegments,\n }),\n [canGoBack, goBack, isRouted, pathSegments, setPathSegments],\n );\n}\n"]}
|
|
@@ -23,6 +23,12 @@ export interface MiniAppDefinition {
|
|
|
23
23
|
*/
|
|
24
24
|
export interface LauncherDefinition<AppId extends string = string> {
|
|
25
25
|
apps: Readonly<Record<AppId, MiniAppDefinition>>;
|
|
26
|
+
/**
|
|
27
|
+
* Opens when entering windowed mode with no windows, including on mount.
|
|
28
|
+
* Closing the last window leaves the desktop empty until the next entry.
|
|
29
|
+
* Omit to leave window startup to the host. Unknown app ids are ignored.
|
|
30
|
+
*/
|
|
31
|
+
defaultWindowAppId?: AppId | undefined;
|
|
26
32
|
/** Shown at the root route. Defaults to the first app in `order`. */
|
|
27
33
|
homeAppId?: AppId | undefined;
|
|
28
34
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"launcherDefinition.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/launcherDefinition.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"launcherDefinition.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/launcherDefinition.ts"],"names":[],"mappings":"AA0CA,sEAAsE;AACtE,MAAM,UAAU,eAAe,CAC7B,UAAqC,EACrC,KAAgC;IAEhC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC5E,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,oBAAoB,CAClC,UAAqC;IAErC,MAAM,KAAK,GACT,UAAU,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACnD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC;AACrE,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,wBAAwB,CACtC,UAAqC;IAErC,IACE,UAAU,CAAC,SAAS,KAAK,SAAS;QAClC,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,SAAS,CAAC,EACjD,CAAC;QACD,OAAO,UAAU,CAAC,SAAS,CAAC;IAC9B,CAAC;IACD,OAAO,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AACrD,CAAC","sourcesContent":["import type { ComponentType } from \"react\";\nimport type { WindowingIcon } from \"../icons/windowingIcon\";\n\n/** One app a launcher opens: in a window, or as the routed shell's page. */\nexport interface MiniAppDefinition {\n /**\n * Builds the app's component. A window calls it when it opens, and the\n * routed shell when it shows the app, so each gets its own component.\n */\n createComponent: () => ComponentType;\n /** The app's glyph in the launchers and the taskbar. */\n icon?: WindowingIcon | undefined;\n /**\n * Whether the app's sidebar starts shown, in a new window and on the routed\n * shell's tablet tier. Defaults to shown. The phone tier always starts with\n * the sidebar hidden.\n */\n initialShowSidebar?: boolean | undefined;\n title: string;\n}\n\n/**\n * A launcher application: the mini-apps it can open, the order its launchers\n * list them in, and the one the routed shell shows at the root route.\n */\nexport interface LauncherDefinition<AppId extends string = string> {\n apps: Readonly<Record<AppId, MiniAppDefinition>>;\n /**\n * Opens when entering windowed mode with no windows, including on mount.\n * Closing the last window leaves the desktop empty until the next entry.\n * Omit to leave window startup to the host. Unknown app ids are ignored.\n */\n defaultWindowAppId?: AppId | undefined;\n /** Shown at the root route. Defaults to the first app in `order`. */\n homeAppId?: AppId | undefined;\n /**\n * The order the launchers list the apps in. Ids with no app in `apps` are\n * skipped. Defaults to the order of `apps`' keys.\n */\n order?: ReadonlyArray<AppId> | undefined;\n}\n\n/** Narrows an opaque window `appId` to one of the launcher's apps. */\nexport function isLauncherAppId<AppId extends string>(\n definition: LauncherDefinition<AppId>,\n value: string | null | undefined,\n): value is AppId {\n return typeof value === \"string\" && Object.hasOwn(definition.apps, value);\n}\n\n/** The launcher's apps in the order its launchers list them. */\nexport function resolveLauncherOrder<AppId extends string>(\n definition: LauncherDefinition<AppId>,\n): ReadonlyArray<AppId> {\n const order: ReadonlyArray<string> =\n definition.order ?? Object.keys(definition.apps);\n return order.filter((appId) => isLauncherAppId(definition, appId));\n}\n\n/** The app the routed shell shows at the root route, if the launcher has any. */\nexport function resolveLauncherHomeAppId<AppId extends string>(\n definition: LauncherDefinition<AppId>,\n): AppId | null {\n if (\n definition.homeAppId !== undefined &&\n isLauncherAppId(definition, definition.homeAppId)\n ) {\n return definition.homeAppId;\n }\n return resolveLauncherOrder(definition)[0] ?? null;\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type LauncherDefinition } from "./launcherDefinition.js";
|
|
2
|
+
import type { NavigationMode } from "./navigationMode.js";
|
|
3
|
+
/** Opens the host's default once per entry into an empty windowed desktop. */
|
|
4
|
+
export declare function useDefaultWindow({ definition, enabled, mode, openMiniApp, windowCount, }: {
|
|
5
|
+
definition: LauncherDefinition;
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
mode: NavigationMode;
|
|
8
|
+
openMiniApp: (request: {
|
|
9
|
+
appId: string;
|
|
10
|
+
}) => string | null;
|
|
11
|
+
windowCount: number;
|
|
12
|
+
}): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { isLauncherAppId } from "./launcherDefinition.js";
|
|
3
|
+
/** Opens the host's default once per entry into an empty windowed desktop. */
|
|
4
|
+
export function useDefaultWindow({ definition, enabled, mode, openMiniApp, windowCount, }) {
|
|
5
|
+
const handledWindowedEntry = useRef(false);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (mode !== "windowed") {
|
|
8
|
+
handledWindowedEntry.current = false;
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (!enabled || handledWindowedEntry.current)
|
|
12
|
+
return;
|
|
13
|
+
// Record the entry before opening, including across StrictMode effects.
|
|
14
|
+
handledWindowedEntry.current = true;
|
|
15
|
+
const { defaultWindowAppId } = definition;
|
|
16
|
+
if (windowCount === 0 && isLauncherAppId(definition, defaultWindowAppId)) {
|
|
17
|
+
openMiniApp({ appId: defaultWindowAppId });
|
|
18
|
+
}
|
|
19
|
+
}, [definition, enabled, mode, openMiniApp, windowCount]);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=useDefaultWindow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDefaultWindow.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/useDefaultWindow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,eAAe,EAA2B,MAAM,sBAAsB,CAAC;AAGhF,8EAA8E;AAC9E,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,MAAM,EAAE,kBAAkB,EAAE,GAAG,UAAU,CAAC;QAC1C,IAAI,WAAW,KAAK,CAAC,IAAI,eAAe,CAAC,UAAU,EAAE,kBAAkB,CAAC,EAAE,CAAC;YACzE,WAAW,CAAC,EAAE,KAAK,EAAE,kBAAkB,EAAE,CAAC,CAAC;QAC7C,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/** Opens the host's default once per entry into an empty windowed desktop. */\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 const { defaultWindowAppId } = definition;\n if (windowCount === 0 && isLauncherAppId(definition, defaultWindowAppId)) {\n openMiniApp({ appId: defaultWindowAppId });\n }\n }, [definition, enabled, mode, openMiniApp, windowCount]);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tearleads/windowing",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.17",
|
|
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": {
|
package/routed/RoutedPane.css
CHANGED
|
@@ -205,16 +205,19 @@
|
|
|
205
205
|
cursor: pointer;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
.routed-pane-iconbutton:hover:not(:disabled),
|
|
209
208
|
.routed-pane-iconbutton:focus-visible:not(:disabled) {
|
|
210
|
-
background: var(--app-hover-surface);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
.routed-pane-iconbutton[aria-expanded="true"] {
|
|
214
209
|
background: var(--emphasis-surface);
|
|
215
210
|
color: var(--emphasis-text);
|
|
216
211
|
}
|
|
217
212
|
|
|
213
|
+
@media (hover: hover) {
|
|
214
|
+
.routed-pane-iconbutton:hover:not(:disabled),
|
|
215
|
+
.routed-pane-taskbar-menu-button:hover {
|
|
216
|
+
background: var(--emphasis-surface);
|
|
217
|
+
color: var(--emphasis-text);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
218
221
|
.routed-pane-iconbutton:disabled {
|
|
219
222
|
opacity: var(--opacity-disabled);
|
|
220
223
|
cursor: default;
|
|
@@ -352,7 +355,6 @@
|
|
|
352
355
|
cursor: pointer;
|
|
353
356
|
}
|
|
354
357
|
|
|
355
|
-
.routed-pane-taskbar-menu-button:hover,
|
|
356
358
|
.routed-pane-taskbar-menu-button:focus-visible,
|
|
357
359
|
.routed-pane-taskbar-menu-button[aria-expanded="true"] {
|
|
358
360
|
background: var(--emphasis-surface);
|