@fungi.computer/tourtois 0.10.0 → 0.11.0

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.
@@ -1,4 +1,4 @@
1
- import type { AgentAccessOperation, AppPermissionOutcome, ComputerAccessOperation } from "@fungi.computer/agar";
1
+ import type { AgentAccessOperation, AppPermissionOutcome, AppPermissionRequest, ComputerAccessOperation } from "@fungi.computer/agar";
2
2
  import type { AppAgentPermission, AppComputerPermission } from "@fungi.computer/nacre/app-directory";
3
3
  export declare const consentableAgentOperations: (requested: readonly AgentAccessOperation[], declared: readonly string[]) => readonly AgentAccessOperation[];
4
4
  export declare const consentableComputerOperations: (requested: readonly ComputerAccessOperation[], declared: readonly string[]) => readonly ComputerAccessOperation[];
@@ -9,10 +9,18 @@ export declare function consentedAgentPermission(current: AppAgentPermission, of
9
9
  * access; a real Computer selection is the owner's choice and never widened.
10
10
  */
11
11
  export declare function consentedComputerPermission(current: AppComputerPermission | null, offered: readonly ComputerAccessOperation[]): AppComputerPermission | "covered" | "customize";
12
+ /** Every right the request names, in plain words, in a stable order. */
13
+ export declare function plainRights(request: {
14
+ agents: readonly AgentAccessOperation[];
15
+ computers: readonly ComputerAccessOperation[];
16
+ others?: AppPermissionRequest | undefined;
17
+ }): readonly string[];
12
18
  export type AppAccessRequest = Readonly<{
13
19
  appName: string;
14
20
  agents: readonly AgentAccessOperation[];
15
21
  computers: readonly ComputerAccessOperation[];
22
+ /** Git, Workflow, event and generation rights asked for in the same request. */
23
+ others?: AppPermissionRequest | undefined;
16
24
  /** A host refusal is visible and cannot be converted into an Allow. */
17
25
  refusal?: Readonly<{
18
26
  code: string;
@@ -22,7 +30,7 @@ export type AppAccessRequest = Readonly<{
22
30
  allow: () => Promise<boolean>;
23
31
  settle: (outcome: AppPermissionOutcome) => void;
24
32
  }>;
25
- /** One-click host consent for the rights a default App declared. */
33
+ /** One-click host consent: one sheet listing every right in plain words. */
26
34
  export declare function AppAccessConsent({ request, }: {
27
35
  request: AppAccessRequest | null;
28
36
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Button } from "@fungi.computer/caps/components/button";
3
3
  import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogTitle, } from "@fungi.computer/caps/components/dialog";
4
- import { WindowFrame, WindowHeader, } from "@fungi.computer/caps/components/window";
5
- import { useState } from "react";
4
+ import { WindowFrame } from "@fungi.computer/caps/components/window";
5
+ import { useRef, useState } from "react";
6
6
  const directoryOperations = ["agent.list"];
7
7
  const sessionOperations = ["agent.read", "agent.send", "agent.manage"];
8
8
  const agentOperations = [
@@ -67,25 +67,42 @@ const rightNames = {
67
67
  "computer.writeFile": "change their files",
68
68
  "computer.execute": "run commands on them",
69
69
  };
70
- const describe = (offered) => {
71
- const rights = [...agentOperations, ...computerOperations]
72
- .filter((operation) => offered.includes(operation))
73
- .map((operation) => rightNames[operation]);
74
- const last = rights.at(-1) ?? "";
75
- return rights.length < 2
76
- ? last
77
- : `${rights.slice(0, -1).join(", ")} and ${last}`;
70
+ /** Plain words for the Git, Workflow, event and generation rights. */
71
+ const otherRightNames = {
72
+ "git.repository": "save its work in Git repositories",
73
+ "workflow.publish": "publish workflows",
74
+ "workflow.arm": "let workflows start on their own",
75
+ "workflow.run": "run workflows",
76
+ "app.events.emit": "send events to your other Apps",
77
+ "llm.generation": "write with an AI model",
78
+ "media.generation": "make images and videos",
79
+ "media.share": "share what it makes",
78
80
  };
79
- const resources = (request, agent, computer) => [
80
- request.agents.length > 0 ? agent : null,
81
- request.computers.length > 0 ? computer : null,
82
- ]
83
- .filter((resource) => resource !== null)
84
- .join(" and ");
85
- /** One-click host consent for the rights a default App declared. */
81
+ /** Every right the request names, in plain words, in a stable order. */
82
+ export function plainRights(request) {
83
+ const others = request.others;
84
+ const named = [
85
+ ...(others?.git ?? []),
86
+ ...(others?.workflows ?? []),
87
+ ...(others?.events ?? []),
88
+ ...(others?.generation ?? []),
89
+ ];
90
+ const agentRights = agentOperations
91
+ .filter((operation) => request.agents.includes(operation))
92
+ .map((operation) => rightNames[operation]);
93
+ const computerRights = computerOperations
94
+ .filter((operation) => request.computers.includes(operation))
95
+ .map((operation) => rightNames[operation]);
96
+ const otherRights = Object.entries(otherRightNames)
97
+ .filter(([operation]) => named.includes(operation))
98
+ .map(([, words]) => words);
99
+ return [...agentRights, ...computerRights, ...otherRights];
100
+ }
101
+ /** One-click host consent: one sheet listing every right in plain words. */
86
102
  export function AppAccessConsent({ request, }) {
87
103
  const [saving, setSaving] = useState(false);
88
104
  const [failed, setFailed] = useState(false);
105
+ const approve = useRef(null);
89
106
  const settle = (outcome) => {
90
107
  setSaving(false);
91
108
  setFailed(false);
@@ -94,28 +111,20 @@ export function AppAccessConsent({ request, }) {
94
111
  return (_jsx(Dialog, { open: request !== null, onOpenChange: (next) => {
95
112
  if (!next && !saving)
96
113
  settle("declined");
97
- }, children: _jsxs(DialogContent, { render: _jsx(WindowFrame, { floating: true }), keepMounted: false, className: "tourtois-app-consent", children: [_jsx(WindowHeader, { title: "App access" }), _jsxs("div", { className: "tourtois-app-consent-body", children: [_jsx(DialogTitle, { children: request
98
- ? `Let ${request.appName} work with your ${resources(request, "Agents", "Computers")}?`
99
- : "" }), _jsx(DialogDescription, { children: request
100
- ? `${request.appName} can ${describe([...request.agents, ...request.computers])} for every ${resources(request, "Agent", "Computer")} in this Oyster. You can change this later in System Settings.`
101
- : "" }), request?.refusal !== undefined ? (_jsx("p", { role: "alert", "data-refusal-code": request.refusal.code, children: request.refusal.message })) : null, failed ? (_jsx("p", { role: "alert", children: "Access could not be saved. Try again." })) : null, _jsxs(DialogFooter, { children: [_jsx(Button, { variant: "ghost", disabled: saving, onClick: () => {
102
- settle("customize");
103
- }, children: "Customize\u2026" }), _jsx(Button, { variant: "ghost", disabled: saving, onClick: () => {
104
- settle("declined");
105
- }, children: "Not now" }), _jsx(Button, { disabled: saving || request === null || request.refusal !== undefined, onClick: () => {
106
- if (request === null || request.refusal !== undefined)
107
- return;
108
- setSaving(true);
109
- setFailed(false);
110
- void request.allow().then((saved) => {
111
- if (saved)
112
- settle("granted");
113
- else {
114
- settle("declined");
115
- }
116
- }, () => {
117
- setSaving(false);
118
- setFailed(true);
119
- });
120
- }, children: saving ? "Allowing…" : "Allow" })] })] })] }) }));
114
+ }, children: _jsx(DialogContent, { render: _jsx(WindowFrame, { floating: true }), keepMounted: false, className: "tourtois-app-consent", initialFocus: approve, children: _jsxs("div", { className: "tourtois-app-consent-body", children: [_jsx(DialogTitle, { children: request ? `Approve ${request.appName}'s permissions?` : "" }), _jsx(DialogDescription, { children: request ? `${request.appName} would like to:` : "" }), request !== null ? (_jsx("ul", { className: "tourtois-app-consent-rights text-sm", children: plainRights(request).map((right) => (_jsx("li", { children: right }, right))) })) : null, _jsx("p", { className: "text-sm", children: "You can change this later in System Settings." }), request?.refusal !== undefined ? (_jsx("p", { role: "alert", "data-refusal-code": request.refusal.code, children: request.refusal.message })) : null, failed ? (_jsx("p", { role: "alert", children: "Access could not be saved. Try again." })) : null, _jsxs(DialogFooter, { className: "tourtois-app-consent-footer", children: [_jsx(Button, { variant: "ghost", size: "sm", disabled: saving, onClick: () => {
115
+ settle("customize");
116
+ }, children: "Customize\u2026" }), _jsxs("div", { className: "tourtois-app-consent-decision", children: [_jsx(Button, { variant: "ghost", disabled: saving, onClick: () => {
117
+ settle("declined");
118
+ }, children: "Not now" }), _jsx(Button, { ref: approve, disabled: saving || request === null || request.refusal !== undefined, onClick: () => {
119
+ if (request === null || request.refusal !== undefined)
120
+ return;
121
+ setSaving(true);
122
+ setFailed(false);
123
+ void request.allow().then((saved) => {
124
+ settle(saved ? "granted" : "declined");
125
+ }, () => {
126
+ setSaving(false);
127
+ setFailed(true);
128
+ });
129
+ }, children: saving ? "Approving…" : "Approve" })] })] })] }) }) }));
121
130
  }
package/dist/AppPane.js CHANGED
@@ -15,6 +15,7 @@ import { AppIcon } from "./app-icon.js";
15
15
  import { useWindowMotion } from "./use-window-motion.js";
16
16
  import { backHint } from "./shell-commands.js";
17
17
  import { createAppWindowManager, } from "./app-windows.js";
18
+ import { useDismissOverlays } from "./layers.js";
18
19
  import { launchComputerId } from "./app-launch.js";
19
20
  /**
20
21
  * The App's own path, commands and state, when it publishes them; an App
@@ -62,6 +63,7 @@ export function AppPane({ projection, nextLaunch, icon, manager, onError, index,
62
63
  const containerRef = useRef(null);
63
64
  const popover = useLayer("popover");
64
65
  const [computerPickerOpen, setComputerPickerOpen] = useState(false);
66
+ const dismissOthers = useDismissOverlays();
65
67
  useEffect(() => {
66
68
  if (projection.launch.computers === undefined)
67
69
  return;
@@ -192,7 +194,11 @@ export function AppPane({ projection, nextLaunch, icon, manager, onError, index,
192
194
  onError("App could not be reloaded.");
193
195
  });
194
196
  }
195
- : undefined, computerPickerOpen: computerPickerOpen, onComputerPickerOpenChange: setComputerPickerOpen, onSelectComputer: (computerId) => {
197
+ : undefined, computerPickerOpen: computerPickerOpen, onComputerPickerOpenChange: (open) => {
198
+ if (open)
199
+ dismissOthers();
200
+ setComputerPickerOpen(open);
201
+ }, onSelectComputer: (computerId) => {
196
202
  onSelectComputer(projection.windowId, computerId);
197
203
  }, surface: () => containerRef.current, onAction: (action) => {
198
204
  void manager
@@ -250,7 +256,9 @@ export function WindowStatusBar({ projection, onSelectComputer, onAction, surfac
250
256
  item.kind === "text" &&
251
257
  item.id === "documents"));
252
258
  const appReadouts = end.length === 0 ? undefined : end.map(render);
253
- return (_jsx(AppStatusBar, { className: "tourtois-window-status-bar", "aria-label": `${title} status`, attachment: computers === undefined ? undefined : (_jsx(StatusBarPicker, { ...(computerPickerOpen === undefined
259
+ return (_jsx(AppStatusBar, { className: "tourtois-window-status-bar", "aria-label": `${title} status`, attachment:
260
+ // One Computer is not a choice: the picker appears from two.
261
+ computers === undefined || computers.length === 1 ? undefined : (_jsx(StatusBarPicker, { ...(computerPickerOpen === undefined
254
262
  ? {}
255
263
  : { open: computerPickerOpen }), ...(onComputerPickerOpenChange === undefined
256
264
  ? {}
@@ -15,7 +15,7 @@ export function DesktopMenuBar({ teamName, focusedId, title, appBar, tiled, onLa
15
15
  const [layoutOpen, setLayoutOpen] = useState(false);
16
16
  return (_jsxs(ShellMenuBar, { children: [_jsxs(DropdownMenu, { modal: false, open: systemOpen, onOpenChange: setSystemOpen, children: [_jsxs(DropdownMenuTrigger, { className: "tourtois-system-menu-trigger", render: _jsx(Button, { size: "menubar", variant: "ghost" }), "aria-label": "Team and account menu", "aria-description": "Current Team: " + teamName, title: teamName, children: [_jsx(MushroomMark, {}), _jsx("span", { className: "tourtois-team-name truncate", children: teamName })] }), _jsxs(DropdownMenuContent, { align: "start", container: popover,
17
17
  // A sibling App click keeps focus there; Escape still returns here.
18
- finalFocus: (interaction) => interaction === "keyboard" && document.hasFocus(), children: [_jsx(DropdownMenuItem, { onSelect: onOpenSettings, children: "System Settings\u2026" }), onEditAvatar ? (_jsx(DropdownMenuItem, { onSelect: onEditAvatar, children: "Edit avatar\u2026" })) : null, systemMenuItems] })] }), appBar, onShowDesktop ? (_jsx(IconButton, { size: "responsive", icon: _jsx(Home, {}), "aria-label": "Show desktop", title: "Show desktop", onClick: onShowDesktop })) : null, _jsx("strong", { className: "tourtois-focused-app", children: title }), _jsx(FocusedAppMenus, {}, `menus:${focusedId ?? "shell"}`), onLayoutChange || onRestoreLayout || onArrangeDesktop ? (_jsxs(DropdownMenu, { modal: false, open: layoutOpen, onOpenChange: setLayoutOpen, children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { size: "menubar", variant: "ghost" }), children: "Layout" }), _jsxs(DropdownMenuContent, { align: "start", container: popover, finalFocus: (interaction) => interaction === "keyboard" && document.hasFocus(), children: [onLayoutChange ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuCheckboxItem, { checked: tiled, onCheckedChange: () => {
18
+ finalFocus: (interaction) => interaction === "keyboard" && document.hasFocus(), children: [_jsx(DropdownMenuItem, { onSelect: onOpenSettings, children: "System Settings\u2026" }), onEditAvatar ? (_jsx(DropdownMenuItem, { onSelect: onEditAvatar, children: "Edit avatar\u2026" })) : null, systemMenuItems] })] }), appBar, onShowDesktop ? (_jsx(IconButton, { size: "responsive", icon: _jsx(Home, {}), "aria-label": "Show desktop", title: "Show desktop", onClick: onShowDesktop })) : null, _jsx("strong", { className: "tourtois-focused-app", children: title }), _jsx(FocusedAppMenus, {}, `menus:${focusedId ?? "shell"}`), onLayoutChange || onRestoreLayout || onArrangeDesktop ? (_jsxs(DropdownMenu, { modal: false, open: layoutOpen, onOpenChange: setLayoutOpen, children: [_jsx(DropdownMenuTrigger, { "data-layout-menu": true, render: _jsx(Button, { size: "menubar", variant: "ghost" }), children: "Layout" }), _jsxs(DropdownMenuContent, { align: "start", container: popover, finalFocus: (interaction) => interaction === "keyboard" && document.hasFocus(), children: [onLayoutChange ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuCheckboxItem, { checked: tiled, onCheckedChange: () => {
19
19
  onLayoutChange(true);
20
20
  setLayoutOpen(false);
21
21
  }, children: "Tiled" }), _jsx(DropdownMenuCheckboxItem, { checked: !tiled, onCheckedChange: () => {
@@ -5,6 +5,7 @@ import { useQuery } from "@tanstack/react-query";
5
5
  import { MaosaicoRoot } from "@fungi.computer/maosaico";
6
6
  import { useEffect, useRef, useState } from "react";
7
7
  import { AppWorkbench } from "./AppWorkbench.js";
8
+ import { WelcomeProvider } from "./desktop/welcome.js";
8
9
  function useWorkbenchBounds() {
9
10
  const ref = useRef(null);
10
11
  const [bounds, setBounds] = useState({ height: 0, width: 0 });
@@ -35,5 +36,5 @@ export function TeamTourtois({ children, teamId, teamName, extraLaunchers, setti
35
36
  });
36
37
  return (_jsx("main", { className: "tourtois-shell", "data-tourtois-shell": true, children: _jsxs(TourtoisLayers, { children: [_jsx("div", { className: "tourtois-workbench", children: _jsx(MaosaicoRoot, { bounds: bounds, containerRef: paneLayerRef, tiling: tiled || phone
37
38
  ? { mainSize: Math.max(0, Math.min(640, bounds.width)), gap: 8 }
38
- : undefined, children: _jsx(AppWorkbench, { paneLayerRef: paneLayerRef, phone: phone, teamId: teamId, teamName: teamName ?? teamId, initialComputerId: data?.[0]?.computerId ?? null, computers: data ?? [], computersUnavailable: isLoading || isError, onLayoutChange: phone ? undefined : setTiled, platform: platform, desktopStorage: desktopStorage, desktopMethods: desktopMethods, gills: gills, ...(extraLaunchers ? { extraLaunchers } : {}), ...(settingsLaunchers ? { settingsLaunchers } : {}), ...(systemMenuItems ? { systemMenuItems } : {}), directoryReader: directoryReader, ...(takeAppOpenRequest ? { takeAppOpenRequest } : {}) }) }) }), children] }) }));
39
+ : undefined, children: _jsx(WelcomeProvider, { teamId: teamId, storage: desktopStorage, children: _jsx(AppWorkbench, { paneLayerRef: paneLayerRef, phone: phone, teamId: teamId, teamName: teamName ?? teamId, initialComputerId: data?.[0]?.computerId ?? null, computers: data ?? [], computersUnavailable: isLoading || isError, onLayoutChange: phone ? undefined : setTiled, platform: platform, desktopStorage: desktopStorage, desktopMethods: desktopMethods, gills: gills, ...(extraLaunchers ? { extraLaunchers } : {}), ...(settingsLaunchers ? { settingsLaunchers } : {}), ...(systemMenuItems ? { systemMenuItems } : {}), directoryReader: directoryReader, ...(takeAppOpenRequest ? { takeAppOpenRequest } : {}) }) }) }) }), children] }) }));
39
40
  }
@@ -8,5 +8,5 @@ import { Check, PanelsTopLeft } from "lucide-react";
8
8
  export function WorkbenchAppBar({ phone, ...props }) {
9
9
  const popover = useLayer("popover");
10
10
  const collapsed = phone && props.windows.length > 0;
11
- return (_jsxs(_Fragment, { children: [collapsed ? (_jsxs(DropdownMenu, { modal: false, children: [_jsxs(DropdownMenuTrigger, { render: _jsx(Button, { size: "menubar", variant: "ghost" }), "aria-label": "Switch open Apps", title: "Switch open Apps", children: [_jsx("span", { "aria-hidden": "true", className: "grid size-5 place-items-center [&_svg]:size-full", children: props.windows.find((item) => item.active)?.icon ?? (_jsx(PanelsTopLeft, {})) }), _jsx("span", { children: "Windows" })] }), _jsxs(DropdownMenuContent, { container: popover, align: "start", children: [props.windows.map((item) => (_jsxs(DropdownMenuItem, { role: "menuitemradio", "aria-checked": item.active ?? false, "aria-current": item.active ? "page" : undefined, onSelect: item.onSelect, children: [_jsx("span", { "aria-hidden": "true", className: "grid size-7 shrink-0 place-items-center [&_svg]:size-5", children: item.icon }), _jsx("span", { className: "flex-1", children: item.label }), item.active ? _jsx(Check, { "aria-hidden": "true", size: 16 }) : null] }, item.id))), _jsx(DropdownMenuSeparator, {}), props.windows.map((item) => item.onClose ? (_jsxs(DropdownMenuItem, { onSelect: item.onClose, children: ["Close ", item.label] }, item.id)) : null)] })] })) : null, _jsx(AppBar, { ...props, windows: collapsed ? [] : props.windows })] }));
11
+ return (_jsxs(_Fragment, { children: [collapsed ? (_jsxs(DropdownMenu, { modal: false, children: [_jsxs(DropdownMenuTrigger, { render: _jsx(Button, { size: "menubar", variant: "ghost" }), "aria-label": "Switch open Apps", title: "Switch open Apps", children: [_jsx("span", { "aria-hidden": "true", className: "grid size-5 place-items-center [&_svg]:size-full", children: props.windows.find((item) => item.active)?.icon ?? (_jsx(PanelsTopLeft, {})) }), _jsx("span", { className: "tourtois-windows-label", children: "Windows" })] }), _jsxs(DropdownMenuContent, { container: popover, align: "start", children: [props.windows.map((item) => (_jsxs(DropdownMenuItem, { role: "menuitemradio", "aria-checked": item.active ?? false, "aria-current": item.active ? "page" : undefined, onSelect: item.onSelect, children: [_jsx("span", { "aria-hidden": "true", className: "grid size-7 shrink-0 place-items-center [&_svg]:size-5", children: item.icon }), _jsx("span", { className: "flex-1", children: item.label }), item.active ? _jsx(Check, { "aria-hidden": "true", size: 16 }) : null] }, item.id))), _jsx(DropdownMenuSeparator, {}), props.windows.map((item) => item.onClose ? (_jsxs(DropdownMenuItem, { onSelect: item.onClose, children: ["Close ", item.label] }, item.id)) : null)] })] })) : null, _jsx(AppBar, { appsLabel: "Apps", ...props, windows: collapsed ? [] : props.windows })] }));
12
12
  }
package/dist/chrome.css CHANGED
@@ -131,23 +131,9 @@
131
131
  }
132
132
  }
133
133
 
134
- /* App status actions: flat chips on the picker's surface that keep their
135
- size, show a pressed or open state, and go icon-only on a phone. */
136
- .tourtois-status-chip {
137
- flex: none;
138
- max-width: none;
139
- }
140
- .tourtois-status-chip[aria-pressed="true"],
141
- .tourtois-status-chip[aria-expanded="true"] {
142
- background: var(--color-base-300);
143
- }
144
- @media (max-width: 640px) {
145
- .tourtois-status-chip:has(> svg) .tourtois-status-chip-label {
146
- position: absolute;
147
- width: 1px;
148
- height: 1px;
149
- overflow: hidden;
150
- clip-path: inset(50%);
151
- white-space: nowrap;
134
+ /* On the narrowest phones the bar keeps its icons; the tab's name is its tooltip. */
135
+ @media (max-width: 420px) {
136
+ .tourtois-windows-label {
137
+ display: none;
152
138
  }
153
139
  }
@@ -1,19 +1,20 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { GillParamPicker } from "./gill-param-picker.js";
3
- import { useEffect, useRef, useState, useSyncExternalStore, } from "react";
4
- import { createPortal } from "react-dom";
5
- import { arrangeBento, useLayer, useMaosaicoBento, } from "@fungi.computer/maosaico";
3
+ import { useEffect, useRef, useState, useSyncExternalStore } from "react";
4
+ import { arrangeBento, useMaosaicoBento } from "@fungi.computer/maosaico";
5
+ import { Alert } from "@fungi.computer/caps/components/alert";
6
6
  import { EmptyState } from "@fungi.computer/caps/blocks/empty-state";
7
7
  import { LoadingState } from "@fungi.computer/caps/blocks/loading-state";
8
8
  import { Button } from "@fungi.computer/caps/components/button";
9
9
  import { IconButton } from "@fungi.computer/caps/components/icon-button";
10
10
  import { GripVertical, Trash2 } from "lucide-react";
11
- import { Select } from "@fungi.computer/caps/components/select";
11
+ import { toast } from "@fungi.computer/caps/components/toaster";
12
12
  import { Badge } from "@fungi.computer/caps/components/badge";
13
13
  import { Sigil } from "@fungi.computer/sigils";
14
14
  import { DeclaredAppIcon } from "../app-icon.js";
15
15
  import { createDesktopLayoutClient, } from "../desktop-client.js";
16
16
  import { availableDesktopLayout, desktopPlacements, desktopBentoIntent, } from "../desktop-layout.js";
17
+ import { ArrangeToolbar } from "./arrange-toolbar.js";
17
18
  import { LauncherGill } from "./launcher-gill.js";
18
19
  import { RowGill } from "./row-gill.js";
19
20
  const gap = 16;
@@ -63,9 +64,9 @@ export function Desktop(props) {
63
64
  owner.invalidate();
64
65
  readCatalog.current = catalog;
65
66
  }, [owner, catalog]);
66
- return (_jsxs("div", { className: "tourtois-desktop", "data-desktop-bento": true, children: [error ? (_jsxs("p", { role: "alert", children: [error, " ", _jsx(Button, { variant: "ghost", size: "sm", onClick: () => {
67
- setRetry((value) => value + 1);
68
- }, children: "Retry" })] })) : null, !owner && !error ? (_jsx(LoadingState, { message: "Loading your desktop\u2026" })) : null, owner ? _jsx(ArrangedDesktop, { ...props, owner: owner }) : null] }));
67
+ return (_jsxs("div", { className: "tourtois-desktop", "data-desktop-bento": true, children: [error ? (_jsx(Alert, { tone: "error", description: error, action: _jsx(Button, { variant: "ghost", size: "sm", onClick: () => {
68
+ setRetry((value) => value + 1);
69
+ }, children: "Retry" }) })) : null, !owner && !error ? (_jsx(LoadingState, { message: "Loading your desktop\u2026" })) : null, owner ? _jsx(ArrangedDesktop, { ...props, owner: owner }) : null] }));
69
70
  }
70
71
  /** One plain line per refusal; the raw code goes to the console only. */
71
72
  function refusalMessage(code) {
@@ -82,30 +83,6 @@ function refusalMessage(code) {
82
83
  return "Couldn't save that change. Try again.";
83
84
  }
84
85
  }
85
- /**
86
- * The arrange controls live in the chrome layer so no window can cover them;
87
- * the in-flow spacer keeps the widgets clear of the bar.
88
- */
89
- function ArrangeToolbar({ children }) {
90
- const chrome = useLayer("chrome");
91
- const [bar, setBar] = useState(null);
92
- const [height, setHeight] = useState(0);
93
- useEffect(() => {
94
- if (!bar)
95
- return;
96
- const observer = new ResizeObserver(() => {
97
- setHeight(bar.offsetHeight);
98
- });
99
- observer.observe(bar);
100
- setHeight(bar.offsetHeight);
101
- return () => {
102
- observer.disconnect();
103
- };
104
- }, [bar]);
105
- return (_jsxs(_Fragment, { children: [_jsx("div", { "aria-hidden": "true", style: { height, marginBottom: 16 } }), chrome
106
- ? createPortal(_jsx("div", { ref: setBar, className: "tourtois-desktop-controls", role: "toolbar", "aria-label": "Arrange desktop", children: children }), chrome)
107
- : null] }));
108
- }
109
86
  function ArrangedDesktop({ owner, ...props }) {
110
87
  const snapshot = useSyncExternalStore(owner.subscribe, owner.get, owner.get);
111
88
  const catalog = snapshot.widgets;
@@ -114,6 +91,7 @@ function ArrangedDesktop({ owner, ...props }) {
114
91
  const [configuration, setConfiguration] = useState(null);
115
92
  const [error, setError] = useState(null);
116
93
  const [saving, setSaving] = useState(false);
94
+ const [saved, setSaved] = useState(false);
117
95
  const stage = useRef(null);
118
96
  const [width, setWidth] = useState(0);
119
97
  const [contentHeights, setContentHeights] = useState(new Map());
@@ -164,6 +142,8 @@ function ArrangedDesktop({ owner, ...props }) {
164
142
  if (result.kind !== "accepted")
165
143
  console.error("Desktop change refused", result.code);
166
144
  setError(result.kind === "accepted" ? null : refusalMessage(result.code));
145
+ if (result.kind === "accepted")
146
+ setSaved(true);
167
147
  return result.kind === "accepted";
168
148
  }
169
149
  catch (cause) {
@@ -242,24 +222,44 @@ function ArrangedDesktop({ owner, ...props }) {
242
222
  onSelect: () => undefined,
243
223
  })),
244
224
  ];
245
- return (_jsxs(_Fragment, { children: [snapshot.refreshFailure ? (_jsx("p", { role: "alert", children: snapshot.refreshFailure.message })) : null, editing ? (_jsxs(ArrangeToolbar, { children: [_jsx(Button, { size: "sm", variant: "outline", onClick: () => {
246
- onEditingChange(false);
247
- }, children: "Done arranging" }), _jsx("div", { className: "tourtois-desktop-add-gill", children: _jsxs(Select, { "aria-label": "Add widget", className: "select-sm", value: "", disabled: saving, onChange: (event) => {
248
- const gill = catalog[Number(event.currentTarget.value)];
249
- const size = gill?.sizes[0];
250
- if (gill && size && (gill.params?.length ?? 0) > 0)
251
- setConfiguration({ gill });
252
- else if (gill && size)
253
- void save("layout.place", {
254
- surfaceId: gill.surfaceId,
255
- gillId: gill.gillId,
256
- size,
257
- });
258
- }, children: [_jsx("option", { value: "", children: "Add widget\u2026" }), catalog.map((gill, index) => (_jsx("option", { value: index, children: gill.title }, `${gill.surfaceId}:${gill.gillId}`)))] }) }), _jsx(Button, { size: "sm", variant: "outline", disabled: saving, onClick: () => {
259
- void save("layout.reset", {});
260
- }, children: "Reset layout" }), snapshot.canWriteTeam ? (_jsx(Button, { size: "sm", variant: "outline", disabled: saving, onClick: () => {
261
- void save("layout.set", { layout: snapshot.layout }, "team");
262
- }, children: "Save as Team default" })) : null] })) : null, configuration ? (_jsx(GillParamPicker, { gill: configuration.gill, initialParams: snapshot.layout.items.find((item) => item.id === configuration.itemId)?.params, computers: props.computersForGill?.(configuration.gill.surfaceId) ?? [], transport: props.transport, editing: configuration.itemId !== undefined, onClose: () => {
225
+ const choices = catalog.map((gill) => {
226
+ const app = props.apps.find((entry) => entry.surfaceId === gill.surfaceId);
227
+ return {
228
+ gill,
229
+ placed: visibleItems.some((item) => item.surfaceId === gill.surfaceId && item.gillId === gill.gillId),
230
+ appName: app?.displayName ?? "Desktop",
231
+ icon: app ? (_jsx(DeclaredAppIcon, { icon: app.icon })) : (_jsx(Sigil, { name: "allApps" })),
232
+ };
233
+ });
234
+ const addWidget = (gill) => {
235
+ const size = gill.sizes[0];
236
+ if (!size)
237
+ return;
238
+ if ((gill.params?.length ?? 0) > 0)
239
+ setConfiguration({ gill });
240
+ else
241
+ void save("layout.place", {
242
+ surfaceId: gill.surfaceId,
243
+ gillId: gill.gillId,
244
+ size,
245
+ });
246
+ };
247
+ const finishArranging = () => {
248
+ if (saved)
249
+ toast("Desktop saved", {
250
+ id: "desktop-saved",
251
+ toasterId: "workbench-notices",
252
+ });
253
+ setSaved(false);
254
+ onEditingChange(false);
255
+ };
256
+ const longPress = useRef(undefined);
257
+ return (_jsxs(_Fragment, { children: [snapshot.refreshFailure ? (_jsx(Alert, { tone: "warning", description: snapshot.refreshFailure.message })) : null, editing ? (_jsx(ArrangeToolbar, { phone: props.phone, status: saving ? "saving" : saved ? "saved" : "idle", error: error, canWriteTeam: snapshot.canWriteTeam, choices: choices, saving: saving, onChoose: addWidget, onReset: async () => {
258
+ if (!(await save("layout.reset", {})))
259
+ throw new Error("The layout was not reset");
260
+ }, onSaveTeam: () => {
261
+ void save("layout.set", { layout: snapshot.layout }, "team");
262
+ }, onDone: finishArranging })) : null, configuration ? (_jsx(GillParamPicker, { gill: configuration.gill, initialParams: snapshot.layout.items.find((item) => item.id === configuration.itemId)?.params, computers: props.computersForGill?.(configuration.gill.surfaceId) ?? [], transport: props.transport, editing: configuration.itemId !== undefined, onClose: () => {
263
263
  setConfiguration(null);
264
264
  }, onSave: (params) => {
265
265
  if (configuration.itemId !== undefined)
@@ -281,7 +281,7 @@ function ArrangedDesktop({ owner, ...props }) {
281
281
  })
282
282
  : Promise.resolve(false);
283
283
  } }, configuration.itemId ??
284
- `${configuration.gill.surfaceId}:${configuration.gill.gillId}`)) : null, snapshot.notice ? _jsx("p", { role: "alert", children: snapshot.notice }) : null, visibleItems.length === 0 ? (_jsx("div", { className: "tourtois-desktop-empty", children: _jsx(EmptyState, { variant: "panel", title: "Your desktop is empty", description: "Restore the Launcher to get back to your Apps.", actions: _jsx(Button, { disabled: saving, onClick: () => {
284
+ `${configuration.gill.surfaceId}:${configuration.gill.gillId}`)) : null, snapshot.notice ? (_jsx(Alert, { tone: "info", description: snapshot.notice })) : null, visibleItems.length === 0 ? (_jsx("div", { className: "tourtois-desktop-empty", children: _jsx(EmptyState, { variant: "panel", title: "Your desktop is empty", description: "Restore the Launcher to get back to your Apps.", actions: _jsx(Button, { disabled: saving, onClick: () => {
285
285
  const size = launcherGill?.sizes.includes("M")
286
286
  ? "M"
287
287
  : launcherGill?.sizes[0];
@@ -293,12 +293,12 @@ function ArrangedDesktop({ owner, ...props }) {
293
293
  });
294
294
  else
295
295
  void save("layout.reset", {});
296
- }, children: "Restore Launcher" }) }) })) : null, error ? _jsx("p", { role: "alert", children: error }) : null, _jsx("div", { ref: stage, className: "tourtois-desktop-stage", style: { height }, "data-desktop-columns": columns, "data-preview": binding.preview, children: visibleItems.map((item) => {
296
+ }, children: "Restore Launcher" }) }) })) : null, error && !editing ? _jsx(Alert, { tone: "error", description: error }) : null, _jsx("div", { ref: stage, className: "tourtois-desktop-stage", style: { height }, "data-desktop-columns": columns, "data-preview": binding.preview, "data-arranging": editing ? "" : undefined, children: visibleItems.map((item) => {
297
297
  const frame = binding.frames.get(item.id);
298
298
  const gill = catalog.find((gill) => gill.surfaceId === item.surfaceId && gill.gillId === item.gillId);
299
299
  if (!frame || !gill)
300
300
  return null;
301
- const controls = editing ? (_jsxs("div", { className: "tourtois-gill-controls", children: [_jsx(IconButton, { size: "responsive", "aria-label": `Move ${gill.title}`, title: `Move ${gill.title}`, icon: _jsx(GripVertical, {}), ...binding.bind(item.id, "move") }), _jsx("div", { className: "join tourtois-gill-sizes", role: "group", "aria-label": `Size of ${gill.title}`, children: gill.sizes.map((size) => (_jsx(IconButton, { className: "join-item", size: "sm", icon: size, "aria-label": `Size ${size === "S" ? "small" : size === "M" ? "medium" : "large"}`, title: `${gill.title}: ${size}`, variant: size === item.size ? "secondary" : "ghost", "aria-pressed": size === item.size, disabled: saving, onClick: () => {
301
+ const controls = editing ? (_jsxs("div", { className: "tourtois-arrange-controls", children: [_jsx(IconButton, { size: "responsive", "aria-label": `Move ${gill.title}`, title: `Move ${gill.title}`, icon: _jsx(GripVertical, {}), ...binding.bind(item.id, "move") }), _jsx("div", { className: "join tourtois-gill-sizes", role: "group", "aria-label": `Size of ${gill.title}`, children: gill.sizes.map((size) => (_jsx(IconButton, { className: "join-item", size: "sm", icon: size, "aria-label": `Size ${size === "S" ? "small" : size === "M" ? "medium" : "large"}`, title: `${gill.title}: ${size}`, variant: size === item.size ? "secondary" : "ghost", "aria-pressed": size === item.size, disabled: saving, onClick: () => {
302
302
  void save("layout.resize", { id: item.id, size });
303
303
  } }, size))) }), _jsx("span", { title: onlyLauncher && isLauncher(item)
304
304
  ? "Your desktop needs one Launcher"
@@ -312,23 +312,40 @@ function ArrangedDesktop({ owner, ...props }) {
312
312
  };
313
313
  const app = props.apps.find((app) => app.surfaceId === item.surfaceId);
314
314
  const declaration = app?.gills.find((declaration) => declaration.id === item.gillId);
315
- return (_jsx("div", { "data-desktop-gill": item.id, className: "tourtois-desktop-tile", style: {
315
+ return (_jsxs("div", { "data-desktop-gill": item.id, className: "tourtois-desktop-tile", style: {
316
316
  left: frame.x,
317
317
  top: frame.y,
318
318
  width: frame.width,
319
319
  height: frame.height,
320
- }, children: gill.kind === "launcher" ? (_jsx(LauncherGill, { items: props.launcherItems, size: item.size, onAllApps: props.onAllApps, loading: props.loading, unavailable: props.unavailable, onRetry: props.onRetryApps, warnings: warnings, preferences: snapshot.layout.launcher, onPreference: (id, state) => {
321
- void save("layout.launcher", { appId: id, state });
322
- }, editHandle: controls, onContentHeight: onContentHeight })) : declaration && app ? (_jsx(RowGill, { surfaceId: item.surfaceId, appHeader: {
323
- name: app.displayName ?? "App",
324
- icon: _jsx(DeclaredAppIcon, { icon: app.icon }),
325
- }, declaration: declaration, params: item.params, size: item.size, paused: props.paused, transport: props.transport, onOpen: (target) => {
326
- props.onOpen({
327
- appId: app.appId,
328
- intent: { kind: "navigate", params: target.params },
329
- });
330
- }, onConfigure: () => {
331
- setConfiguration({ gill, itemId: item.id });
332
- }, launch: props.launcherItems.find((app) => app.id === `app:${item.surfaceId}`), editHandle: controls, onContentHeight: onContentHeight }, JSON.stringify(item.params ?? {}))) : null }, item.id));
320
+ }, onPointerDown: (event) => {
321
+ // Touch has no menu to reach Arrange from: a long press enters it.
322
+ if (editing || event.pointerType !== "touch")
323
+ return;
324
+ window.clearTimeout(longPress.current);
325
+ longPress.current = window.setTimeout(() => {
326
+ onEditingChange(true);
327
+ }, 600);
328
+ }, onPointerUp: () => {
329
+ window.clearTimeout(longPress.current);
330
+ }, onPointerMove: () => {
331
+ window.clearTimeout(longPress.current);
332
+ }, onPointerCancel: () => {
333
+ window.clearTimeout(longPress.current);
334
+ }, children: [_jsx("div", { className: "tourtois-desktop-tile-body", ref: (node) => {
335
+ if (node)
336
+ node.inert = editing;
337
+ }, children: gill.kind === "launcher" ? (_jsx(LauncherGill, { items: props.launcherItems, size: item.size, onAllApps: props.onAllApps, loading: props.loading, unavailable: props.unavailable, onRetry: props.onRetryApps, warnings: warnings, preferences: snapshot.layout.launcher, onPreference: (id, state) => {
338
+ void save("layout.launcher", { appId: id, state });
339
+ }, editHandle: editing ? _jsx("span", { "aria-hidden": "true" }) : undefined, onContentHeight: onContentHeight })) : declaration && app ? (_jsx(RowGill, { surfaceId: item.surfaceId, appHeader: {
340
+ name: app.displayName ?? "App",
341
+ icon: _jsx(DeclaredAppIcon, { icon: app.icon }),
342
+ }, declaration: declaration, params: item.params, size: item.size, paused: props.paused, transport: props.transport, onOpen: (target) => {
343
+ props.onOpen({
344
+ appId: app.appId,
345
+ intent: { kind: "navigate", params: target.params },
346
+ });
347
+ }, onConfigure: () => {
348
+ setConfiguration({ gill, itemId: item.id });
349
+ }, launch: props.launcherItems.find((app) => app.id === `app:${item.surfaceId}`), editHandle: editing ? _jsx("span", { "aria-hidden": "true" }) : undefined, onContentHeight: onContentHeight }, JSON.stringify(item.params ?? {}))) : null }), controls] }, item.id));
333
350
  }) })] }));
334
351
  }
@@ -0,0 +1,19 @@
1
+ import { type WidgetChoice } from "./widget-picker.js";
2
+ import type { DesktopGill } from "../desktop-layout.js";
3
+ export type ArrangeStatus = "idle" | "saving" | "saved";
4
+ /**
5
+ * Arrange's floating controls. They live in the chrome layer, take no flow
6
+ * space, and stay above every window.
7
+ */
8
+ export declare function ArrangeToolbar({ phone, status, error, canWriteTeam, choices, saving, onChoose, onReset, onSaveTeam, onDone, }: {
9
+ phone: boolean;
10
+ status: ArrangeStatus;
11
+ error: string | null;
12
+ canWriteTeam: boolean;
13
+ choices: readonly WidgetChoice[];
14
+ saving: boolean;
15
+ onChoose: (gill: DesktopGill) => void;
16
+ onReset: () => Promise<void>;
17
+ onSaveTeam: () => void;
18
+ onDone: () => void;
19
+ }): import("react").ReactPortal | null;
@@ -0,0 +1,63 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import { MoreHorizontal, Plus } from "lucide-react";
5
+ import { Button } from "@fungi.computer/caps/components/button";
6
+ import { ConfirmAction } from "@fungi.computer/caps/components/confirm-action";
7
+ import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@fungi.computer/caps/components/dialog";
8
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@fungi.computer/caps/components/dropdown-menu";
9
+ import { IconButton } from "@fungi.computer/caps/components/icon-button";
10
+ import { PopoverAnchor } from "@fungi.computer/caps/components/popover";
11
+ import { Status } from "@fungi.computer/caps/components/status";
12
+ import { Surface } from "@fungi.computer/caps/components/surface";
13
+ import { useLayer } from "@fungi.computer/maosaico";
14
+ import { WidgetPicker } from "./widget-picker.js";
15
+ /** Return focus to where Arrange was invoked, or the Layout menu. */
16
+ function restoreFocus(origin) {
17
+ if (origin instanceof HTMLElement && origin.isConnected) {
18
+ origin.focus();
19
+ return;
20
+ }
21
+ const layout = document.querySelector("[data-layout-menu]");
22
+ layout?.focus();
23
+ }
24
+ /**
25
+ * Arrange's floating controls. They live in the chrome layer, take no flow
26
+ * space, and stay above every window.
27
+ */
28
+ export function ArrangeToolbar({ phone, status, error, canWriteTeam, choices, saving, onChoose, onReset, onSaveTeam, onDone, }) {
29
+ const chrome = useLayer("chrome");
30
+ const [pickerOpen, setPickerOpen] = useState(false);
31
+ const [resetOpen, setResetOpen] = useState(false);
32
+ const origin = useRef(document.activeElement);
33
+ const done = useRef(onDone);
34
+ done.current = onDone;
35
+ const picker = useRef(pickerOpen);
36
+ picker.current = pickerOpen;
37
+ useEffect(() => {
38
+ const back = origin.current;
39
+ const onKey = (event) => {
40
+ if (event.key !== "Escape" || event.defaultPrevented)
41
+ return;
42
+ if (picker.current)
43
+ setPickerOpen(false);
44
+ else
45
+ done.current();
46
+ };
47
+ document.addEventListener("keydown", onKey);
48
+ return () => {
49
+ document.removeEventListener("keydown", onKey);
50
+ restoreFocus(back);
51
+ };
52
+ }, []);
53
+ if (!chrome)
54
+ return null;
55
+ return createPortal(_jsxs(Surface, { className: "tourtois-arrange", role: "toolbar", "aria-label": "Arranging desktop", "data-phone": phone ? "" : undefined, children: [_jsxs(PopoverAnchor, { className: "tourtois-arrange-add", children: [pickerOpen ? (_jsx(WidgetPicker, { choices: choices, disabled: saving, onChoose: onChoose })) : null, _jsxs(Button, { size: "sm", variant: "outline", "aria-expanded": pickerOpen, "aria-label": "Add widget", onClick: () => {
56
+ setPickerOpen(!pickerOpen);
57
+ }, children: [_jsx(Plus, { "aria-hidden": "true", size: 16 }), phone ? "Add" : "Add widget"] })] }), _jsxs(DropdownMenu, { modal: false, children: [_jsx(DropdownMenuTrigger, { render: _jsx(IconButton, { size: "sm", variant: "ghost", icon: _jsx(MoreHorizontal, {}), "aria-label": "More layout actions", title: "More layout actions" }) }), _jsxs(DropdownMenuContent, { container: chrome, align: "end", side: "top", children: [_jsx(DropdownMenuItem, { onSelect: () => {
58
+ setResetOpen(true);
59
+ }, children: "Reset layout\u2026" }), canWriteTeam ? (_jsx(DropdownMenuItem, { onSelect: onSaveTeam, children: "Save as Team default" })) : null] })] }), _jsx("span", { className: "tourtois-arrange-state", role: "status", "data-empty": error || status !== "idle" ? undefined : "", children: error ? (_jsx(Status, { glyph: "cross", tone: "error", label: error })) : status === "saving" ? (_jsx(Status, { glyph: "arc", tone: "info", label: "Saving\u2026" })) : status === "saved" ? (_jsx(Status, { glyph: "check", tone: "success", label: "Saved" })) : null }), _jsx(Button, { size: "sm", variant: "primary", "aria-label": "Done arranging", onClick: onDone, children: "Done" }), _jsx(Dialog, { open: resetOpen, onOpenChange: setResetOpen, children: _jsxs(DialogContent, { children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: "Reset layout" }), _jsx(DialogDescription, { children: "Your widgets go back to the default desktop." })] }), _jsx(ConfirmAction, { mode: "hold", label: "Reset layout", confirmLabel: "Hold to reset the layout", onConfirm: async () => {
60
+ await onReset();
61
+ setResetOpen(false);
62
+ } })] }) })] }), chrome);
63
+ }