@tearleads/windowing 0.2.40 → 0.2.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +4 -3
  2. package/display/DisplayProperties.css +94 -0
  3. package/display/DisplayProperties.d.ts +6 -4
  4. package/display/DisplayProperties.js +23 -5
  5. package/display/DisplayProperties.js.map +1 -1
  6. package/docs/appearance.md +44 -4
  7. package/docs/launcher.md +9 -0
  8. package/docs/screensavers.md +3 -1
  9. package/docs/windows.md +7 -1
  10. package/index.d.ts +4 -1
  11. package/index.js +8 -5
  12. package/index.js.map +1 -1
  13. package/launcher/LauncherNavigationProvider.d.ts +9 -3
  14. package/launcher/LauncherNavigationProvider.js +10 -8
  15. package/launcher/LauncherNavigationProvider.js.map +1 -1
  16. package/launcher/useWindowedEntryWindows.d.ts +17 -0
  17. package/launcher/useWindowedEntryWindows.js +76 -0
  18. package/launcher/useWindowedEntryWindows.js.map +1 -0
  19. package/menu/useLongPress.d.ts +15 -2
  20. package/menu/useLongPress.js +43 -14
  21. package/menu/useLongPress.js.map +1 -1
  22. package/package.json +1 -1
  23. package/routed/RoutedPaneNav.css +2 -1
  24. package/screensaver/ScreensaverProvider.d.ts +2 -2
  25. package/screensaver/ScreensaverProvider.js +4 -2
  26. package/screensaver/ScreensaverProvider.js.map +1 -1
  27. package/tray/SystemTray.css +20 -0
  28. package/tray/SystemTray.d.ts +23 -0
  29. package/tray/SystemTray.js +54 -0
  30. package/tray/SystemTray.js.map +1 -0
  31. package/tray/SystemTrayProvider.d.ts +26 -0
  32. package/tray/SystemTrayProvider.js +62 -0
  33. package/tray/SystemTrayProvider.js.map +1 -0
  34. package/tray/systemTrayDefinition.d.ts +19 -0
  35. package/tray/systemTrayDefinition.js +2 -0
  36. package/tray/systemTrayDefinition.js.map +1 -0
  37. package/launcher/useDefaultWindow.d.ts +0 -15
  38. package/launcher/useDefaultWindow.js +0 -28
  39. package/launcher/useDefaultWindow.js.map +0 -1
@@ -0,0 +1,17 @@
1
+ import { type LauncherDefinition } from "./launcherDefinition.js";
2
+ import type { NavigationMode } from "./navigationMode.js";
3
+ import type { OpenMiniAppRequest } from "./openMiniAppWindow.js";
4
+ /**
5
+ * Opens the windows a windowed desktop starts with, once per entry into
6
+ * windowed mode: the host's default windows, in order, if the desktop is
7
+ * empty, and then the app the browser's URL names, in front. While windowed,
8
+ * a browser history step to another app's URL opens that app too.
9
+ */
10
+ export declare function useWindowedEntryWindows({ defaultWindowEnabled, definition, mode, openMiniApp, routeWindowEnabled, windowCount, }: {
11
+ defaultWindowEnabled: boolean;
12
+ definition: LauncherDefinition;
13
+ mode: NavigationMode;
14
+ openMiniApp: (request: OpenMiniAppRequest) => string | null;
15
+ routeWindowEnabled: boolean;
16
+ windowCount: number;
17
+ }): void;
@@ -0,0 +1,76 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { isLauncherAppId } from "./launcherDefinition.js";
3
+ import { parseLauncherRoute } from "./routePaths.js";
4
+ /** The request that opens the app the browser's URL names, if it names one. */
5
+ function readRouteWindowRequest(definition) {
6
+ const { appId, pathSegments } = parseLauncherRoute(window.location.pathname, definition);
7
+ if (appId === null)
8
+ return null;
9
+ // An app's root route names no place within it, so the app's open window
10
+ // is raised where it is.
11
+ return pathSegments.length > 0 ? { appId, pathSegments } : { appId };
12
+ }
13
+ /**
14
+ * The requests that open the host's default windows, each app once and
15
+ * without the URL's app, which opens after them: the launcher's open requests
16
+ * within one pass cannot see the windows the earlier ones created.
17
+ */
18
+ function readDefaultWindowRequests(definition, routeRequest) {
19
+ return [...new Set(definition.defaultWindowAppIds)]
20
+ .filter((appId) => appId !== routeRequest?.appId && isLauncherAppId(definition, appId))
21
+ .map((appId) => ({ appId }));
22
+ }
23
+ /**
24
+ * Opens the windows a windowed desktop starts with, once per entry into
25
+ * windowed mode: the host's default windows, in order, if the desktop is
26
+ * empty, and then the app the browser's URL names, in front. While windowed,
27
+ * a browser history step to another app's URL opens that app too.
28
+ */
29
+ export function useWindowedEntryWindows({ defaultWindowEnabled, definition, mode, openMiniApp, routeWindowEnabled, windowCount, }) {
30
+ const handledDefaultWindows = useRef(false);
31
+ const handledRouteWindow = useRef(false);
32
+ useEffect(() => {
33
+ if (mode !== "windowed") {
34
+ handledDefaultWindows.current = false;
35
+ handledRouteWindow.current = false;
36
+ return;
37
+ }
38
+ // The URL belongs to the entry, not to this launcher: one that is
39
+ // disabled at the entry skips it rather than opening it when enabled.
40
+ const routeRequest = routeWindowEnabled && !handledRouteWindow.current
41
+ ? readRouteWindowRequest(definition)
42
+ : null;
43
+ // Record the entry before opening, including across StrictMode effects.
44
+ handledRouteWindow.current = true;
45
+ const requests = [];
46
+ if (defaultWindowEnabled && !handledDefaultWindows.current) {
47
+ handledDefaultWindows.current = true;
48
+ if (windowCount === 0) {
49
+ requests.push(...readDefaultWindowRequests(definition, routeRequest));
50
+ }
51
+ }
52
+ if (routeRequest)
53
+ requests.push(routeRequest);
54
+ for (const request of requests)
55
+ openMiniApp(request);
56
+ }, [
57
+ defaultWindowEnabled,
58
+ definition,
59
+ mode,
60
+ openMiniApp,
61
+ routeWindowEnabled,
62
+ windowCount,
63
+ ]);
64
+ useEffect(() => {
65
+ if (mode !== "windowed" || !routeWindowEnabled)
66
+ return;
67
+ const openRouteWindow = () => {
68
+ const routeRequest = readRouteWindowRequest(definition);
69
+ if (routeRequest)
70
+ openMiniApp(routeRequest);
71
+ };
72
+ window.addEventListener("popstate", openRouteWindow);
73
+ return () => window.removeEventListener("popstate", openRouteWindow);
74
+ }, [definition, mode, openMiniApp, routeWindowEnabled]);
75
+ }
76
+ //# sourceMappingURL=useWindowedEntryWindows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWindowedEntryWindows.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/launcher/useWindowedEntryWindows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO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E,eAAe,CAAC,CAAC;IACvE,CAAC,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { isLauncherAppId, type LauncherDefinition } from \"./launcherDefinition\";\nimport type { NavigationMode } from \"./navigationMode\";\nimport type { OpenMiniAppRequest } from \"./openMiniAppWindow\";\nimport { parseLauncherRoute } from \"./routePaths\";\n\n/** The request that opens the app the browser's URL names, if it names one. */\nfunction readRouteWindowRequest(\n definition: LauncherDefinition,\n): OpenMiniAppRequest | null {\n const { appId, pathSegments } = parseLauncherRoute(\n window.location.pathname,\n definition,\n );\n if (appId === null) return null;\n // An app's root route names no place within it, so the app's open window\n // is raised where it is.\n return pathSegments.length > 0 ? { appId, pathSegments } : { appId };\n}\n\n/**\n * The requests that open the host's default windows, each app once and\n * without the URL's app, which opens after them: the launcher's open requests\n * within one pass cannot see the windows the earlier ones created.\n */\nfunction readDefaultWindowRequests(\n definition: LauncherDefinition,\n routeRequest: OpenMiniAppRequest | null,\n): OpenMiniAppRequest[] {\n return [...new Set(definition.defaultWindowAppIds)]\n .filter(\n (appId) =>\n appId !== routeRequest?.appId && isLauncherAppId(definition, appId),\n )\n .map((appId) => ({ appId }));\n}\n\n/**\n * Opens the windows a windowed desktop starts with, once per entry into\n * windowed mode: the host's default windows, in order, if the desktop is\n * empty, and then the app the browser's URL names, in front. While windowed,\n * a browser history step to another app's URL opens that app too.\n */\nexport function useWindowedEntryWindows({\n defaultWindowEnabled,\n definition,\n mode,\n openMiniApp,\n routeWindowEnabled,\n windowCount,\n}: {\n defaultWindowEnabled: boolean;\n definition: LauncherDefinition;\n mode: NavigationMode;\n openMiniApp: (request: OpenMiniAppRequest) => string | null;\n routeWindowEnabled: boolean;\n windowCount: number;\n}) {\n const handledDefaultWindows = useRef(false);\n const handledRouteWindow = useRef(false);\n\n useEffect(() => {\n if (mode !== \"windowed\") {\n handledDefaultWindows.current = false;\n handledRouteWindow.current = false;\n return;\n }\n // The URL belongs to the entry, not to this launcher: one that is\n // disabled at the entry skips it rather than opening it when enabled.\n const routeRequest =\n routeWindowEnabled && !handledRouteWindow.current\n ? readRouteWindowRequest(definition)\n : null;\n // Record the entry before opening, including across StrictMode effects.\n handledRouteWindow.current = true;\n const requests: OpenMiniAppRequest[] = [];\n if (defaultWindowEnabled && !handledDefaultWindows.current) {\n handledDefaultWindows.current = true;\n if (windowCount === 0) {\n requests.push(...readDefaultWindowRequests(definition, routeRequest));\n }\n }\n if (routeRequest) requests.push(routeRequest);\n for (const request of requests) openMiniApp(request);\n }, [\n defaultWindowEnabled,\n definition,\n mode,\n openMiniApp,\n routeWindowEnabled,\n windowCount,\n ]);\n\n useEffect(() => {\n if (mode !== \"windowed\" || !routeWindowEnabled) return;\n const openRouteWindow = () => {\n const routeRequest = readRouteWindowRequest(definition);\n if (routeRequest) openMiniApp(routeRequest);\n };\n window.addEventListener(\"popstate\", openRouteWindow);\n return () => window.removeEventListener(\"popstate\", openRouteWindow);\n }, [definition, mode, openMiniApp, routeWindowEnabled]);\n}\n"]}
@@ -5,10 +5,23 @@ interface LongPressHandlers {
5
5
  onPointerMove: (event: ReactPointerEvent<HTMLElement>) => void;
6
6
  onPointerUp: (event: ReactPointerEvent<HTMLElement>) => void;
7
7
  }
8
+ interface LongPressOptions {
9
+ /**
10
+ * Deliver the gesture as a mouse right-click arrives: a secondary-button
11
+ * `mousedown`, then `contextmenu`, on the element the finger pressed rather
12
+ * than the element holding these handlers. Open menus then close as they do
13
+ * on any press outside them, and a control inside a wrapper sees the event
14
+ * first, before it bubbles to the wrapper's menu. If the pressed element
15
+ * left the page during the hold (an icon redrawn for a new state), the
16
+ * element now under the finger receives both, or else the holder.
17
+ */
18
+ emulateRightClick?: boolean | undefined;
19
+ }
8
20
  /**
9
21
  * Returns pointer handlers that, when a **touch** pointer is held still for
10
22
  * {@link LONG_PRESS_DELAY_MS}, dispatch a native `contextmenu` event on the
11
- * pressed element at the touch point.
23
+ * element holding them at the touch point (or, with `emulateRightClick`, a
24
+ * right-click's `mousedown` and `contextmenu` on the pressed element).
12
25
  *
13
26
  * Dispatching the real event (rather than calling a handler directly) means the
14
27
  * element's existing `onContextMenu` — the same one a right-click triggers —
@@ -25,5 +38,5 @@ interface LongPressHandlers {
25
38
  * Pass `enabled: false` (e.g. when no context-menu handler is wired) to make the
26
39
  * returned handlers no-ops.
27
40
  */
28
- export declare function useLongPress(enabled: boolean): LongPressHandlers;
41
+ export declare function useLongPress(enabled: boolean, options?: LongPressOptions): LongPressHandlers;
29
42
  export {};
@@ -4,10 +4,38 @@ const LONG_PRESS_DELAY_MS = 450;
4
4
  const LONG_PRESS_MOVE_TOLERANCE_PX = 10;
5
5
  /** Drop the click-suppressor if no synthesized click arrives within this window. */
6
6
  const SYNTHESIZED_CLICK_WINDOW_MS = 700;
7
+ // The element to deliver to: the pressed element, else (when a re-render
8
+ // replaced it) the one now under the finger inside the holder, else the
9
+ // holder; null when even the holder has left the page.
10
+ function resolvePressedElement(pressed, holder, point) {
11
+ if (pressed?.isConnected) {
12
+ return pressed;
13
+ }
14
+ const underFinger = pressed
15
+ ? holder.ownerDocument.elementFromPoint(point.x, point.y)
16
+ : null;
17
+ if (underFinger && holder.contains(underFinger)) {
18
+ return underFinger;
19
+ }
20
+ return holder.isConnected ? holder : null;
21
+ }
22
+ function deliverLongPress(element, point, emulateRightClick) {
23
+ const init = {
24
+ bubbles: true,
25
+ cancelable: true,
26
+ clientX: point.x,
27
+ clientY: point.y,
28
+ };
29
+ if (emulateRightClick) {
30
+ element.dispatchEvent(new MouseEvent("mousedown", { ...init, button: 2, buttons: 2 }));
31
+ }
32
+ element.dispatchEvent(new MouseEvent("contextmenu", init));
33
+ }
7
34
  /**
8
35
  * Returns pointer handlers that, when a **touch** pointer is held still for
9
36
  * {@link LONG_PRESS_DELAY_MS}, dispatch a native `contextmenu` event on the
10
- * pressed element at the touch point.
37
+ * element holding them at the touch point (or, with `emulateRightClick`, a
38
+ * right-click's `mousedown` and `contextmenu` on the pressed element).
11
39
  *
12
40
  * Dispatching the real event (rather than calling a handler directly) means the
13
41
  * element's existing `onContextMenu` — the same one a right-click triggers —
@@ -24,7 +52,8 @@ const SYNTHESIZED_CLICK_WINDOW_MS = 700;
24
52
  * Pass `enabled: false` (e.g. when no context-menu handler is wired) to make the
25
53
  * returned handlers no-ops.
26
54
  */
27
- export function useLongPress(enabled) {
55
+ export function useLongPress(enabled, options) {
56
+ const emulateRightClick = options?.emulateRightClick === true;
28
57
  const timerRef = useRef(null);
29
58
  const originRef = useRef(null);
30
59
  const removeClickSuppressorRef = useRef(null);
@@ -70,21 +99,21 @@ export function useLongPress(enabled) {
70
99
  return;
71
100
  }
72
101
  clearTimer();
73
- originRef.current = { x: event.clientX, y: event.clientY };
74
- const element = event.currentTarget;
75
- const clientX = event.clientX;
76
- const clientY = event.clientY;
102
+ const point = { x: event.clientX, y: event.clientY };
103
+ originRef.current = point;
104
+ const holder = event.currentTarget;
105
+ const pressed = emulateRightClick && event.target instanceof Element
106
+ ? event.target
107
+ : null;
77
108
  timerRef.current = setTimeout(() => {
78
109
  timerRef.current = null;
79
- armClickSuppressor();
80
- element.dispatchEvent(new MouseEvent("contextmenu", {
81
- bubbles: true,
82
- cancelable: true,
83
- clientX,
84
- clientY,
85
- }));
110
+ const element = resolvePressedElement(pressed, holder, point);
111
+ if (element) {
112
+ armClickSuppressor();
113
+ deliverLongPress(element, point, emulateRightClick);
114
+ }
86
115
  }, LONG_PRESS_DELAY_MS);
87
- }, [armClickSuppressor, clearTimer, enabled]);
116
+ }, [armClickSuppressor, clearTimer, emulateRightClick, enabled]);
88
117
  const onPointerMove = useCallback((event) => {
89
118
  const origin = originRef.current;
90
119
  if (!origin) {
@@ -1 +1 @@
1
- {"version":3,"file":"useLongPress.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/useLongPress.ts"],"names":[],"mappings":"AAAA,OAAO,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AC5B,OAAO,EAAE,IAAI;gBACb,UAAU,EAAE,IAAI;gBAChB,OAAO;gBACP,OAAO;aACR,CAAC,CACH,CAAC;QACJ,CAAC,EAAE,mBAAmB,CAAC,CAAC;IAC1B,CAAC,EACD,CAAC,kBAAkB,EAAE,UAAU,EAAE,OAAO,CAAC,CAC1C,CAAC;IAEF,MAAM,aAAa,GAAG,WAAW,CAC/B,CAAC,KAAqC,EAAE,EAAE;QACxC,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC;QACjC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO;QACT,CAAC;QAED,MAAM,WAAW,GACf,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,4BAA4B;YACjE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,4BAA4B,CAAC;QACpE,IAAI,WAAW,EAAE,CAAC;YAChB,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC,EACD,CAAC,UAAU,CAAC,CACb,CAAC;IAEF,OAAO;QACL,eAAe,EAAE,UAAU;QAC3B,aAAa;QACb,aAAa;QACb,WAAW,EAAE,UAAU;KACxB,CAAC;AACJ,CAAC","sourcesContent":["import {\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\n\nconst LONG_PRESS_DELAY_MS = 450;\n/** Cancel the press if the finger drifts past this many px (a scroll, not a hold). */\nconst LONG_PRESS_MOVE_TOLERANCE_PX = 10;\n/** Drop the click-suppressor if no synthesized click arrives within this window. */\nconst SYNTHESIZED_CLICK_WINDOW_MS = 700;\n\ninterface LongPressHandlers {\n onPointerCancel: (event: ReactPointerEvent<HTMLElement>) => void;\n onPointerDown: (event: ReactPointerEvent<HTMLElement>) => void;\n onPointerMove: (event: ReactPointerEvent<HTMLElement>) => void;\n onPointerUp: (event: ReactPointerEvent<HTMLElement>) => void;\n}\n\n/**\n * Returns pointer handlers that, when a **touch** pointer is held still for\n * {@link LONG_PRESS_DELAY_MS}, dispatch a native `contextmenu` event on the\n * pressed element at the touch point.\n *\n * Dispatching the real event (rather than calling a handler directly) means the\n * element's existing `onContextMenu` — the same one a right-click triggers —\n * fires with a genuine event, so touch reuses the desktop context-menu path\n * verbatim. Mouse and pen pointers are ignored so right-click stays the desktop\n * affordance.\n *\n * After the long press fires we register a one-shot capturing `click` listener\n * on `window` to swallow the click the browser synthesizes on touch release —\n * `preventDefault()` on `pointerup` does NOT suppress that click per the Pointer\n * Events spec, so without this the element's `onClick` (navigate/select) would\n * also run.\n *\n * Pass `enabled: false` (e.g. when no context-menu handler is wired) to make the\n * returned handlers no-ops.\n */\nexport function useLongPress(enabled: boolean): LongPressHandlers {\n const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const originRef = useRef<{ x: number; y: number } | null>(null);\n const removeClickSuppressorRef = useRef<(() => void) | null>(null);\n\n const clearTimer = useCallback(() => {\n if (timerRef.current !== null) {\n clearTimeout(timerRef.current);\n timerRef.current = null;\n }\n originRef.current = null;\n }, []);\n\n // Swallow exactly the next click (the one the browser synthesizes from the\n // touch release after a long press) and then detach. A timeout detaches the\n // suppressor if that click never arrives, so a later genuine tap still works.\n const armClickSuppressor = useCallback(() => {\n removeClickSuppressorRef.current?.();\n\n let fallbackTimer: ReturnType<typeof setTimeout> | null = null;\n const onClickCapture = (clickEvent: MouseEvent) => {\n clickEvent.preventDefault();\n clickEvent.stopPropagation();\n removeClickSuppressorRef.current?.();\n };\n\n const remove = () => {\n window.removeEventListener(\"click\", onClickCapture, true);\n if (fallbackTimer !== null) {\n clearTimeout(fallbackTimer);\n fallbackTimer = null;\n }\n removeClickSuppressorRef.current = null;\n };\n\n removeClickSuppressorRef.current = remove;\n window.addEventListener(\"click\", onClickCapture, true);\n fallbackTimer = setTimeout(remove, SYNTHESIZED_CLICK_WINDOW_MS);\n }, []);\n\n // Tear down on unmount, and also when `enabled` flips off mid-press so a\n // scheduled long-press timer / click suppressor never fires after the hook\n // is disabled.\n useEffect(\n () => () => {\n clearTimer();\n removeClickSuppressorRef.current?.();\n },\n [clearTimer, enabled],\n );\n\n const onPointerDown = useCallback(\n (event: ReactPointerEvent<HTMLElement>) => {\n if (!enabled || event.pointerType !== \"touch\") {\n return;\n }\n\n clearTimer();\n originRef.current = { x: event.clientX, y: event.clientY };\n const element = event.currentTarget;\n const clientX = event.clientX;\n const clientY = event.clientY;\n timerRef.current = setTimeout(() => {\n timerRef.current = null;\n armClickSuppressor();\n element.dispatchEvent(\n new MouseEvent(\"contextmenu\", {\n bubbles: true,\n cancelable: true,\n clientX,\n clientY,\n }),\n );\n }, LONG_PRESS_DELAY_MS);\n },\n [armClickSuppressor, clearTimer, enabled],\n );\n\n const onPointerMove = useCallback(\n (event: ReactPointerEvent<HTMLElement>) => {\n const origin = originRef.current;\n if (!origin) {\n return;\n }\n\n const movedTooFar =\n Math.abs(event.clientX - origin.x) > LONG_PRESS_MOVE_TOLERANCE_PX ||\n Math.abs(event.clientY - origin.y) > LONG_PRESS_MOVE_TOLERANCE_PX;\n if (movedTooFar) {\n clearTimer();\n }\n },\n [clearTimer],\n );\n\n return {\n onPointerCancel: clearTimer,\n onPointerDown,\n onPointerMove,\n onPointerUp: clearTimer,\n };\n}\n"]}
1
+ {"version":3,"file":"useLongPress.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/menu/useLongPress.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,SAAS,EACT,MAAM,GACP,MAAM,OAAO,CAAC;AAEf,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,sFAAsF;AACtF,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,oFAAoF;AACpF,MAAM,2BAA2B,GAAG,GAAG,CAAC;AA2BxC,yEAAyE;AACzE,wEAAwE;AACxE,uDAAuD;AACvD,SAAS,qBAAqB,CAC5B,OAAuB,EACvB,M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AAE;QACxC,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC;QACjC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO;QACT,CAAC;QAED,MAAM,WAAW,GACf,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,4BAA4B;YACjE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,4BAA4B,CAAC;QACpE,IAAI,WAAW,EAAE,CAAC;YAChB,UAAU,EAAE,CAAC;QACf,CAAC;IACH,CAAC,EACD,CAAC,UAAU,CAAC,CACb,CAAC;IAEF,OAAO;QACL,eAAe,EAAE,UAAU;QAC3B,aAAa;QACb,aAAa;QACb,WAAW,EAAE,UAAU;KACxB,CAAC;AACJ,CAAC","sourcesContent":["import {\n type PointerEvent as ReactPointerEvent,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\n\nconst LONG_PRESS_DELAY_MS = 450;\n/** Cancel the press if the finger drifts past this many px (a scroll, not a hold). */\nconst LONG_PRESS_MOVE_TOLERANCE_PX = 10;\n/** Drop the click-suppressor if no synthesized click arrives within this window. */\nconst SYNTHESIZED_CLICK_WINDOW_MS = 700;\n\ninterface LongPressHandlers {\n onPointerCancel: (event: ReactPointerEvent<HTMLElement>) => void;\n onPointerDown: (event: ReactPointerEvent<HTMLElement>) => void;\n onPointerMove: (event: ReactPointerEvent<HTMLElement>) => void;\n onPointerUp: (event: ReactPointerEvent<HTMLElement>) => void;\n}\n\ninterface LongPressOptions {\n /**\n * Deliver the gesture as a mouse right-click arrives: a secondary-button\n * `mousedown`, then `contextmenu`, on the element the finger pressed rather\n * than the element holding these handlers. Open menus then close as they do\n * on any press outside them, and a control inside a wrapper sees the event\n * first, before it bubbles to the wrapper's menu. If the pressed element\n * left the page during the hold (an icon redrawn for a new state), the\n * element now under the finger receives both, or else the holder.\n */\n emulateRightClick?: boolean | undefined;\n}\n\ninterface Point {\n x: number;\n y: number;\n}\n\n// The element to deliver to: the pressed element, else (when a re-render\n// replaced it) the one now under the finger inside the holder, else the\n// holder; null when even the holder has left the page.\nfunction resolvePressedElement(\n pressed: Element | null,\n holder: HTMLElement,\n point: Point,\n): Element | null {\n if (pressed?.isConnected) {\n return pressed;\n }\n const underFinger = pressed\n ? holder.ownerDocument.elementFromPoint(point.x, point.y)\n : null;\n if (underFinger && holder.contains(underFinger)) {\n return underFinger;\n }\n return holder.isConnected ? holder : null;\n}\n\nfunction deliverLongPress(\n element: Element,\n point: Point,\n emulateRightClick: boolean,\n): void {\n const init = {\n bubbles: true,\n cancelable: true,\n clientX: point.x,\n clientY: point.y,\n };\n if (emulateRightClick) {\n element.dispatchEvent(\n new MouseEvent(\"mousedown\", { ...init, button: 2, buttons: 2 }),\n );\n }\n element.dispatchEvent(new MouseEvent(\"contextmenu\", init));\n}\n\n/**\n * Returns pointer handlers that, when a **touch** pointer is held still for\n * {@link LONG_PRESS_DELAY_MS}, dispatch a native `contextmenu` event on the\n * element holding them at the touch point (or, with `emulateRightClick`, a\n * right-click's `mousedown` and `contextmenu` on the pressed element).\n *\n * Dispatching the real event (rather than calling a handler directly) means the\n * element's existing `onContextMenu` — the same one a right-click triggers —\n * fires with a genuine event, so touch reuses the desktop context-menu path\n * verbatim. Mouse and pen pointers are ignored so right-click stays the desktop\n * affordance.\n *\n * After the long press fires we register a one-shot capturing `click` listener\n * on `window` to swallow the click the browser synthesizes on touch release —\n * `preventDefault()` on `pointerup` does NOT suppress that click per the Pointer\n * Events spec, so without this the element's `onClick` (navigate/select) would\n * also run.\n *\n * Pass `enabled: false` (e.g. when no context-menu handler is wired) to make the\n * returned handlers no-ops.\n */\nexport function useLongPress(\n enabled: boolean,\n options?: LongPressOptions,\n): LongPressHandlers {\n const emulateRightClick = options?.emulateRightClick === true;\n const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const originRef = useRef<{ x: number; y: number } | null>(null);\n const removeClickSuppressorRef = useRef<(() => void) | null>(null);\n\n const clearTimer = useCallback(() => {\n if (timerRef.current !== null) {\n clearTimeout(timerRef.current);\n timerRef.current = null;\n }\n originRef.current = null;\n }, []);\n\n // Swallow exactly the next click (the one the browser synthesizes from the\n // touch release after a long press) and then detach. A timeout detaches the\n // suppressor if that click never arrives, so a later genuine tap still works.\n const armClickSuppressor = useCallback(() => {\n removeClickSuppressorRef.current?.();\n\n let fallbackTimer: ReturnType<typeof setTimeout> | null = null;\n const onClickCapture = (clickEvent: MouseEvent) => {\n clickEvent.preventDefault();\n clickEvent.stopPropagation();\n removeClickSuppressorRef.current?.();\n };\n\n const remove = () => {\n window.removeEventListener(\"click\", onClickCapture, true);\n if (fallbackTimer !== null) {\n clearTimeout(fallbackTimer);\n fallbackTimer = null;\n }\n removeClickSuppressorRef.current = null;\n };\n\n removeClickSuppressorRef.current = remove;\n window.addEventListener(\"click\", onClickCapture, true);\n fallbackTimer = setTimeout(remove, SYNTHESIZED_CLICK_WINDOW_MS);\n }, []);\n\n // Tear down on unmount, and also when `enabled` flips off mid-press so a\n // scheduled long-press timer / click suppressor never fires after the hook\n // is disabled.\n useEffect(\n () => () => {\n clearTimer();\n removeClickSuppressorRef.current?.();\n },\n [clearTimer, enabled],\n );\n\n const onPointerDown = useCallback(\n (event: ReactPointerEvent<HTMLElement>) => {\n if (!enabled || event.pointerType !== \"touch\") {\n return;\n }\n\n clearTimer();\n const point = { x: event.clientX, y: event.clientY };\n originRef.current = point;\n const holder = event.currentTarget;\n const pressed =\n emulateRightClick && event.target instanceof Element\n ? event.target\n : null;\n timerRef.current = setTimeout(() => {\n timerRef.current = null;\n const element = resolvePressedElement(pressed, holder, point);\n if (element) {\n armClickSuppressor();\n deliverLongPress(element, point, emulateRightClick);\n }\n }, LONG_PRESS_DELAY_MS);\n },\n [armClickSuppressor, clearTimer, emulateRightClick, enabled],\n );\n\n const onPointerMove = useCallback(\n (event: ReactPointerEvent<HTMLElement>) => {\n const origin = originRef.current;\n if (!origin) {\n return;\n }\n\n const movedTooFar =\n Math.abs(event.clientX - origin.x) > LONG_PRESS_MOVE_TOLERANCE_PX ||\n Math.abs(event.clientY - origin.y) > LONG_PRESS_MOVE_TOLERANCE_PX;\n if (movedTooFar) {\n clearTimer();\n }\n },\n [clearTimer],\n );\n\n return {\n onPointerCancel: clearTimer,\n onPointerDown,\n onPointerMove,\n onPointerUp: clearTimer,\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tearleads/windowing",
3
- "version": "0.2.40",
3
+ "version": "0.2.42",
4
4
  "description": "App-agnostic window management for React: window state, window chrome, and the menu and sidebar primitives it renders with.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -130,7 +130,8 @@
130
130
  inset-inline: 0;
131
131
  inset-block-end: 0;
132
132
  z-index: 2;
133
- max-height: min(70vh, 32rem);
133
+ /* Tall enough for three rows of tablet tiles; shorter screens scroll. */
134
+ max-height: min(70vh, 42rem);
134
135
  overflow-y: auto;
135
136
  scrollbar-gutter: var(--scrollbar-gutter);
136
137
  padding-bottom: max(var(--space-sm), var(--safe-area-bottom));
@@ -12,6 +12,6 @@ export interface ScreensaverProviderProps {
12
12
  gracePeriodMs?: number;
13
13
  verifyPin?: ScreensaverPinVerifier | undefined;
14
14
  }
15
- declare const useScreensaver: () => ScreensaverControls;
16
- export { useScreensaver };
15
+ declare const useOptionalScreensaver: () => ScreensaverControls | null, useScreensaver: () => ScreensaverControls;
16
+ export { useOptionalScreensaver, useScreensaver };
17
17
  export declare function ScreensaverProvider({ children, screensaver: Screensaver, gracePeriodMs, verifyPin, }: ScreensaverProviderProps): import("react").JSX.Element;
@@ -4,8 +4,10 @@ import { createRequiredContext } from "../createRequiredContext.js";
4
4
  import { ScreensaverOverlay } from "./ScreensaverOverlay.js";
5
5
  import { ScreensaverUnlock } from "./ScreensaverUnlock.js";
6
6
  import { useScreensaverController } from "./useScreensaverController.js";
7
- const { context: ScreensaverContext, useRequired: useScreensaver } = createRequiredContext("useScreensaver requires ScreensaverProvider");
8
- export { useScreensaver };
7
+ const { context: ScreensaverContext, useOptional: useOptionalScreensaver, useRequired: useScreensaver, } = createRequiredContext("useScreensaver requires ScreensaverProvider");
8
+ // The optional twin lets a control that starts the screensaver hide itself
9
+ // where the host mounted no provider.
10
+ export { useOptionalScreensaver, useScreensaver };
9
11
  export function ScreensaverProvider({ children, screensaver: Screensaver, gracePeriodMs = 2000, verifyPin, }) {
10
12
  const { isActive, start, stop, state, submit, cancel, dismiss } = useScreensaverController(gracePeriodMs, verifyPin);
11
13
  const unlocking = state.status === "unlock" || state.status === "verifying";
@@ -1 +1 @@
1
- {"version":3,"file":"ScreensaverProvider.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/screensaver/ScreensaverProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsC,OAAO,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AActE,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,cAAc,EAAE,GAChE,qBAAqB,CACnB,6CAA6C,CAC9C,CAAC;AAEJ,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B,MAAM,UAAU,mBAAmB,CAAC,EAClC,QAAQ,EACR,WAAW,EAAE,WAAW,EACxB,aAAa,GAAG,IAAI,EACpB,SAAS,GACgB;IACzB,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAC7D,wBAAwB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IACrD,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,CAAC;IAC5E,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EACjC,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,CACxB,CAAC;IACF,OAAO,CACL,MAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,aACtC,QAAQ,EACR,QAAQ,IAAI,CACX,KAAC,kBAAkB,IAEjB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,KAAK,CAAC,MAAM,KAAK,IAAI,EAC7B,WAAW,EAAE,SAAS,YAErB,SAAS,CAAC,CAAC,CAAC,CACX,KAAC,iBAAiB,IAChB,IAAI,EAAE,KAAK,CAAC,MAAM,KAAK,WAAW,EAClC,KAAK,EAAE,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EACrD,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GAChB,CACH,CAAC,CAAC,CAAC,CACF,KAAC,WAAW,KAAG,CAChB,IAdI,KAAK,CAAC,OAAO,CAeC,CACtB,IAC2B,CAC/B,CAAC;AACJ,CAAC","sourcesContent":["import { type ComponentType, type ReactNode, useMemo } from \"react\";\nimport { createRequiredContext } from \"../createRequiredContext\";\nimport { ScreensaverOverlay } from \"./ScreensaverOverlay\";\nimport { ScreensaverUnlock } from \"./ScreensaverUnlock\";\nimport type { ScreensaverPinVerifier } from \"./screensaverPinVerifier\";\nimport { useScreensaverController } from \"./useScreensaverController\";\n\nexport interface ScreensaverControls {\n start: () => void;\n stop: () => void;\n /** Artwork or PIN gate is visible; false can still consume a pending release. */\n isActive: boolean;\n}\nexport interface ScreensaverProviderProps {\n children: ReactNode;\n screensaver: ComponentType;\n gracePeriodMs?: number;\n verifyPin?: ScreensaverPinVerifier | undefined;\n}\nconst { context: ScreensaverContext, useRequired: useScreensaver } =\n createRequiredContext<ScreensaverControls>(\n \"useScreensaver requires ScreensaverProvider\",\n );\n\nexport { useScreensaver };\n\nexport function ScreensaverProvider({\n children,\n screensaver: Screensaver,\n gracePeriodMs = 2000,\n verifyPin,\n}: ScreensaverProviderProps) {\n const { isActive, start, stop, state, submit, cancel, dismiss } =\n useScreensaverController(gracePeriodMs, verifyPin);\n const unlocking = state.status === \"unlock\" || state.status === \"verifying\";\n const value = useMemo(\n () => ({ start, stop, isActive }),\n [start, stop, isActive],\n );\n return (\n <ScreensaverContext.Provider value={value}>\n {children}\n {isActive && (\n <ScreensaverOverlay\n key={state.session}\n onStop={dismiss}\n locked={state.locked === true}\n interactive={unlocking}\n >\n {unlocking ? (\n <ScreensaverUnlock\n busy={state.status === \"verifying\"}\n error={state.status === \"unlock\" ? state.error : null}\n onSubmit={submit}\n onCancel={cancel}\n />\n ) : (\n <Screensaver />\n )}\n </ScreensaverOverlay>\n )}\n </ScreensaverContext.Provider>\n );\n}\n"]}
1
+ {"version":3,"file":"ScreensaverProvider.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/screensaver/ScreensaverProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsC,OAAO,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AActE,MAAM,EACJ,OAAO,EAAE,kBAAkB,EAC3B,WAAW,EAAE,sBAAsB,EACnC,WAAW,EAAE,cAAc,GAC5B,GAAG,qBAAqB,CACvB,6CAA6C,CAC9C,CAAC;AAEF,2EAA2E;AAC3E,sCAAsC;AACtC,O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Context } from \"../createRequiredContext\";\nimport { ScreensaverOverlay } from \"./ScreensaverOverlay\";\nimport { ScreensaverUnlock } from \"./ScreensaverUnlock\";\nimport type { ScreensaverPinVerifier } from \"./screensaverPinVerifier\";\nimport { useScreensaverController } from \"./useScreensaverController\";\n\nexport interface ScreensaverControls {\n start: () => void;\n stop: () => void;\n /** Artwork or PIN gate is visible; false can still consume a pending release. */\n isActive: boolean;\n}\nexport interface ScreensaverProviderProps {\n children: ReactNode;\n screensaver: ComponentType;\n gracePeriodMs?: number;\n verifyPin?: ScreensaverPinVerifier | undefined;\n}\nconst {\n context: ScreensaverContext,\n useOptional: useOptionalScreensaver,\n useRequired: useScreensaver,\n} = createRequiredContext<ScreensaverControls>(\n \"useScreensaver requires ScreensaverProvider\",\n);\n\n// The optional twin lets a control that starts the screensaver hide itself\n// where the host mounted no provider.\nexport { useOptionalScreensaver, useScreensaver };\n\nexport function ScreensaverProvider({\n children,\n screensaver: Screensaver,\n gracePeriodMs = 2000,\n verifyPin,\n}: ScreensaverProviderProps) {\n const { isActive, start, stop, state, submit, cancel, dismiss } =\n useScreensaverController(gracePeriodMs, verifyPin);\n const unlocking = state.status === \"unlock\" || state.status === \"verifying\";\n const value = useMemo(\n () => ({ start, stop, isActive }),\n [start, stop, isActive],\n );\n return (\n <ScreensaverContext.Provider value={value}>\n {children}\n {isActive && (\n <ScreensaverOverlay\n key={state.session}\n onStop={dismiss}\n locked={state.locked === true}\n interactive={unlocking}\n >\n {unlocking ? (\n <ScreensaverUnlock\n busy={state.status === \"verifying\"}\n error={state.status === \"unlock\" ? state.error : null}\n onSubmit={submit}\n onCancel={cancel}\n />\n ) : (\n <Screensaver />\n )}\n </ScreensaverOverlay>\n )}\n </ScreensaverContext.Provider>\n );\n}\n"]}
@@ -0,0 +1,20 @@
1
+ /* The system tray: its apps in a row, as the taskbar's other controls. */
2
+ .system-tray {
3
+ display: flex;
4
+ flex: 0 0 auto;
5
+ align-items: center;
6
+ gap: var(--space-xs);
7
+ margin: 0;
8
+ padding: 0;
9
+ list-style: none;
10
+ }
11
+
12
+ .system-tray-app {
13
+ display: flex;
14
+ align-items: center;
15
+ }
16
+
17
+ /* A tray app that renders nothing where it does not apply takes no gap. */
18
+ .system-tray-app:empty {
19
+ display: none;
20
+ }
@@ -0,0 +1,23 @@
1
+ import type { WindowingIcon } from "../icons/windowingIcon.js";
2
+ /** An item a host adds to every tray app's context menu, below Disable. */
3
+ export interface SystemTrayMenuItem {
4
+ icon?: WindowingIcon | undefined;
5
+ id: string;
6
+ label: string;
7
+ onSelect: () => void;
8
+ }
9
+ interface SystemTrayProps {
10
+ /**
11
+ * Items below "Disable <app>" in each tray app's context menu, such as one
12
+ * that opens the host's Display Properties to turn apps back on.
13
+ */
14
+ menuItems?: ReadonlyArray<SystemTrayMenuItem> | undefined;
15
+ }
16
+ /**
17
+ * The tray apps of the nearest {@link SystemTrayProvider} that the user left
18
+ * on, in order, for a taskbar's corner. Right-clicking one, pressing the
19
+ * context-menu key on it, or holding a finger on it opens its menu: Disable,
20
+ * then the host's `menuItems`. It renders nothing outside a provider.
21
+ */
22
+ export declare function SystemTray({ menuItems }: SystemTrayProps): import("react").JSX.Element | null;
23
+ export {};
@@ -0,0 +1,54 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { createElement as _createElement } from "react";
3
+ import { Menu } from "../menu/Menu.js";
4
+ import { MenuItem } from "../menu/MenuItem.js";
5
+ import { useContextMenuState } from "../menu/useContextMenuState.js";
6
+ import { useLongPress } from "../menu/useLongPress.js";
7
+ import { useOptionalSystemTray } from "./SystemTrayProvider.js";
8
+ import "./SystemTray.css";
9
+ const NO_MENU_ITEMS = [];
10
+ // An app's portaled content, such as its own popover, bubbles to its tray
11
+ // slot through React though it sits elsewhere in the page. Only presses on
12
+ // what the slot actually contains open the tray's menu.
13
+ function isInSlot(event) {
14
+ return (event.target instanceof Node && event.currentTarget.contains(event.target));
15
+ }
16
+ /**
17
+ * The tray apps of the nearest {@link SystemTrayProvider} that the user left
18
+ * on, in order, for a taskbar's corner. Right-clicking one, pressing the
19
+ * context-menu key on it, or holding a finger on it opens its menu: Disable,
20
+ * then the host's `menuItems`. It renders nothing outside a provider.
21
+ */
22
+ export function SystemTray({ menuItems = NO_MENU_ITEMS }) {
23
+ const tray = useOptionalSystemTray();
24
+ const { closeContextMenu, contextMenu, openContextMenu } = useContextMenuState();
25
+ // A long press arrives as a right-click would: other open menus close on
26
+ // its press, and the pressed control sees it first, so an app can close its
27
+ // own popover before the tray's menu opens.
28
+ const longPress = useLongPress(true, { emulateRightClick: true });
29
+ if (!tray) {
30
+ return null;
31
+ }
32
+ const { definition, isEnabled, setEnabled } = tray;
33
+ const menuApp = contextMenu ? definition.apps[contextMenu.id] : undefined;
34
+ return (_jsxs(_Fragment, { children: [_jsx("ul", { "aria-label": "System tray", className: "system-tray", children: definition.order.filter(isEnabled).map((id) => {
35
+ const TrayApp = definition.apps[id]?.component;
36
+ return (TrayApp && (_createElement("li", { ...longPress, className: "system-tray-app", key: id, onContextMenu: (event) => {
37
+ if (isInSlot(event)) {
38
+ openContextMenu(event, id);
39
+ }
40
+ }, onPointerDown: (event) => {
41
+ if (isInSlot(event)) {
42
+ longPress.onPointerDown(event);
43
+ }
44
+ } },
45
+ _jsx(TrayApp, {}))));
46
+ }) }), contextMenu && menuApp && (_jsxs(Menu, { onClose: closeContextMenu, position: contextMenu.position, children: [_jsx(MenuItem, { icon: menuApp.icon, label: `Disable ${menuApp.title}`, onClick: () => {
47
+ closeContextMenu();
48
+ setEnabled(contextMenu.id, false);
49
+ } }), menuItems.map((item) => (_jsx(MenuItem, { icon: item.icon, label: item.label, onClick: () => {
50
+ closeContextMenu();
51
+ item.onSelect();
52
+ } }, item.id)))] }))] }));
53
+ }
54
+ //# sourceMappingURL=SystemTray.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SystemTray.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/wind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ACZ,gBAAgB,EAAE,CAAC;4BACnB,IAAI,CAAC,QAAQ,EAAE,CAAC;wBAClB,CAAC,IALI,IAAI,CAAC,EAAE,CAMZ,CACH,CAAC,IACG,CACR,IACA,CACJ,CAAC;AACJ,CAAC","sourcesContent":["import type { SyntheticEvent } from \"react\";\nimport type { WindowingIcon } from \"../icons/windowingIcon\";\nimport { Menu } from \"../menu/Menu\";\nimport { MenuItem } from \"../menu/MenuItem\";\nimport { useContextMenuState } from \"../menu/useContextMenuState\";\nimport { useLongPress } from \"../menu/useLongPress\";\nimport { useOptionalSystemTray } from \"./SystemTrayProvider\";\nimport \"./SystemTray.css\";\n\n/** An item a host adds to every tray app's context menu, below Disable. */\nexport interface SystemTrayMenuItem {\n icon?: WindowingIcon | undefined;\n id: string;\n label: string;\n onSelect: () => void;\n}\n\ninterface SystemTrayProps {\n /**\n * Items below \"Disable <app>\" in each tray app's context menu, such as one\n * that opens the host's Display Properties to turn apps back on.\n */\n menuItems?: ReadonlyArray<SystemTrayMenuItem> | undefined;\n}\n\nconst NO_MENU_ITEMS: ReadonlyArray<SystemTrayMenuItem> = [];\n\n// An app's portaled content, such as its own popover, bubbles to its tray\n// slot through React though it sits elsewhere in the page. Only presses on\n// what the slot actually contains open the tray's menu.\nfunction isInSlot(event: SyntheticEvent<HTMLElement>): boolean {\n return (\n event.target instanceof Node && event.currentTarget.contains(event.target)\n );\n}\n\n/**\n * The tray apps of the nearest {@link SystemTrayProvider} that the user left\n * on, in order, for a taskbar's corner. Right-clicking one, pressing the\n * context-menu key on it, or holding a finger on it opens its menu: Disable,\n * then the host's `menuItems`. It renders nothing outside a provider.\n */\nexport function SystemTray({ menuItems = NO_MENU_ITEMS }: SystemTrayProps) {\n const tray = useOptionalSystemTray();\n const { closeContextMenu, contextMenu, openContextMenu } =\n useContextMenuState();\n // A long press arrives as a right-click would: other open menus close on\n // its press, and the pressed control sees it first, so an app can close its\n // own popover before the tray's menu opens.\n const longPress = useLongPress(true, { emulateRightClick: true });\n if (!tray) {\n return null;\n }\n\n const { definition, isEnabled, setEnabled } = tray;\n const menuApp = contextMenu ? definition.apps[contextMenu.id] : undefined;\n\n return (\n <>\n <ul aria-label=\"System tray\" className=\"system-tray\">\n {definition.order.filter(isEnabled).map((id) => {\n const TrayApp = definition.apps[id]?.component;\n return (\n TrayApp && (\n <li\n {...longPress}\n className=\"system-tray-app\"\n key={id}\n onContextMenu={(event) => {\n if (isInSlot(event)) {\n openContextMenu(event, id);\n }\n }}\n onPointerDown={(event) => {\n if (isInSlot(event)) {\n longPress.onPointerDown(event);\n }\n }}\n >\n <TrayApp />\n </li>\n )\n );\n })}\n </ul>\n {contextMenu && menuApp && (\n <Menu onClose={closeContextMenu} position={contextMenu.position}>\n <MenuItem\n icon={menuApp.icon}\n label={`Disable ${menuApp.title}`}\n onClick={() => {\n closeContextMenu();\n setEnabled(contextMenu.id, false);\n }}\n />\n {menuItems.map((item) => (\n <MenuItem\n icon={item.icon}\n key={item.id}\n label={item.label}\n onClick={() => {\n closeContextMenu();\n item.onSelect();\n }}\n />\n ))}\n </Menu>\n )}\n </>\n );\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { type PropsWithChildren } from "react";
2
+ import type { SystemTrayDefinition } from "./systemTrayDefinition.js";
3
+ interface SystemTrayContextValue {
4
+ /** The host's tray apps, in tray order. */
5
+ definition: SystemTrayDefinition;
6
+ /** Whether the user has left the app on; every app starts on. */
7
+ isEnabled: (id: string) => boolean;
8
+ /** Turns one of the host's apps on or off, and persists the choice. */
9
+ setEnabled: (id: string, enabled: boolean) => void;
10
+ }
11
+ interface SystemTrayProviderProps<Id extends string> extends PropsWithChildren {
12
+ /** The host's tray apps. Define it once, outside render. */
13
+ definition: SystemTrayDefinition<Id>;
14
+ /** Where the apps the user turned off persist in localStorage. */
15
+ storageKey: string;
16
+ }
17
+ /**
18
+ * Owns the system tray: the host's tray apps and which of them the user turned
19
+ * off. {@link SystemTray} shows the ones left on, each with a context menu that
20
+ * turns it off, and Display Properties lists every one with a switch. Mount one
21
+ * above every taskbar that shares the choice.
22
+ */
23
+ export declare function SystemTrayProvider<Id extends string>({ children, definition, storageKey, }: SystemTrayProviderProps<Id>): import("react").JSX.Element;
24
+ export declare const useSystemTray: () => SystemTrayContextValue;
25
+ export declare const useOptionalSystemTray: () => SystemTrayContextValue | null;
26
+ export {};
@@ -0,0 +1,62 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
3
+ import { createRequiredContext } from "../createRequiredContext.js";
4
+ import { loadStoredPreference, saveStoredPreference, } from "../launcher/storedPreference.js";
5
+ const systemTrayContext = createRequiredContext("useSystemTray must be used within a SystemTrayProvider");
6
+ const NONE_DISABLED = new Set();
7
+ // The stored value is a JSON array of the ids the user turned off. Storing the
8
+ // off set rather than the on set lets a tray app the host adds later show up.
9
+ function parseDisabledAppIds(stored) {
10
+ if (stored === null) {
11
+ return NONE_DISABLED;
12
+ }
13
+ const parsed = JSON.parse(stored);
14
+ return Array.isArray(parsed)
15
+ ? new Set(parsed.filter((id) => typeof id === "string"))
16
+ : NONE_DISABLED;
17
+ }
18
+ /**
19
+ * Owns the system tray: the host's tray apps and which of them the user turned
20
+ * off. {@link SystemTray} shows the ones left on, each with a context menu that
21
+ * turns it off, and Display Properties lists every one with a switch. Mount one
22
+ * above every taskbar that shares the choice.
23
+ */
24
+ export function SystemTrayProvider({ children, definition, storageKey, }) {
25
+ const [disabledAppIds, setDisabledAppIds] = useState(() => loadStoredPreference(storageKey, parseDisabledAppIds));
26
+ // Persist only what the user changed, after the change commits, so several
27
+ // calls in one event (turning every app back on) all land.
28
+ const persistedAppIds = useRef(disabledAppIds);
29
+ useEffect(() => {
30
+ if (persistedAppIds.current === disabledAppIds) {
31
+ return;
32
+ }
33
+ persistedAppIds.current = disabledAppIds;
34
+ saveStoredPreference(storageKey, JSON.stringify([...disabledAppIds]));
35
+ }, [disabledAppIds, storageKey]);
36
+ const isEnabled = useCallback((id) => !disabledAppIds.has(id), [disabledAppIds]);
37
+ const setEnabled = useCallback((id, enabled) => {
38
+ if (!Object.hasOwn(definition.apps, id)) {
39
+ return;
40
+ }
41
+ setDisabledAppIds((current) => {
42
+ if (current.has(id) !== enabled) {
43
+ return current;
44
+ }
45
+ const next = new Set(current);
46
+ if (enabled) {
47
+ next.delete(id);
48
+ }
49
+ else {
50
+ next.add(id);
51
+ }
52
+ return next;
53
+ });
54
+ }, [definition.apps]);
55
+ const value = useMemo(() => ({ definition, isEnabled, setEnabled }), [definition, isEnabled, setEnabled]);
56
+ return (_jsx(systemTrayContext.context.Provider, { value: value, children: children }));
57
+ }
58
+ export const useSystemTray = systemTrayContext.useRequired;
59
+ // Non-throwing accessor: without a provider the tray shows nothing, and Display
60
+ // Properties leaves out its System Tray section.
61
+ export const useOptionalSystemTray = systemTrayContext.useOptional;
62
+ //# sourceMappingURL=SystemTrayProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SystemTrayProvider.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/tray/SystemTrayProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEL,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,8BAA8B,CAAC;AAYtC,MAAM,iBAAiB,GAAG,qBAAqB,CAC7C,wDAAwD,CACzD,CAAC;AAEF,MAAM,aAAa,GAAwB,IAAI,GAAG,EAAE,CAAC;AAErD,+EAA+E;AAC/E,8EAA8E;AAC9E,SAAS,mBAAmB,CAAC,MAAqB;IAChD,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,aAAa,CAAC;IACvB,CAAC;IACD,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC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,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,OAAO,EAAE,CAAC;gBAChC,OAAO,OAAO,CAAC;YACjB,CAAC;YACD,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;YAC9B,IAAI,OAAO,EAAE,CAAC;gBACZ,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAClB,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACf,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,EACD,CAAC,UAAU,CAAC,IAAI,CAAC,CAClB,CAAC;IAEF,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,EAC7C,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,CAAC,CACpC,CAAC;IAEF,OAAO,CACL,KAAC,iBAAiB,CAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAC7C,QAAQ,GAC0B,CACtC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC,WAAW,CAAC;AAE3D,gFAAgF;AAChF,iDAAiD;AACjD,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,WAAW,CAAC","sourcesContent":["import {\n type PropsWithChildren,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createRequiredContext } from \"../createRequiredContext\";\nimport {\n loadStoredPreference,\n saveStoredPreference,\n} from \"../launcher/storedPreference\";\nimport type { SystemTrayDefinition } from \"./systemTrayDefinition\";\n\ninterface SystemTrayContextValue {\n /** The host's tray apps, in tray order. */\n definition: SystemTrayDefinition;\n /** Whether the user has left the app on; every app starts on. */\n isEnabled: (id: string) => boolean;\n /** Turns one of the host's apps on or off, and persists the choice. */\n setEnabled: (id: string, enabled: boolean) => void;\n}\n\nconst systemTrayContext = createRequiredContext<SystemTrayContextValue>(\n \"useSystemTray must be used within a SystemTrayProvider\",\n);\n\nconst NONE_DISABLED: ReadonlySet<string> = new Set();\n\n// The stored value is a JSON array of the ids the user turned off. Storing the\n// off set rather than the on set lets a tray app the host adds later show up.\nfunction parseDisabledAppIds(stored: string | null): ReadonlySet<string> {\n if (stored === null) {\n return NONE_DISABLED;\n }\n const parsed: unknown = JSON.parse(stored);\n return Array.isArray(parsed)\n ? new Set(parsed.filter((id): id is string => typeof id === \"string\"))\n : NONE_DISABLED;\n}\n\ninterface SystemTrayProviderProps<Id extends string> extends PropsWithChildren {\n /** The host's tray apps. Define it once, outside render. */\n definition: SystemTrayDefinition<Id>;\n /** Where the apps the user turned off persist in localStorage. */\n storageKey: string;\n}\n\n/**\n * Owns the system tray: the host's tray apps and which of them the user turned\n * off. {@link SystemTray} shows the ones left on, each with a context menu that\n * turns it off, and Display Properties lists every one with a switch. Mount one\n * above every taskbar that shares the choice.\n */\nexport function SystemTrayProvider<Id extends string>({\n children,\n definition,\n storageKey,\n}: SystemTrayProviderProps<Id>) {\n const [disabledAppIds, setDisabledAppIds] = useState(() =>\n loadStoredPreference(storageKey, parseDisabledAppIds),\n );\n\n // Persist only what the user changed, after the change commits, so several\n // calls in one event (turning every app back on) all land.\n const persistedAppIds = useRef(disabledAppIds);\n useEffect(() => {\n if (persistedAppIds.current === disabledAppIds) {\n return;\n }\n persistedAppIds.current = disabledAppIds;\n saveStoredPreference(storageKey, JSON.stringify([...disabledAppIds]));\n }, [disabledAppIds, storageKey]);\n\n const isEnabled = useCallback(\n (id: string) => !disabledAppIds.has(id),\n [disabledAppIds],\n );\n\n const setEnabled = useCallback(\n (id: string, enabled: boolean) => {\n if (!Object.hasOwn(definition.apps, id)) {\n return;\n }\n setDisabledAppIds((current) => {\n if (current.has(id) !== enabled) {\n return current;\n }\n const next = new Set(current);\n if (enabled) {\n next.delete(id);\n } else {\n next.add(id);\n }\n return next;\n });\n },\n [definition.apps],\n );\n\n const value = useMemo<SystemTrayContextValue>(\n () => ({ definition, isEnabled, setEnabled }),\n [definition, isEnabled, setEnabled],\n );\n\n return (\n <systemTrayContext.context.Provider value={value}>\n {children}\n </systemTrayContext.context.Provider>\n );\n}\n\nexport const useSystemTray = systemTrayContext.useRequired;\n\n// Non-throwing accessor: without a provider the tray shows nothing, and Display\n// Properties leaves out its System Tray section.\nexport const useOptionalSystemTray = systemTrayContext.useOptional;\n"]}
@@ -0,0 +1,19 @@
1
+ import type { ComponentType } from "react";
2
+ import type { WindowingIcon } from "../icons/windowingIcon.js";
3
+ /**
4
+ * One tray app: a small control a host shows in its taskbar's tray, such as a
5
+ * theme switch or a status indicator, which the user can turn off.
6
+ */
7
+ export interface TrayAppDefinition {
8
+ /** The control. It may render nothing where it does not apply. */
9
+ component: ComponentType;
10
+ /** Drawn beside the title in Display Properties and the app's menu. */
11
+ icon?: WindowingIcon | undefined;
12
+ /** Names the app in Display Properties and its context menu. */
13
+ title: string;
14
+ }
15
+ /** A host's tray apps and their order in the tray, start to end. */
16
+ export interface SystemTrayDefinition<Id extends string = string> {
17
+ apps: Readonly<Record<Id, TrayAppDefinition>>;
18
+ order: ReadonlyArray<Id>;
19
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=systemTrayDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"systemTrayDefinition.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/tray/systemTrayDefinition.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentType } from \"react\";\nimport type { WindowingIcon } from \"../icons/windowingIcon\";\n\n/**\n * One tray app: a small control a host shows in its taskbar's tray, such as a\n * theme switch or a status indicator, which the user can turn off.\n */\nexport interface TrayAppDefinition {\n /** The control. It may render nothing where it does not apply. */\n component: ComponentType;\n /** Drawn beside the title in Display Properties and the app's menu. */\n icon?: WindowingIcon | undefined;\n /** Names the app in Display Properties and its context menu. */\n title: string;\n}\n\n/** A host's tray apps and their order in the tray, start to end. */\nexport interface SystemTrayDefinition<Id extends string = string> {\n apps: Readonly<Record<Id, TrayAppDefinition>>;\n order: ReadonlyArray<Id>;\n}\n"]}
@@ -1,15 +0,0 @@
1
- import { type LauncherDefinition } from "./launcherDefinition.js";
2
- import type { NavigationMode } from "./navigationMode.js";
3
- /**
4
- * Opens the host's default windows, in order so the last is in front, once
5
- * per entry into an empty windowed desktop.
6
- */
7
- export declare function useDefaultWindow({ definition, enabled, mode, openMiniApp, windowCount, }: {
8
- definition: LauncherDefinition;
9
- enabled: boolean;
10
- mode: NavigationMode;
11
- openMiniApp: (request: {
12
- appId: string;
13
- }) => string | null;
14
- windowCount: number;
15
- }): void;