@tearleads/windowing 0.2.46 → 0.2.48

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.
@@ -120,9 +120,9 @@ desktop's context menu.
120
120
 
121
121
  A host's tray apps are the small controls in its taskbar's corner, such as
122
122
  `ThemeSwitch` or a sync status button. A `SystemTrayDefinition` lists them as
123
- `{ title, icon?, component }` by id, with their order. `SystemTrayProvider`
124
- takes the definition and a `storageKey` under which the apps the user turned
125
- off persist, so every app starts on and one the host adds later appears.
123
+ `{ title, icon?, component, defaultEnabled? }` by id, with their order. Set
124
+ `defaultEnabled: false` for an opt-in app. Other apps start on.
125
+ `SystemTrayProvider` persists the user’s visibility choices under `storageKey`.
126
126
  Render `SystemTray` in the taskbar's corner:
127
127
 
128
128
  ```tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tearleads/windowing",
3
- "version": "0.2.46",
3
+ "version": "0.2.48",
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": {
@@ -359,8 +359,10 @@
359
359
  cursor: pointer;
360
360
  }
361
361
 
362
- .routed-pane-taskbar-menu-button:focus-visible,
363
- .routed-pane-taskbar-menu-button[aria-expanded="true"] {
362
+ /* Only keyboard focus fills the button. Open is not marked: the launcher sheet
363
+ covers the button while it is open, and in tablet side mode the expanded
364
+ rail already shows the state, where a lasting fill read as a focus ring. */
365
+ .routed-pane-taskbar-menu-button:focus-visible {
364
366
  background: var(--emphasis-surface);
365
367
  color: var(--emphasis-text);
366
368
  }
@@ -3,7 +3,7 @@ import type { SystemTrayDefinition } from "./systemTrayDefinition.js";
3
3
  interface SystemTrayContextValue {
4
4
  /** The host's tray apps, in tray order. */
5
5
  definition: SystemTrayDefinition;
6
- /** Whether the user has left the app on; every app starts on. */
6
+ /** Whether the app is visible with the user's preferences applied. */
7
7
  isEnabled: (id: string) => boolean;
8
8
  /** Turns one of the host's apps on or off, and persists the choice. */
9
9
  setEnabled: (id: string, enabled: boolean) => void;
@@ -11,12 +11,12 @@ interface SystemTrayContextValue {
11
11
  interface SystemTrayProviderProps<Id extends string> extends PropsWithChildren {
12
12
  /** The host's tray apps. Define it once, outside render. */
13
13
  definition: SystemTrayDefinition<Id>;
14
- /** Where the apps the user turned off persist in localStorage. */
14
+ /** Where tray visibility preferences persist in localStorage. */
15
15
  storageKey: string;
16
16
  }
17
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
18
+ * Applies saved visibility choices to the host’s tray defaults.
19
+ * {@link SystemTray} shows the enabled apps, each with a context menu that
20
20
  * turns it off, and Display Properties lists every one with a switch. Mount one
21
21
  * above every taskbar that shares the choice.
22
22
  */
@@ -3,55 +3,61 @@ import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
3
3
  import { createRequiredContext } from "../createRequiredContext.js";
4
4
  import { loadStoredPreference, saveStoredPreference, } from "../launcher/storedPreference.js";
5
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;
6
+ function parseVisibility(stored) {
7
+ const parsed = stored === null ? null : JSON.parse(stored);
8
+ const preferences = new Map();
9
+ if (Array.isArray(parsed)) {
10
+ const entries = parsed;
11
+ for (const entry of entries) {
12
+ if (typeof entry === "string") {
13
+ preferences.set(entry, false);
14
+ }
15
+ else if (typeof entry === "object" &&
16
+ entry !== null &&
17
+ "enabled" in entry &&
18
+ typeof entry.enabled === "string") {
19
+ preferences.set(entry.enabled, true);
20
+ }
21
+ }
12
22
  }
13
- const parsed = JSON.parse(stored);
14
- return Array.isArray(parsed)
15
- ? new Set(parsed.filter((id) => typeof id === "string"))
16
- : NONE_DISABLED;
23
+ return preferences;
17
24
  }
18
25
  /**
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
26
+ * Applies saved visibility choices to the host’s tray defaults.
27
+ * {@link SystemTray} shows the enabled apps, each with a context menu that
21
28
  * turns it off, and Display Properties lists every one with a switch. Mount one
22
29
  * above every taskbar that shares the choice.
23
30
  */
24
31
  export function SystemTrayProvider({ children, definition, storageKey, }) {
25
- const [disabledAppIds, setDisabledAppIds] = useState(() => loadStoredPreference(storageKey, parseDisabledAppIds));
32
+ const [visibility, setVisibility] = useState(() => loadStoredPreference(storageKey, parseVisibility));
26
33
  // Persist only what the user changed, after the change commits, so several
27
34
  // calls in one event (turning every app back on) all land.
28
- const persistedAppIds = useRef(disabledAppIds);
35
+ const persistedVisibility = useRef(visibility);
29
36
  useEffect(() => {
30
- if (persistedAppIds.current === disabledAppIds) {
37
+ if (persistedVisibility.current === visibility) {
31
38
  return;
32
39
  }
33
- persistedAppIds.current = disabledAppIds;
34
- saveStoredPreference(storageKey, JSON.stringify([...disabledAppIds]));
35
- }, [disabledAppIds, storageKey]);
36
- const isEnabled = useCallback((id) => !disabledAppIds.has(id), [disabledAppIds]);
40
+ persistedVisibility.current = visibility;
41
+ saveStoredPreference(storageKey,
42
+ // Older builds read the disabled ids and skip the opt-in records.
43
+ JSON.stringify(Array.from(visibility, ([id, enabled]) => enabled ? { enabled: id } : id)));
44
+ }, [visibility, storageKey]);
45
+ const apps = definition.apps;
46
+ const defaultEnabled = useCallback((id) => apps[id]?.defaultEnabled ?? true, [apps]);
47
+ const isEnabled = useCallback((id) => visibility.get(id) ?? defaultEnabled(id), [visibility, defaultEnabled]);
37
48
  const setEnabled = useCallback((id, enabled) => {
38
49
  if (!Object.hasOwn(definition.apps, id)) {
39
50
  return;
40
51
  }
41
- setDisabledAppIds((current) => {
42
- if (current.has(id) !== enabled) {
52
+ setVisibility((current) => {
53
+ if ((current.get(id) ?? defaultEnabled(id)) === enabled) {
43
54
  return current;
44
55
  }
45
- const next = new Set(current);
46
- if (enabled) {
47
- next.delete(id);
48
- }
49
- else {
50
- next.add(id);
51
- }
56
+ const next = new Map(current);
57
+ next.set(id, enabled);
52
58
  return next;
53
59
  });
54
- }, [definition.apps]);
60
+ }, [definition.apps, defaultEnabled]);
55
61
  const value = useMemo(() => ({ definition, isEnabled, setEnabled }), [definition, isEnabled, setEnabled]);
56
62
  return (_jsx(systemTrayContext.context.Provider, { value: value, children: children }));
57
63
  }
@@ -1 +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;IAC3C,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAC1B,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,EAAgB,EAAE,CAAC,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC;QACtE,CAAC,CAAC,aAAa,CAAC;AACpB,CAAC;AASD;;;;;GAKG;AACH,MAA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AC;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"]}
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,SAAS,eAAe,CAAC,MAAqB;IAC5C,MAAM,MAAM,GAAY,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACpE,MAAM,WAAW,GAAG,IAAI,GAAG,EAAmB,CAAC;IAC/C,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,MAAM,OAAO,GAAuB,MAAM,CAAC;QAC3C,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAChC,CAAC;iBAAM,IACL,OAAO,KAAK,KAAK,QAAQ;gBACzB,KAAK,KAAK,IAAI;gBACd,SAAS,IAAI,KAAK;gBAClB,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,EACjC,CAAC;gBACD,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AASD;;;;;GAK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/B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;YACxC,OAAO;QACT,CAAC;QACD,aAAa,CAAC,CAAC,OAAO,EAAE,EAAE;YACxB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,cAAc,CAAC,EAAE,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;gBACxD,OAAO,OAAO,CAAC;YACjB,CAAC;YACD,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;YAC9B,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;YACtB,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,EACD,CAAC,UAAU,CAAC,IAAI,EAAE,cAAc,CAAC,CAClC,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 app is visible with the user's preferences applied. */\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\nfunction parseVisibility(stored: string | null): ReadonlyMap<string, boolean> {\n const parsed: unknown = stored === null ? null : JSON.parse(stored);\n const preferences = new Map<string, boolean>();\n if (Array.isArray(parsed)) {\n const entries: readonly unknown[] = parsed;\n for (const entry of entries) {\n if (typeof entry === \"string\") {\n preferences.set(entry, false);\n } else if (\n typeof entry === \"object\" &&\n entry !== null &&\n \"enabled\" in entry &&\n typeof entry.enabled === \"string\"\n ) {\n preferences.set(entry.enabled, true);\n }\n }\n }\n return preferences;\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 tray visibility preferences persist in localStorage. */\n storageKey: string;\n}\n\n/**\n * Applies saved visibility choices to the host’s tray defaults.\n * {@link SystemTray} shows the enabled apps, 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 [visibility, setVisibility] = useState(() =>\n loadStoredPreference(storageKey, parseVisibility),\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 persistedVisibility = useRef(visibility);\n useEffect(() => {\n if (persistedVisibility.current === visibility) {\n return;\n }\n persistedVisibility.current = visibility;\n saveStoredPreference(\n storageKey,\n // Older builds read the disabled ids and skip the opt-in records.\n JSON.stringify(\n Array.from(visibility, ([id, enabled]) =>\n enabled ? { enabled: id } : id,\n ),\n ),\n );\n }, [visibility, storageKey]);\n\n const apps: SystemTrayDefinition[\"apps\"] = definition.apps;\n const defaultEnabled = useCallback(\n (id: string) => apps[id]?.defaultEnabled ?? true,\n [apps],\n );\n\n const isEnabled = useCallback(\n (id: string) => visibility.get(id) ?? defaultEnabled(id),\n [visibility, defaultEnabled],\n );\n\n const setEnabled = useCallback(\n (id: string, enabled: boolean) => {\n if (!Object.hasOwn(definition.apps, id)) {\n return;\n }\n setVisibility((current) => {\n if ((current.get(id) ?? defaultEnabled(id)) === enabled) {\n return current;\n }\n const next = new Map(current);\n next.set(id, enabled);\n return next;\n });\n },\n [definition.apps, defaultEnabled],\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"]}
@@ -7,6 +7,8 @@ import type { WindowingIcon } from "../icons/windowingIcon.js";
7
7
  export interface TrayAppDefinition {
8
8
  /** The control. It may render nothing where it does not apply. */
9
9
  component: ComponentType;
10
+ /** Whether the control appears before the user chooses. Defaults to true. */
11
+ defaultEnabled?: boolean;
10
12
  /** Drawn beside the title in Display Properties and the app's menu. */
11
13
  icon?: WindowingIcon | undefined;
12
14
  /** Names the app in Display Properties and its context menu. */
@@ -1 +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
+ {"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 /** Whether the control appears before the user chooses. Defaults to true. */\n defaultEnabled?: boolean;\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"]}