@tearleads/windowing 0.2.10 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -1
- package/index.d.ts +19 -0
- package/index.js +20 -1
- package/index.js.map +1 -1
- package/launcher/LauncherNavigationProvider.d.ts +71 -0
- package/launcher/LauncherNavigationProvider.js +253 -0
- package/launcher/LauncherNavigationProvider.js.map +1 -0
- package/launcher/MiniAppRouteSegmentsContext.d.ts +19 -0
- package/launcher/MiniAppRouteSegmentsContext.js +26 -0
- package/launcher/MiniAppRouteSegmentsContext.js.map +1 -0
- package/launcher/MiniAppWindow.d.ts +18 -0
- package/launcher/MiniAppWindow.js +41 -0
- package/launcher/MiniAppWindow.js.map +1 -0
- package/launcher/NavigationModeOverrideProvider.d.ts +23 -0
- package/launcher/NavigationModeOverrideProvider.js +31 -0
- package/launcher/NavigationModeOverrideProvider.js.map +1 -0
- package/launcher/NavigationModeSwitch.css +22 -0
- package/launcher/NavigationModeSwitch.d.ts +24 -0
- package/launcher/NavigationModeSwitch.js +40 -0
- package/launcher/NavigationModeSwitch.js.map +1 -0
- package/launcher/breakpoints.d.ts +17 -0
- package/launcher/breakpoints.js +18 -0
- package/launcher/breakpoints.js.map +1 -0
- package/launcher/launcherDefinition.d.ts +39 -0
- package/launcher/launcherDefinition.js +18 -0
- package/launcher/launcherDefinition.js.map +1 -0
- package/launcher/navigationHistory.d.ts +16 -0
- package/launcher/navigationHistory.js +48 -0
- package/launcher/navigationHistory.js.map +1 -0
- package/launcher/navigationMode.d.ts +31 -0
- package/launcher/navigationMode.js +35 -0
- package/launcher/navigationMode.js.map +1 -0
- package/launcher/routePaths.d.ts +17 -0
- package/launcher/routePaths.js +46 -0
- package/launcher/routePaths.js.map +1 -0
- package/launcher/routedPathNavigator.d.ts +20 -0
- package/launcher/routedPathNavigator.js +36 -0
- package/launcher/routedPathNavigator.js.map +1 -0
- package/launcher/storedPreference.d.ts +7 -0
- package/launcher/storedPreference.js +43 -0
- package/launcher/storedPreference.js.map +1 -0
- package/launcher/useActiveLauncherRoute.d.ts +14 -0
- package/launcher/useActiveLauncherRoute.js +41 -0
- package/launcher/useActiveLauncherRoute.js.map +1 -0
- package/launcher/useCompactRoutedMode.d.ts +2 -0
- package/launcher/useCompactRoutedMode.js +9 -0
- package/launcher/useCompactRoutedMode.js.map +1 -0
- package/launcher/useMiniAppRouteState.d.ts +14 -0
- package/launcher/useMiniAppRouteState.js +15 -0
- package/launcher/useMiniAppRouteState.js.map +1 -0
- package/launcher/useNavigationMode.d.ts +23 -0
- package/launcher/useNavigationMode.js +34 -0
- package/launcher/useNavigationMode.js.map +1 -0
- package/launcher/useNavigationModeDocumentAttribute.d.ts +16 -0
- package/launcher/useNavigationModeDocumentAttribute.js +24 -0
- package/launcher/useNavigationModeDocumentAttribute.js.map +1 -0
- package/launcher/useRoutedLayoutActive.d.ts +25 -0
- package/launcher/useRoutedLayoutActive.js +69 -0
- package/launcher/useRoutedLayoutActive.js.map +1 -0
- package/launcher/useRoutedLayoutTier.d.ts +17 -0
- package/launcher/useRoutedLayoutTier.js +24 -0
- package/launcher/useRoutedLayoutTier.js.map +1 -0
- package/package.json +1 -1
- package/routed/RoutedPane.css +393 -0
- package/routed/RoutedPane.d.ts +63 -0
- package/routed/RoutedPane.js +91 -0
- package/routed/RoutedPane.js.map +1 -0
- package/routed/RoutedPaneAppBar.d.ts +8 -0
- package/routed/RoutedPaneAppBar.js +23 -0
- package/routed/RoutedPaneAppBar.js.map +1 -0
- package/routed/RoutedPaneMain.d.ts +15 -0
- package/routed/RoutedPaneMain.js +27 -0
- package/routed/RoutedPaneMain.js.map +1 -0
- package/routed/RoutedPaneNav.css +298 -0
- package/routed/RoutedPaneNav.d.ts +20 -0
- package/routed/RoutedPaneNav.js +106 -0
- package/routed/RoutedPaneNav.js.map +1 -0
- package/routed/RoutedPaneOverlayHost.d.ts +37 -0
- package/routed/RoutedPaneOverlayHost.js +29 -0
- package/routed/RoutedPaneOverlayHost.js.map +1 -0
- package/routed/RoutedPanePlacementButton.d.ts +5 -0
- package/routed/RoutedPanePlacementButton.js +10 -0
- package/routed/RoutedPanePlacementButton.js.map +1 -0
- package/routed/RoutedPaneSidebar.css +61 -0
- package/routed/RoutedPaneSidebar.d.ts +7 -0
- package/routed/RoutedPaneSidebar.js +18 -0
- package/routed/RoutedPaneSidebar.js.map +1 -0
- package/routed/RoutedPaneTaskBar.d.ts +24 -0
- package/routed/RoutedPaneTaskBar.js +24 -0
- package/routed/RoutedPaneTaskBar.js.map +1 -0
- package/routed/classNames.d.ts +2 -0
- package/routed/classNames.js +6 -0
- package/routed/classNames.js.map +1 -0
- package/routed/launcherPlacement.d.ts +7 -0
- package/routed/launcherPlacement.js +8 -0
- package/routed/launcherPlacement.js.map +1 -0
- package/routed/useMobileKeyboardVisible.d.ts +7 -0
- package/routed/useMobileKeyboardVisible.js +78 -0
- package/routed/useMobileKeyboardVisible.js.map +1 -0
- package/routed/useMobileSheetDrag.d.ts +10 -0
- package/routed/useMobileSheetDrag.js +83 -0
- package/routed/useMobileSheetDrag.js.map +1 -0
- package/routed/useRoutedPaneOverlays.d.ts +25 -0
- package/routed/useRoutedPaneOverlays.js +72 -0
- package/routed/useRoutedPaneOverlays.js.map +1 -0
- package/tokens.css +24 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useCallback, } from "react";
|
|
2
|
+
import { createNavigationHistoryState, getNextNavigationHistoryCursor, } from "./navigationHistory.js";
|
|
3
|
+
function pushWindowHistoryCursor(cursor, path) {
|
|
4
|
+
const state = createNavigationHistoryState(window.history.state, cursor);
|
|
5
|
+
window.history.pushState(state, "", path);
|
|
6
|
+
}
|
|
7
|
+
export function replaceWindowHistoryCursor(cursor, path) {
|
|
8
|
+
const state = createNavigationHistoryState(window.history.state, cursor);
|
|
9
|
+
if (path === undefined) {
|
|
10
|
+
window.history.replaceState(state, "");
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
window.history.replaceState(state, "", path);
|
|
14
|
+
}
|
|
15
|
+
export function useRoutedPathNavigator({ historyCursorRef, runtimeRef, setHistoryCursor, setRoute, }) {
|
|
16
|
+
return useCallback(({ path, replace = false, route }) => {
|
|
17
|
+
if (runtimeRef.current.mode !== "routed") {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
setRoute(route);
|
|
21
|
+
const shouldReplace = replace || window.location.pathname === path;
|
|
22
|
+
if (shouldReplace) {
|
|
23
|
+
replaceWindowHistoryCursor(historyCursorRef.current, path);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const currentCursor = historyCursorRef.current;
|
|
27
|
+
const nextCursor = getNextNavigationHistoryCursor(currentCursor);
|
|
28
|
+
replaceWindowHistoryCursor({
|
|
29
|
+
entries: nextCursor.entries,
|
|
30
|
+
index: currentCursor.index,
|
|
31
|
+
});
|
|
32
|
+
setHistoryCursor(nextCursor);
|
|
33
|
+
pushWindowHistoryCursor(nextCursor, path);
|
|
34
|
+
}, [historyCursorRef, runtimeRef, setHistoryCursor, setRoute]);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=routedPathNavigator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routedPathNavigator.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/routedPathNavigator.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,GACZ,MAAM,OAAO,CAAC;AACf,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,GAE/B,MAAM,qBAAqB,CAAC;AAc7B,SAAS,uBAAuB,CAC9B,MAA+B,EAC/B,IAAY;IAEZ,MAAM,KAAK,GAAG,4BAA4B,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACzE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,MAA+B,EAC/B,IAAa;IAEb,MAAM,KAAK,GAAG,4BAA4B,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACzE,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,EACrC,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,QAAQ,GAMT;IACC,OAAO,WAAW,CAChB,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,KAAK,EAAE,KAAK,EAA4B,EAAE,EAAE;QAC7D,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACzC,OAAO;QACT,CAAC;QAED,QAAQ,CAAC,KAAK,CAAC,CAAC;QAChB,MAAM,aAAa,GAAG,OAAO,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,KAAK,IAAI,CAAC;QACnE,IAAI,aAAa,EAAE,CAAC;YAClB,0BAA0B,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC3D,OAAO;QACT,CAAC;QAED,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,CAAC;QAC/C,MAAM,UAAU,GAAG,8BAA8B,CAAC,aAAa,CAAC,CAAC;QACjE,0BAA0B,CAAC;YACzB,OAAO,EAAE,UAAU,CAAC,OAAO;YAC3B,KAAK,EAAE,aAAa,CAAC,KAAK;SAC3B,CAAC,CAAC;QACH,gBAAgB,CAAC,UAAU,CAAC,CAAC;QAC7B,uBAAuB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC,EACD,CAAC,gBAAgB,EAAE,UAAU,EAAE,gBAAgB,EAAE,QAAQ,CAAC,CAC3D,CAAC;AACJ,CAAC","sourcesContent":["import {\n type Dispatch,\n type MutableRefObject,\n type SetStateAction,\n useCallback,\n} from \"react\";\nimport {\n createNavigationHistoryState,\n getNextNavigationHistoryCursor,\n type NavigationHistoryCursor,\n} from \"./navigationHistory\";\nimport type { NavigationMode } from \"./navigationMode\";\nimport type { LauncherRoute } from \"./routePaths\";\n\ninterface RoutedNavigationRuntime {\n mode: NavigationMode;\n}\n\ninterface RoutedPathNavigatorInput {\n path: string;\n replace?: boolean | undefined;\n route: LauncherRoute;\n}\n\nfunction pushWindowHistoryCursor(\n cursor: NavigationHistoryCursor,\n path: string,\n) {\n const state = createNavigationHistoryState(window.history.state, cursor);\n window.history.pushState(state, \"\", path);\n}\n\nexport function replaceWindowHistoryCursor(\n cursor: NavigationHistoryCursor,\n path?: string,\n) {\n const state = createNavigationHistoryState(window.history.state, cursor);\n if (path === undefined) {\n window.history.replaceState(state, \"\");\n return;\n }\n\n window.history.replaceState(state, \"\", path);\n}\n\nexport function useRoutedPathNavigator({\n historyCursorRef,\n runtimeRef,\n setHistoryCursor,\n setRoute,\n}: {\n historyCursorRef: MutableRefObject<NavigationHistoryCursor>;\n runtimeRef: MutableRefObject<RoutedNavigationRuntime>;\n setHistoryCursor: (cursor: NavigationHistoryCursor) => void;\n setRoute: Dispatch<SetStateAction<LauncherRoute>>;\n}) {\n return useCallback(\n ({ path, replace = false, route }: RoutedPathNavigatorInput) => {\n if (runtimeRef.current.mode !== \"routed\") {\n return;\n }\n\n setRoute(route);\n const shouldReplace = replace || window.location.pathname === path;\n if (shouldReplace) {\n replaceWindowHistoryCursor(historyCursorRef.current, path);\n return;\n }\n\n const currentCursor = historyCursorRef.current;\n const nextCursor = getNextNavigationHistoryCursor(currentCursor);\n replaceWindowHistoryCursor({\n entries: nextCursor.entries,\n index: currentCursor.index,\n });\n setHistoryCursor(nextCursor);\n pushWindowHistoryCursor(nextCursor, path);\n },\n [historyCursorRef, runtimeRef, setHistoryCursor, setRoute],\n );\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loads a stored preference, funneling every failure mode (no storage,
|
|
3
|
+
* storage throws, `parse` throws) into `parse(null)` so the parser's
|
|
4
|
+
* null-branch is the single source of the fallback value.
|
|
5
|
+
*/
|
|
6
|
+
export declare function loadStoredPreference<T>(storageKey: string, parse: (stored: string | null) => T): T;
|
|
7
|
+
export declare function saveStoredPreference(storageKey: string, value: string): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Best-effort localStorage persistence for the launcher's display preferences
|
|
2
|
+
// (the navigation-mode choice, the launcher's placement). Unavailable or
|
|
3
|
+
// throwing storage degrades to the caller's fallback.
|
|
4
|
+
function getLocalStorage() {
|
|
5
|
+
try {
|
|
6
|
+
return typeof globalThis.localStorage === "undefined"
|
|
7
|
+
? null
|
|
8
|
+
: globalThis.localStorage;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Loads a stored preference, funneling every failure mode (no storage,
|
|
16
|
+
* storage throws, `parse` throws) into `parse(null)` so the parser's
|
|
17
|
+
* null-branch is the single source of the fallback value.
|
|
18
|
+
*/
|
|
19
|
+
export function loadStoredPreference(storageKey, parse) {
|
|
20
|
+
const storage = getLocalStorage();
|
|
21
|
+
if (!storage) {
|
|
22
|
+
return parse(null);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
return parse(storage.getItem(storageKey));
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return parse(null);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function saveStoredPreference(storageKey, value) {
|
|
32
|
+
const storage = getLocalStorage();
|
|
33
|
+
if (!storage) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
storage.setItem(storageKey, value);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Persistence is best-effort; ignore disabled storage and quota errors.
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=storedPreference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storedPreference.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/storedPreference.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,yEAAyE;AACzE,sDAAsD;AAEtD,SAAS,eAAe;IACtB,IAAI,CAAC;QACH,OAAO,OAAO,UAAU,CAAC,YAAY,KAAK,WAAW;YACnD,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAClC,UAAkB,EAClB,KAAmC;IAEnC,MAAM,OAAO,GAAG,eAAe,EAAE,CAAC;IAClC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,UAAkB,EAAE,KAAa;IACpE,MAAM,OAAO,GAAG,eAAe,EAAE,CAAC;IAClC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO;IACT,CAAC;IACD,IAAI,CAAC;QACH,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,wEAAwE;IAC1E,CAAC;AACH,CAAC","sourcesContent":["// Best-effort localStorage persistence for the launcher's display preferences\n// (the navigation-mode choice, the launcher's placement). Unavailable or\n// throwing storage degrades to the caller's fallback.\n\nfunction getLocalStorage(): Pick<Storage, \"getItem\" | \"setItem\"> | null {\n try {\n return typeof globalThis.localStorage === \"undefined\"\n ? null\n : globalThis.localStorage;\n } catch {\n return null;\n }\n}\n\n/**\n * Loads a stored preference, funneling every failure mode (no storage,\n * storage throws, `parse` throws) into `parse(null)` so the parser's\n * null-branch is the single source of the fallback value.\n */\nexport function loadStoredPreference<T>(\n storageKey: string,\n parse: (stored: string | null) => T,\n): T {\n const storage = getLocalStorage();\n if (!storage) {\n return parse(null);\n }\n try {\n return parse(storage.getItem(storageKey));\n } catch {\n return parse(null);\n }\n}\n\nexport function saveStoredPreference(storageKey: string, value: string): void {\n const storage = getLocalStorage();\n if (!storage) {\n return;\n }\n try {\n storage.setItem(storageKey, value);\n } catch {\n // Persistence is best-effort; ignore disabled storage and quota errors.\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type WindowEntry } from "../window/WindowStateProvider/index.js";
|
|
2
|
+
import { type LauncherDefinition } from "./launcherDefinition.js";
|
|
3
|
+
import type { NavigationMode } from "./navigationMode.js";
|
|
4
|
+
import type { LauncherRoute } from "./routePaths.js";
|
|
5
|
+
/**
|
|
6
|
+
* The mini-app the launcher is presenting: the routed shell's route, or the
|
|
7
|
+
* foremost visible window of one of the launcher's apps.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveActiveLauncherRoute<AppId extends string>(definition: LauncherDefinition<AppId>, mode: NavigationMode, route: LauncherRoute, windows: ReadonlyArray<WindowEntry>): LauncherRoute<AppId>;
|
|
10
|
+
/**
|
|
11
|
+
* {@link resolveActiveLauncherRoute} for the launcher in context, typed by the
|
|
12
|
+
* definition the host passes, normally the one it gave the provider.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useActiveLauncherRoute<AppId extends string>(definition: LauncherDefinition<AppId>): LauncherRoute<AppId>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { findTopWindow, useWindowStateData, } from "../window/WindowStateProvider/index.js";
|
|
3
|
+
import { useLauncherNavigationState } from "./LauncherNavigationProvider.js";
|
|
4
|
+
import { isLauncherAppId } from "./launcherDefinition.js";
|
|
5
|
+
const EMPTY_ROUTE_SEGMENTS = [];
|
|
6
|
+
const EMPTY_LAUNCHER_ROUTE = {
|
|
7
|
+
appId: null,
|
|
8
|
+
pathSegments: [],
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The mini-app the launcher is presenting: the routed shell's route, or the
|
|
12
|
+
* foremost visible window of one of the launcher's apps.
|
|
13
|
+
*/
|
|
14
|
+
export function resolveActiveLauncherRoute(definition, mode, route, windows) {
|
|
15
|
+
if (mode === "routed") {
|
|
16
|
+
return isLauncherAppId(definition, route.appId)
|
|
17
|
+
? { appId: route.appId, pathSegments: route.pathSegments }
|
|
18
|
+
: EMPTY_LAUNCHER_ROUTE;
|
|
19
|
+
}
|
|
20
|
+
// Shell chrome follows the foremost visible mini-app; utility windows without
|
|
21
|
+
// an app route do not change which mini-app the launcher is presenting.
|
|
22
|
+
const topWindow = findTopWindow(windows, (candidate) => {
|
|
23
|
+
return !candidate.minimized && isLauncherAppId(definition, candidate.appId);
|
|
24
|
+
});
|
|
25
|
+
return topWindow && isLauncherAppId(definition, topWindow.appId)
|
|
26
|
+
? {
|
|
27
|
+
appId: topWindow.appId,
|
|
28
|
+
pathSegments: topWindow.pathSegments ?? EMPTY_ROUTE_SEGMENTS,
|
|
29
|
+
}
|
|
30
|
+
: EMPTY_LAUNCHER_ROUTE;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* {@link resolveActiveLauncherRoute} for the launcher in context, typed by the
|
|
34
|
+
* definition the host passes, normally the one it gave the provider.
|
|
35
|
+
*/
|
|
36
|
+
export function useActiveLauncherRoute(definition) {
|
|
37
|
+
const { mode, route } = useLauncherNavigationState();
|
|
38
|
+
const { windows } = useWindowStateData();
|
|
39
|
+
return useMemo(() => resolveActiveLauncherRoute(definition, mode, route, windows), [definition, mode, route, windows]);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=useActiveLauncherRoute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useActiveLauncherRoute.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/useActiveLauncherRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EACL,aAAa,EACb,kBAAkB,GAEnB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,eAAe,EAA2B,MAAM,sBAAsB,CAAC;AAIhF,MAAM,oBAAoB,GAA0B,EAAE,CAAC;AACvD,MAAM,oBAAoB,GAAyB;IACjD,KAAK,EAAE,IAAI;IACX,YAAY,EAAE,EAAE;CACjB,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CACxC,UAAqC,EACrC,IAAoB,EACpB,KAAoB,EACpB,OAAmC;IAEnC,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,OAAO,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC;YAC7C,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE;YAC1D,CAAC,CAAC,oBAAoB,CAAC;IAC3B,CAAC;IAED,8EAA8E;IAC9E,wEAAwE;IACxE,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,EAAE;QACrD,OAAO,CAAC,SAAS,CAAC,SAAS,IAAI,eAAe,CAAC,UAAU,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,IAAI,eAAe,CAAC,UAAU,EAAE,SAAS,CAAC,KAAK,CAAC;QAC9D,CAAC,CAAC;YACE,KAAK,EAAE,SAAS,CAAC,KAAK;YACtB,YAAY,EAAE,SAAS,CAAC,YAAY,IAAI,oBAAoB;SAC7D;QACH,CAAC,CAAC,oBAAoB,CAAC;AAC3B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACpC,UAAqC;IAErC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,0BAA0B,EAAE,CAAC;IACrD,MAAM,EAAE,OAAO,EAAE,GAAG,kBAAkB,EAAE,CAAC;IACzC,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,0BAA0B,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,EAClE,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CACnC,CAAC;AACJ,CAAC","sourcesContent":["import { useMemo } from \"react\";\nimport {\n findTopWindow,\n useWindowStateData,\n type WindowEntry,\n} from \"../window/WindowStateProvider\";\nimport { useLauncherNavigationState } from \"./LauncherNavigationProvider\";\nimport { isLauncherAppId, type LauncherDefinition } from \"./launcherDefinition\";\nimport type { NavigationMode } from \"./navigationMode\";\nimport type { LauncherRoute } from \"./routePaths\";\n\nconst EMPTY_ROUTE_SEGMENTS: ReadonlyArray<string> = [];\nconst EMPTY_LAUNCHER_ROUTE: LauncherRoute<never> = {\n appId: null,\n pathSegments: [],\n};\n\n/**\n * The mini-app the launcher is presenting: the routed shell's route, or the\n * foremost visible window of one of the launcher's apps.\n */\nexport function resolveActiveLauncherRoute<AppId extends string>(\n definition: LauncherDefinition<AppId>,\n mode: NavigationMode,\n route: LauncherRoute,\n windows: ReadonlyArray<WindowEntry>,\n): LauncherRoute<AppId> {\n if (mode === \"routed\") {\n return isLauncherAppId(definition, route.appId)\n ? { appId: route.appId, pathSegments: route.pathSegments }\n : EMPTY_LAUNCHER_ROUTE;\n }\n\n // Shell chrome follows the foremost visible mini-app; utility windows without\n // an app route do not change which mini-app the launcher is presenting.\n const topWindow = findTopWindow(windows, (candidate) => {\n return !candidate.minimized && isLauncherAppId(definition, candidate.appId);\n });\n return topWindow && isLauncherAppId(definition, topWindow.appId)\n ? {\n appId: topWindow.appId,\n pathSegments: topWindow.pathSegments ?? EMPTY_ROUTE_SEGMENTS,\n }\n : EMPTY_LAUNCHER_ROUTE;\n}\n\n/**\n * {@link resolveActiveLauncherRoute} for the launcher in context, typed by the\n * definition the host passes, normally the one it gave the provider.\n */\nexport function useActiveLauncherRoute<AppId extends string>(\n definition: LauncherDefinition<AppId>,\n): LauncherRoute<AppId> {\n const { mode, route } = useLauncherNavigationState();\n const { windows } = useWindowStateData();\n return useMemo(\n () => resolveActiveLauncherRoute(definition, mode, route, windows),\n [definition, mode, route, windows],\n );\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useOptionalLauncherNavigationState } from "./LauncherNavigationProvider.js";
|
|
2
|
+
import { useRoutedLayoutTier } from "./useRoutedLayoutTier.js";
|
|
3
|
+
/** Whether the routed shell is on screen at its phone tier. */
|
|
4
|
+
export function useCompactRoutedMode() {
|
|
5
|
+
const navigation = useOptionalLauncherNavigationState();
|
|
6
|
+
const tier = useRoutedLayoutTier();
|
|
7
|
+
return navigation?.mode === "routed" && tier === "mobile";
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=useCompactRoutedMode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCompactRoutedMode.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/useCompactRoutedMode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,+DAA+D;AAC/D,MAAM,UAAU,oBAAoB;IAClC,MAAM,UAAU,GAAG,kCAAkC,EAAE,CAAC;IACxD,MAAM,IAAI,GAAG,mBAAmB,EAAE,CAAC;IAEnC,OAAO,UAAU,EAAE,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,QAAQ,CAAC;AAC5D,CAAC","sourcesContent":["import { useOptionalLauncherNavigationState } from \"./LauncherNavigationProvider\";\nimport { useRoutedLayoutTier } from \"./useRoutedLayoutTier\";\n\n/** Whether the routed shell is on screen at its phone tier. */\nexport function useCompactRoutedMode(): boolean {\n const navigation = useOptionalLauncherNavigationState();\n const tier = useRoutedLayoutTier();\n\n return navigation?.mode === \"routed\" && tier === \"mobile\";\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface MiniAppRouteSetOptions {
|
|
2
|
+
replace?: boolean | undefined;
|
|
3
|
+
}
|
|
4
|
+
export declare function useMiniAppRouteState<TRoute, TNextRoute extends TRoute = TRoute>({ appId, formatRouteSegments, localRoute, parseRouteSegments, setLocalRoute, }: {
|
|
5
|
+
appId: string;
|
|
6
|
+
formatRouteSegments: (route: TNextRoute) => ReadonlyArray<string>;
|
|
7
|
+
localRoute: TRoute;
|
|
8
|
+
parseRouteSegments: (segments: ReadonlyArray<string>) => TRoute;
|
|
9
|
+
setLocalRoute?: ((route: TNextRoute) => void) | undefined;
|
|
10
|
+
}): {
|
|
11
|
+
isRouted: boolean;
|
|
12
|
+
route: TRoute;
|
|
13
|
+
setRoute: (nextRoute: TNextRoute, options?: MiniAppRouteSetOptions) => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { useMiniAppRouteSegments } from "./LauncherNavigationProvider.js";
|
|
3
|
+
export function useMiniAppRouteState({ appId, formatRouteSegments, localRoute, parseRouteSegments, setLocalRoute, }) {
|
|
4
|
+
const { isRouted, pathSegments, setPathSegments } = useMiniAppRouteSegments(appId);
|
|
5
|
+
const route = isRouted ? parseRouteSegments(pathSegments) : localRoute;
|
|
6
|
+
const setRoute = useCallback((nextRoute, options = {}) => {
|
|
7
|
+
if (isRouted) {
|
|
8
|
+
setPathSegments(formatRouteSegments(nextRoute), options);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
setLocalRoute?.(nextRoute);
|
|
12
|
+
}, [formatRouteSegments, isRouted, setLocalRoute, setPathSegments]);
|
|
13
|
+
return { isRouted, route, setRoute };
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=useMiniAppRouteState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMiniAppRouteState.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/useMiniAppRouteState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAMvE,MAAM,UAAU,oBAAoB,CAGlC,EACA,KAAK,EACL,mBAAmB,EACnB,UAAU,EACV,kBAAkB,EAClB,aAAa,GAOd;IACC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,GAC/C,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IACvE,MAAM,QAAQ,GAAG,WAAW,CAC1B,CAAC,SAAqB,EAAE,UAAkC,EAAE,EAAE,EAAE;QAC9D,IAAI,QAAQ,EAAE,CAAC;YACb,eAAe,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC;YACzD,OAAO;QACT,CAAC;QAED,aAAa,EAAE,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC,EACD,CAAC,mBAAmB,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,CAAC,CAChE,CAAC;IAEF,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AACvC,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport { useMiniAppRouteSegments } from \"./LauncherNavigationProvider\";\n\nexport interface MiniAppRouteSetOptions {\n replace?: boolean | undefined;\n}\n\nexport function useMiniAppRouteState<\n TRoute,\n TNextRoute extends TRoute = TRoute,\n>({\n appId,\n formatRouteSegments,\n localRoute,\n parseRouteSegments,\n setLocalRoute,\n}: {\n appId: string;\n formatRouteSegments: (route: TNextRoute) => ReadonlyArray<string>;\n localRoute: TRoute;\n parseRouteSegments: (segments: ReadonlyArray<string>) => TRoute;\n setLocalRoute?: ((route: TNextRoute) => void) | undefined;\n}) {\n const { isRouted, pathSegments, setPathSegments } =\n useMiniAppRouteSegments(appId);\n const route = isRouted ? parseRouteSegments(pathSegments) : localRoute;\n const setRoute = useCallback(\n (nextRoute: TNextRoute, options: MiniAppRouteSetOptions = {}) => {\n if (isRouted) {\n setPathSegments(formatRouteSegments(nextRoute), options);\n return;\n }\n\n setLocalRoute?.(nextRoute);\n },\n [formatRouteSegments, isRouted, setLocalRoute, setPathSegments],\n );\n\n return { isRouted, route, setRoute };\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type NavigationMode } from "./navigationMode.js";
|
|
2
|
+
interface UseNavigationModeInput {
|
|
3
|
+
/**
|
|
4
|
+
* A host's fixed layout. It wins over `preferredMode`, and yields only to
|
|
5
|
+
* the user's `override`.
|
|
6
|
+
*/
|
|
7
|
+
forcedMode?: NavigationMode | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* The user's manual choice (see {@link NavigationModeOverrideProvider}). It
|
|
10
|
+
* wins over `forcedMode` while windowed remains eligible.
|
|
11
|
+
*/
|
|
12
|
+
override?: NavigationMode | null | undefined;
|
|
13
|
+
/** The mode when nothing forces one. Defaults to `routed`. */
|
|
14
|
+
preferredMode?: NavigationMode | undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The launcher's current navigation mode, following the screen as it resizes
|
|
18
|
+
* and the pointer as it changes. A manual choice wins over the host mode while
|
|
19
|
+
* windowed remains eligible: narrow and touch screens route even when a
|
|
20
|
+
* desktop windowed choice is saved.
|
|
21
|
+
*/
|
|
22
|
+
export declare function useNavigationMode({ forcedMode, override, preferredMode, }?: UseNavigationModeInput): NavigationMode;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { WINDOWED_LAYOUT_NARROW_QUERY } from "./breakpoints.js";
|
|
3
|
+
import { isWindowedLayoutEligible, readNavigationEnvironment, resolveNavigationMode, } from "./navigationMode.js";
|
|
4
|
+
const COARSE_POINTER_QUERY = "(pointer: coarse)";
|
|
5
|
+
/**
|
|
6
|
+
* The launcher's current navigation mode, following the screen as it resizes
|
|
7
|
+
* and the pointer as it changes. A manual choice wins over the host mode while
|
|
8
|
+
* windowed remains eligible: narrow and touch screens route even when a
|
|
9
|
+
* desktop windowed choice is saved.
|
|
10
|
+
*/
|
|
11
|
+
export function useNavigationMode({ forcedMode, override, preferredMode, } = {}) {
|
|
12
|
+
const [environment, setEnvironment] = useState(readNavigationEnvironment);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const narrowQuery = window.matchMedia(WINDOWED_LAYOUT_NARROW_QUERY);
|
|
15
|
+
const pointerQuery = window.matchMedia(COARSE_POINTER_QUERY);
|
|
16
|
+
const updateEnvironment = () => setEnvironment(readNavigationEnvironment());
|
|
17
|
+
updateEnvironment();
|
|
18
|
+
narrowQuery.addEventListener("change", updateEnvironment);
|
|
19
|
+
pointerQuery.addEventListener("change", updateEnvironment);
|
|
20
|
+
return () => {
|
|
21
|
+
narrowQuery.removeEventListener("change", updateEnvironment);
|
|
22
|
+
pointerQuery.removeEventListener("change", updateEnvironment);
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
25
|
+
const availableOverride = override === "windowed" && !isWindowedLayoutEligible(environment)
|
|
26
|
+
? null
|
|
27
|
+
: override;
|
|
28
|
+
return resolveNavigationMode({
|
|
29
|
+
environment,
|
|
30
|
+
forcedMode: availableOverride ?? forcedMode,
|
|
31
|
+
preferredMode,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=useNavigationMode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNavigationMode.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/useNavigationMode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EACL,wBAAwB,EAGxB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAiBjD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAChC,UAAU,EACV,QAAQ,EACR,aAAa,MACa,EAAE;IAC5B,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAC5C,yBAAyB,CAC1B,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,4BAA4B,CAAC,CAAC;QACpE,MAAM,YAAY,GAAG,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;QAC7D,MAAM,iBAAiB,GAAG,GAAG,EAAE,CAAC,cAAc,CAAC,yBAAyB,EAAE,CAAC,CAAC;QAC5E,iBAAiB,EAAE,CAAC;QACpB,WAAW,CAAC,gBAAgB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;QAC1D,YAAY,CAAC,gBAAgB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;QAC3D,OAAO,GAAG,EAAE;YACV,WAAW,CAAC,mBAAmB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;YAC7D,YAAY,CAAC,mBAAmB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;QAChE,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,iBAAiB,GACrB,QAAQ,KAAK,UAAU,IAAI,CAAC,wBAAwB,CAAC,WAAW,CAAC;QAC/D,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,QAAQ,CAAC;IAEf,OAAO,qBAAqB,CAAC;QAC3B,WAAW;QACX,UAAU,EAAE,iBAAiB,IAAI,UAAU;QAC3C,aAAa;KACd,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { useEffect, useState } from \"react\";\nimport { WINDOWED_LAYOUT_NARROW_QUERY } from \"./breakpoints\";\nimport {\n isWindowedLayoutEligible,\n type NavigationEnvironment,\n type NavigationMode,\n readNavigationEnvironment,\n resolveNavigationMode,\n} from \"./navigationMode\";\n\nconst COARSE_POINTER_QUERY = \"(pointer: coarse)\";\n\ninterface UseNavigationModeInput {\n /**\n * A host's fixed layout. It wins over `preferredMode`, and yields only to\n * the user's `override`.\n */\n forcedMode?: NavigationMode | undefined;\n /**\n * The user's manual choice (see {@link NavigationModeOverrideProvider}). It\n * wins over `forcedMode` while windowed remains eligible.\n */\n override?: NavigationMode | null | undefined;\n /** The mode when nothing forces one. Defaults to `routed`. */\n preferredMode?: NavigationMode | undefined;\n}\n\n/**\n * The launcher's current navigation mode, following the screen as it resizes\n * and the pointer as it changes. A manual choice wins over the host mode while\n * windowed remains eligible: narrow and touch screens route even when a\n * desktop windowed choice is saved.\n */\nexport function useNavigationMode({\n forcedMode,\n override,\n preferredMode,\n}: UseNavigationModeInput = {}): NavigationMode {\n const [environment, setEnvironment] = useState<NavigationEnvironment>(\n readNavigationEnvironment,\n );\n\n useEffect(() => {\n const narrowQuery = window.matchMedia(WINDOWED_LAYOUT_NARROW_QUERY);\n const pointerQuery = window.matchMedia(COARSE_POINTER_QUERY);\n const updateEnvironment = () => setEnvironment(readNavigationEnvironment());\n updateEnvironment();\n narrowQuery.addEventListener(\"change\", updateEnvironment);\n pointerQuery.addEventListener(\"change\", updateEnvironment);\n return () => {\n narrowQuery.removeEventListener(\"change\", updateEnvironment);\n pointerQuery.removeEventListener(\"change\", updateEnvironment);\n };\n }, []);\n\n const availableOverride =\n override === \"windowed\" && !isWindowedLayoutEligible(environment)\n ? null\n : override;\n\n return resolveNavigationMode({\n environment,\n forcedMode: availableOverride ?? forcedMode,\n preferredMode,\n });\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { NavigationMode } from "./navigationMode.js";
|
|
2
|
+
/**
|
|
3
|
+
* Mirrors the active navigation mode onto `<html data-navigation-mode>` while
|
|
4
|
+
* the caller is mounted, so CSS can size interactive controls for touch
|
|
5
|
+
* whenever the routed (phone / tablet / iPad) shell is active. Stamping the
|
|
6
|
+
* document root lets portaled menus and modals inherit the rules too.
|
|
7
|
+
*
|
|
8
|
+
* The attribute — not a `@media (pointer: coarse)` query — is the touch hook
|
|
9
|
+
* because an iPad with a mouse or trackpad renders the routed layout yet reports
|
|
10
|
+
* `pointer: fine`; a coarse-pointer query would leave every control at its dense
|
|
11
|
+
* desktop size on that device.
|
|
12
|
+
*
|
|
13
|
+
* The package's own stylesheets key their touch sizes off
|
|
14
|
+
* `:root[data-navigation-mode="routed"]`, and so can a host's.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useNavigationModeDocumentAttribute(mode: NavigationMode): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Mirrors the active navigation mode onto `<html data-navigation-mode>` while
|
|
4
|
+
* the caller is mounted, so CSS can size interactive controls for touch
|
|
5
|
+
* whenever the routed (phone / tablet / iPad) shell is active. Stamping the
|
|
6
|
+
* document root lets portaled menus and modals inherit the rules too.
|
|
7
|
+
*
|
|
8
|
+
* The attribute — not a `@media (pointer: coarse)` query — is the touch hook
|
|
9
|
+
* because an iPad with a mouse or trackpad renders the routed layout yet reports
|
|
10
|
+
* `pointer: fine`; a coarse-pointer query would leave every control at its dense
|
|
11
|
+
* desktop size on that device.
|
|
12
|
+
*
|
|
13
|
+
* The package's own stylesheets key their touch sizes off
|
|
14
|
+
* `:root[data-navigation-mode="routed"]`, and so can a host's.
|
|
15
|
+
*/
|
|
16
|
+
export function useNavigationModeDocumentAttribute(mode) {
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
document.documentElement.setAttribute("data-navigation-mode", mode);
|
|
19
|
+
return () => {
|
|
20
|
+
document.documentElement.removeAttribute("data-navigation-mode");
|
|
21
|
+
};
|
|
22
|
+
}, [mode]);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=useNavigationModeDocumentAttribute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNavigationModeDocumentAttribute.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/useNavigationModeDocumentAttribute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kCAAkC,CAAC,IAAoB;IACrE,SAAS,CAAC,GAAG,EAAE;QACb,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAC,sBAAsB,EAAE,IAAI,CAAC,CAAC;QACpE,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,eAAe,CAAC,eAAe,CAAC,sBAAsB,CAAC,CAAC;QACnE,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AACb,CAAC","sourcesContent":["import { useEffect } from \"react\";\nimport type { NavigationMode } from \"./navigationMode\";\n\n/**\n * Mirrors the active navigation mode onto `<html data-navigation-mode>` while\n * the caller is mounted, so CSS can size interactive controls for touch\n * whenever the routed (phone / tablet / iPad) shell is active. Stamping the\n * document root lets portaled menus and modals inherit the rules too.\n *\n * The attribute — not a `@media (pointer: coarse)` query — is the touch hook\n * because an iPad with a mouse or trackpad renders the routed layout yet reports\n * `pointer: fine`; a coarse-pointer query would leave every control at its dense\n * desktop size on that device.\n *\n * The package's own stylesheets key their touch sizes off\n * `:root[data-navigation-mode=\"routed\"]`, and so can a host's.\n */\nexport function useNavigationModeDocumentAttribute(mode: NavigationMode): void {\n useEffect(() => {\n document.documentElement.setAttribute(\"data-navigation-mode\", mode);\n return () => {\n document.documentElement.removeAttribute(\"data-navigation-mode\");\n };\n }, [mode]);\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `true` while the routed (touch) layout is active — mobile **or** tablet/iPad —
|
|
3
|
+
* tracked reactively via the `data-navigation-mode` attribute so it stays in
|
|
4
|
+
* lockstep with the CSS that keys off the same hook. Reading the attribute —
|
|
5
|
+
* rather than re-deriving the mode from the viewport — guarantees JS logic and
|
|
6
|
+
* CSS agree even when the host forces a mode or a dev toggle overrides it.
|
|
7
|
+
*
|
|
8
|
+
* Use it as the single "touch layout" gate: for row-pitch math, and for
|
|
9
|
+
* touch-only affordances such as a row overflow ("kebab") button, which has no
|
|
10
|
+
* right-click equivalent on touch.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useRoutedLayoutActive(): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* `true` while the windowed (desktop window-manager) layout is active — the
|
|
15
|
+
* counterpart to {@link useRoutedLayoutActive}, tracked off the same
|
|
16
|
+
* `data-navigation-mode` attribute so JS and CSS stay in lockstep.
|
|
17
|
+
*
|
|
18
|
+
* The routed layout's negation is deliberately *not* used here: a render with no
|
|
19
|
+
* attribute at all (an isolated component tree, e.g. a unit test) is neither
|
|
20
|
+
* routed nor windowed, so `!routed` would wrongly report windowed. This checks
|
|
21
|
+
* for the explicit `"windowed"` value instead. Use it for portaled overlays
|
|
22
|
+
* that should read as floating windows on the desktop while the routed (touch)
|
|
23
|
+
* shell keeps its compact styling.
|
|
24
|
+
*/
|
|
25
|
+
export declare function useWindowedLayoutActive(): boolean;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
// A single shared MutationObserver fans out to every subscriber. This hook backs
|
|
3
|
+
// every virtualized row/frame and every touch-only affordance (e.g. row kebabs),
|
|
4
|
+
// so a per-subscription observer would spin up dozens of identical observers
|
|
5
|
+
// watching the same attribute on the same element.
|
|
6
|
+
const navigationModeListeners = new Set();
|
|
7
|
+
let navigationModeObserver = null;
|
|
8
|
+
/**
|
|
9
|
+
* Subscribes to changes of the `data-navigation-mode` attribute that
|
|
10
|
+
* {@link useNavigationModeDocumentAttribute} stamps on `<html>`, sharing
|
|
11
|
+
* one observer across all subscribers.
|
|
12
|
+
*/
|
|
13
|
+
function subscribeToNavigationMode(onChange) {
|
|
14
|
+
navigationModeListeners.add(onChange);
|
|
15
|
+
if (!navigationModeObserver) {
|
|
16
|
+
navigationModeObserver = new MutationObserver(() => {
|
|
17
|
+
for (const listener of navigationModeListeners) {
|
|
18
|
+
listener();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
navigationModeObserver.observe(document.documentElement, {
|
|
22
|
+
attributes: true,
|
|
23
|
+
attributeFilter: ["data-navigation-mode"],
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return () => {
|
|
27
|
+
navigationModeListeners.delete(onChange);
|
|
28
|
+
if (navigationModeListeners.size === 0 && navigationModeObserver) {
|
|
29
|
+
navigationModeObserver.disconnect();
|
|
30
|
+
navigationModeObserver = null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function isRoutedLayoutSnapshot() {
|
|
35
|
+
return (document.documentElement.getAttribute("data-navigation-mode") === "routed");
|
|
36
|
+
}
|
|
37
|
+
function isWindowedLayoutSnapshot() {
|
|
38
|
+
return (document.documentElement.getAttribute("data-navigation-mode") === "windowed");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* `true` while the routed (touch) layout is active — mobile **or** tablet/iPad —
|
|
42
|
+
* tracked reactively via the `data-navigation-mode` attribute so it stays in
|
|
43
|
+
* lockstep with the CSS that keys off the same hook. Reading the attribute —
|
|
44
|
+
* rather than re-deriving the mode from the viewport — guarantees JS logic and
|
|
45
|
+
* CSS agree even when the host forces a mode or a dev toggle overrides it.
|
|
46
|
+
*
|
|
47
|
+
* Use it as the single "touch layout" gate: for row-pitch math, and for
|
|
48
|
+
* touch-only affordances such as a row overflow ("kebab") button, which has no
|
|
49
|
+
* right-click equivalent on touch.
|
|
50
|
+
*/
|
|
51
|
+
export function useRoutedLayoutActive() {
|
|
52
|
+
return useSyncExternalStore(subscribeToNavigationMode, isRoutedLayoutSnapshot, isRoutedLayoutSnapshot);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* `true` while the windowed (desktop window-manager) layout is active — the
|
|
56
|
+
* counterpart to {@link useRoutedLayoutActive}, tracked off the same
|
|
57
|
+
* `data-navigation-mode` attribute so JS and CSS stay in lockstep.
|
|
58
|
+
*
|
|
59
|
+
* The routed layout's negation is deliberately *not* used here: a render with no
|
|
60
|
+
* attribute at all (an isolated component tree, e.g. a unit test) is neither
|
|
61
|
+
* routed nor windowed, so `!routed` would wrongly report windowed. This checks
|
|
62
|
+
* for the explicit `"windowed"` value instead. Use it for portaled overlays
|
|
63
|
+
* that should read as floating windows on the desktop while the routed (touch)
|
|
64
|
+
* shell keeps its compact styling.
|
|
65
|
+
*/
|
|
66
|
+
export function useWindowedLayoutActive() {
|
|
67
|
+
return useSyncExternalStore(subscribeToNavigationMode, isWindowedLayoutSnapshot, isWindowedLayoutSnapshot);
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=useRoutedLayoutActive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRoutedLayoutActive.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/useRoutedLayoutActive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAE7C,iFAAiF;AACjF,iFAAiF;AACjF,6EAA6E;AAC7E,mDAAmD;AACnD,MAAM,uBAAuB,GAAG,IAAI,GAAG,EAAc,CAAC;AACtD,IAAI,sBAAsB,GAA4B,IAAI,CAAC;AAE3D;;;;GAIG;AACH,SAAS,yBAAyB,CAAC,QAAoB;IACrD,uBAAuB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC5B,sBAAsB,GAAG,IAAI,gBAAgB,CAAC,GAAG,EAAE;YACjD,KAAK,MAAM,QAAQ,IAAI,uBAAuB,EAAE,CAAC;gBAC/C,QAAQ,EAAE,CAAC;YACb,CAAC;QACH,CAAC,CAAC,CAAC;QACH,sBAAsB,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,EAAE;YACvD,UAAU,EAAE,IAAI;YAChB,eAAe,EAAE,CAAC,sBAAsB,CAAC;SAC1C,CAAC,CAAC;IACL,CAAC;IAED,OAAO,GAAG,EAAE;QACV,uBAAuB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACzC,IAAI,uBAAuB,CAAC,IAAI,KAAK,CAAC,IAAI,sBAAsB,EAAE,CAAC;YACjE,sBAAsB,CAAC,UAAU,EAAE,CAAC;YACpC,sBAAsB,GAAG,IAAI,CAAC;QAChC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,sBAAsB;IAC7B,OAAO,CACL,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAC,sBAAsB,CAAC,KAAK,QAAQ,CAC3E,CAAC;AACJ,CAAC;AAED,SAAS,wBAAwB;IAC/B,OAAO,CACL,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAC,sBAAsB,CAAC,KAAK,UAAU,CAC7E,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,oBAAoB,CACzB,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,CACvB,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,uBAAuB;IACrC,OAAO,oBAAoB,CACzB,yBAAyB,EACzB,wBAAwB,EACxB,wBAAwB,CACzB,CAAC;AACJ,CAAC","sourcesContent":["import { useSyncExternalStore } from \"react\";\n\n// A single shared MutationObserver fans out to every subscriber. This hook backs\n// every virtualized row/frame and every touch-only affordance (e.g. row kebabs),\n// so a per-subscription observer would spin up dozens of identical observers\n// watching the same attribute on the same element.\nconst navigationModeListeners = new Set<() => void>();\nlet navigationModeObserver: MutationObserver | null = null;\n\n/**\n * Subscribes to changes of the `data-navigation-mode` attribute that\n * {@link useNavigationModeDocumentAttribute} stamps on `<html>`, sharing\n * one observer across all subscribers.\n */\nfunction subscribeToNavigationMode(onChange: () => void): () => void {\n navigationModeListeners.add(onChange);\n if (!navigationModeObserver) {\n navigationModeObserver = new MutationObserver(() => {\n for (const listener of navigationModeListeners) {\n listener();\n }\n });\n navigationModeObserver.observe(document.documentElement, {\n attributes: true,\n attributeFilter: [\"data-navigation-mode\"],\n });\n }\n\n return () => {\n navigationModeListeners.delete(onChange);\n if (navigationModeListeners.size === 0 && navigationModeObserver) {\n navigationModeObserver.disconnect();\n navigationModeObserver = null;\n }\n };\n}\n\nfunction isRoutedLayoutSnapshot(): boolean {\n return (\n document.documentElement.getAttribute(\"data-navigation-mode\") === \"routed\"\n );\n}\n\nfunction isWindowedLayoutSnapshot(): boolean {\n return (\n document.documentElement.getAttribute(\"data-navigation-mode\") === \"windowed\"\n );\n}\n\n/**\n * `true` while the routed (touch) layout is active — mobile **or** tablet/iPad —\n * tracked reactively via the `data-navigation-mode` attribute so it stays in\n * lockstep with the CSS that keys off the same hook. Reading the attribute —\n * rather than re-deriving the mode from the viewport — guarantees JS logic and\n * CSS agree even when the host forces a mode or a dev toggle overrides it.\n *\n * Use it as the single \"touch layout\" gate: for row-pitch math, and for\n * touch-only affordances such as a row overflow (\"kebab\") button, which has no\n * right-click equivalent on touch.\n */\nexport function useRoutedLayoutActive(): boolean {\n return useSyncExternalStore(\n subscribeToNavigationMode,\n isRoutedLayoutSnapshot,\n isRoutedLayoutSnapshot,\n );\n}\n\n/**\n * `true` while the windowed (desktop window-manager) layout is active — the\n * counterpart to {@link useRoutedLayoutActive}, tracked off the same\n * `data-navigation-mode` attribute so JS and CSS stay in lockstep.\n *\n * The routed layout's negation is deliberately *not* used here: a render with no\n * attribute at all (an isolated component tree, e.g. a unit test) is neither\n * routed nor windowed, so `!routed` would wrongly report windowed. This checks\n * for the explicit `\"windowed\"` value instead. Use it for portaled overlays\n * that should read as floating windows on the desktop while the routed (touch)\n * shell keeps its compact styling.\n */\nexport function useWindowedLayoutActive(): boolean {\n return useSyncExternalStore(\n subscribeToNavigationMode,\n isWindowedLayoutSnapshot,\n isWindowedLayoutSnapshot,\n );\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two responsive shells the routed layout can present.
|
|
3
|
+
*
|
|
4
|
+
* - `mobile` — phone-style chrome: a top app bar with a hamburger that opens a
|
|
5
|
+
* slide-in navigation drawer over the content.
|
|
6
|
+
* - `tablet` — iPad-style chrome: a persistent left sidebar rail beside the
|
|
7
|
+
* main content.
|
|
8
|
+
*/
|
|
9
|
+
export type RoutedLayoutTier = "mobile" | "tablet";
|
|
10
|
+
/**
|
|
11
|
+
* Tracks which routed shell to render, keyed off the same `760px` line the
|
|
12
|
+
* `RoutedPane.css` media query uses (see {@link ROUTED_TABLET_BREAKPOINT_PX}).
|
|
13
|
+
*
|
|
14
|
+
* Re-renders when the viewport crosses the breakpoint so the shell swaps
|
|
15
|
+
* between the mobile drawer and the persistent tablet rail live.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useRoutedLayoutTier(): RoutedLayoutTier;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { ROUTED_TABLET_QUERY, } from "./breakpoints.js";
|
|
3
|
+
function readTier() {
|
|
4
|
+
return window.matchMedia(ROUTED_TABLET_QUERY).matches ? "tablet" : "mobile";
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Tracks which routed shell to render, keyed off the same `760px` line the
|
|
8
|
+
* `RoutedPane.css` media query uses (see {@link ROUTED_TABLET_BREAKPOINT_PX}).
|
|
9
|
+
*
|
|
10
|
+
* Re-renders when the viewport crosses the breakpoint so the shell swaps
|
|
11
|
+
* between the mobile drawer and the persistent tablet rail live.
|
|
12
|
+
*/
|
|
13
|
+
export function useRoutedLayoutTier() {
|
|
14
|
+
const [tier, setTier] = useState(readTier);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const query = window.matchMedia(ROUTED_TABLET_QUERY);
|
|
17
|
+
const updateTier = () => setTier(query.matches ? "tablet" : "mobile");
|
|
18
|
+
updateTier();
|
|
19
|
+
query.addEventListener("change", updateTier);
|
|
20
|
+
return () => query.removeEventListener("change", updateTier);
|
|
21
|
+
}, []);
|
|
22
|
+
return tier;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=useRoutedLayoutTier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRoutedLayoutTier.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/useRoutedLayoutTier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAEL,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAYvB,SAAS,QAAQ;IACf,OAAO,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC9E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE3C,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;QACrD,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QAEtE,UAAU,EAAE,CAAC;QACb,KAAK,CAAC,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC7C,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,mBAAmB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAC/D,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { useEffect, useState } from \"react\";\nimport {\n ROUTED_TABLET_BREAKPOINT_PX,\n ROUTED_TABLET_QUERY,\n} from \"./breakpoints\";\n\n/**\n * The two responsive shells the routed layout can present.\n *\n * - `mobile` — phone-style chrome: a top app bar with a hamburger that opens a\n * slide-in navigation drawer over the content.\n * - `tablet` — iPad-style chrome: a persistent left sidebar rail beside the\n * main content.\n */\nexport type RoutedLayoutTier = \"mobile\" | \"tablet\";\n\nfunction readTier(): RoutedLayoutTier {\n return window.matchMedia(ROUTED_TABLET_QUERY).matches ? \"tablet\" : \"mobile\";\n}\n\n/**\n * Tracks which routed shell to render, keyed off the same `760px` line the\n * `RoutedPane.css` media query uses (see {@link ROUTED_TABLET_BREAKPOINT_PX}).\n *\n * Re-renders when the viewport crosses the breakpoint so the shell swaps\n * between the mobile drawer and the persistent tablet rail live.\n */\nexport function useRoutedLayoutTier(): RoutedLayoutTier {\n const [tier, setTier] = useState(readTier);\n\n useEffect(() => {\n const query = window.matchMedia(ROUTED_TABLET_QUERY);\n const updateTier = () => setTier(query.matches ? \"tablet\" : \"mobile\");\n\n updateTier();\n query.addEventListener(\"change\", updateTier);\n return () => query.removeEventListener(\"change\", updateTier);\n }, []);\n\n return tier;\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.12",
|
|
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": {
|