@1agh/maude 1.2.0 → 1.3.1

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 (91) hide show
  1. package/README.md +3 -1
  2. package/apps/studio/acp/index.ts +43 -7
  3. package/apps/studio/annotations-layer.tsx +191 -116
  4. package/apps/studio/annotations-model.ts +39 -0
  5. package/apps/studio/annotations-sync.ts +50 -0
  6. package/apps/studio/api.ts +732 -38
  7. package/apps/studio/bin/annotate.mjs +3 -1
  8. package/apps/studio/bin/server-up.sh +17 -2
  9. package/apps/studio/canvas-build.ts +49 -8
  10. package/apps/studio/canvas-edit.ts +468 -7
  11. package/apps/studio/canvas-lib.tsx +82 -18
  12. package/apps/studio/canvas-list-watch.ts +33 -2
  13. package/apps/studio/canvas-notice-message.ts +16 -0
  14. package/apps/studio/canvas-notifications.tsx +19 -0
  15. package/apps/studio/canvas-shell.tsx +57 -6
  16. package/apps/studio/client/app.jsx +783 -245
  17. package/apps/studio/client/apply-edit-request.ts +55 -0
  18. package/apps/studio/client/canvas-url.js +39 -1
  19. package/apps/studio/client/export-center.jsx +111 -61
  20. package/apps/studio/client/github.js +38 -1
  21. package/apps/studio/client/index-loader.ts +76 -0
  22. package/apps/studio/client/panels/CloudBar.jsx +52 -6
  23. package/apps/studio/client/panels/GitPanel.jsx +103 -0
  24. package/apps/studio/client/panels/OnboardingWizard.jsx +36 -7
  25. package/apps/studio/client/panels/RepoBranchSwitcher.jsx +92 -27
  26. package/apps/studio/client/panels/SourceConflictPanel.jsx +166 -0
  27. package/apps/studio/client/panels/SyncPanel.jsx +113 -0
  28. package/apps/studio/client/panels/TeamProjects.jsx +376 -0
  29. package/apps/studio/client/panels/file-deep-link-dialog.jsx +54 -0
  30. package/apps/studio/client/photo-knobs.jsx +3 -0
  31. package/apps/studio/client/share-dialog.jsx +91 -0
  32. package/apps/studio/client/share-link.js +94 -0
  33. package/apps/studio/client/styles/3-shell-maude.css +36 -18
  34. package/apps/studio/client/styles/4-components.css +18 -1
  35. package/apps/studio/client/tree-row-menu.jsx +48 -3
  36. package/apps/studio/client/whats-new.jsx +26 -32
  37. package/apps/studio/cloud/endpoints.ts +132 -0
  38. package/apps/studio/collab/awareness-bridge.ts +65 -14
  39. package/apps/studio/collab/index.ts +4 -0
  40. package/apps/studio/collab/persistence.ts +5 -1
  41. package/apps/studio/collab/registry.ts +9 -3
  42. package/apps/studio/collab/room.ts +13 -2
  43. package/apps/studio/context.ts +59 -0
  44. package/apps/studio/dist/client.bundle.js +1594 -1562
  45. package/apps/studio/dist/comment-mount.js +2 -2
  46. package/apps/studio/dist/runtime/.min-sizes.json +1 -0
  47. package/apps/studio/dist/runtime/sonner.js +1 -0
  48. package/apps/studio/dist/styles.css +1 -1
  49. package/apps/studio/git/accepted-guard.ts +36 -0
  50. package/apps/studio/hmr-broadcast.ts +34 -1
  51. package/apps/studio/http.ts +300 -18
  52. package/apps/studio/inspect.ts +19 -0
  53. package/apps/studio/managed-projects.ts +172 -0
  54. package/apps/studio/notifications.tsx +292 -0
  55. package/apps/studio/runtime-bundle.ts +2 -0
  56. package/apps/studio/server.ts +59 -3
  57. package/apps/studio/sync/accepted-cold-start.ts +225 -0
  58. package/apps/studio/sync/accepted-link.ts +320 -0
  59. package/apps/studio/sync/action-stage.ts +343 -0
  60. package/apps/studio/sync/agent.ts +12 -60
  61. package/apps/studio/sync/cell-file-events.ts +3 -0
  62. package/apps/studio/sync/codec.ts +73 -6
  63. package/apps/studio/sync/ctl-provider.ts +15 -2
  64. package/apps/studio/sync/document-discovery.ts +81 -0
  65. package/apps/studio/sync/file-membership.ts +10 -2
  66. package/apps/studio/sync/file-plane.ts +309 -26
  67. package/apps/studio/sync/index.ts +1174 -21
  68. package/apps/studio/sync/migrate-seed.ts +110 -19
  69. package/apps/studio/sync/poke.ts +4 -2
  70. package/apps/studio/sync/presentation.ts +315 -2
  71. package/apps/studio/sync/projection.ts +820 -23
  72. package/apps/studio/sync/repeated-module.ts +73 -0
  73. package/apps/studio/sync/revision-barrier.ts +129 -0
  74. package/apps/studio/sync/seed-repair.ts +46 -0
  75. package/apps/studio/sync/source-merge.ts +100 -0
  76. package/apps/studio/sync/source-ops.ts +289 -0
  77. package/apps/studio/sync/source-recovery.ts +70 -0
  78. package/apps/studio/sync/source-validation.ts +56 -0
  79. package/apps/studio/sync/status.ts +83 -1
  80. package/apps/studio/sync/transaction-client.ts +486 -0
  81. package/apps/studio/sync/writer-registry.ts +236 -0
  82. package/apps/studio/text-caret.ts +35 -0
  83. package/apps/studio/undo-hud.tsx +9 -87
  84. package/apps/studio/use-canvas-media-drop.tsx +4 -39
  85. package/apps/studio/use-tool-mode.tsx +44 -0
  86. package/apps/studio/whats-new.json +137 -0
  87. package/cli/lib/harness/codex-runtime.mjs +4 -1
  88. package/package.json +9 -8
  89. package/plugins/design/dependencies.json +3 -3
  90. package/plugins/design/templates/_shell.html +95 -7
  91. package/plugins/flow/dependencies.json +3 -3
@@ -14,6 +14,9 @@
14
14
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
15
15
 
16
16
  import { safeDetail, safeName, syncPresentation } from '../../sync/presentation.ts';
17
+ import { TeamProjectsDialog } from './TeamProjects.jsx';
18
+ import SourceConflictPanel from './SourceConflictPanel.jsx';
19
+ import { isNativeApp } from '../github.js';
17
20
 
18
21
  /**
19
22
  * How long Resync stays disabled after a cycle finishes.
@@ -259,6 +262,50 @@ export default function SyncPanel({
259
262
  onClose,
260
263
  }) {
261
264
  const p = syncPresentation(status, { project });
265
+ // Plan T20/T22 — a refused workspace on the desktop is usually a sign-in that
266
+ // ran out. Signing in again re-mints the credential and reopens the same copy.
267
+ const [signInAgain, setSignInAgain] = useState(false);
268
+ // Plan T19 — "Download everything for offline".
269
+ const [offline, setOffline] = useState('');
270
+ const [offlineBusy, setOfflineBusy] = useState(false);
271
+ async function prepareOffline() {
272
+ setOfflineBusy(true);
273
+ setOffline('');
274
+ try {
275
+ const r = await fetch('/_api/sync/offline', { method: 'POST' });
276
+ const j = await r.json().catch(() => ({}));
277
+ if (!j.ok) setOffline(j.error || 'Could not download the project right now.');
278
+ else if (j.complete) setOffline(`Everything is on this device${j.pulled ? ` — ${j.pulled} file${j.pulled === 1 ? '' : 's'} came down` : ''}.`);
279
+ else setOffline(`${j.pulled} file${j.pulled === 1 ? '' : 's'} came down; ${j.failed} still to come — Maude keeps trying.`);
280
+ } catch {
281
+ setOffline('Maude isn’t reachable right now.');
282
+ } finally {
283
+ setOfflineBusy(false);
284
+ }
285
+ }
286
+ // Plan T28 — the conflict being resolved (a canvas slug), or null.
287
+ const [resolving, setResolving] = useState(null);
288
+ // Plan T16 — the person's decision on an unfinished AI edit.
289
+ const [aiBusy, setAiBusy] = useState('');
290
+ const [aiNote, setAiNote] = useState('');
291
+ const aiHeld = status?.aiAction?.state === 'held' ? status.aiAction : null;
292
+ async function resolveAi(choice) {
293
+ setAiBusy(choice);
294
+ setAiNote('');
295
+ try {
296
+ const r = await fetch('/_api/project/ai-action', {
297
+ method: 'POST',
298
+ headers: { 'Content-Type': 'application/json' },
299
+ body: JSON.stringify({ choice }),
300
+ });
301
+ const j = await r.json().catch(() => ({}));
302
+ if (!j.ok) setAiNote(j.error || (j.code ? `The project refused it (${j.code}).` : 'That did not work.'));
303
+ } catch {
304
+ setAiNote('Maude isn’t reachable right now.');
305
+ } finally {
306
+ setAiBusy('');
307
+ }
308
+ }
262
309
  const [resyncing, setResyncing] = useState(false);
263
310
  const [cooling, setCooling] = useState(false);
264
311
  const [note, setNote] = useState('');
@@ -530,6 +577,18 @@ export default function SyncPanel({
530
577
  continuous now, so nobody needs this button to pick up a new
531
578
  canvas — it is a repair tool, and repairing a cell is the hub's
532
579
  job. See `.ai/logs/rca/issue-cloud-assets-open-findings.md` §5. */}
580
+ {!cloud && status?.files && (
581
+ <button
582
+ type="button"
583
+ className="sp-resync"
584
+ data-testid="sync-offline"
585
+ onClick={prepareOffline}
586
+ disabled={offlineBusy}
587
+ title="Download every file of the project to this device now, to work offline"
588
+ >
589
+ {offlineBusy ? 'Downloading…' : 'Download all'}
590
+ </button>
591
+ )}
533
592
  {!cloud && (
534
593
  <button
535
594
  type="button"
@@ -551,6 +610,11 @@ export default function SyncPanel({
551
610
  {safeDetail(note, '')}
552
611
  </div>
553
612
  )}
613
+ {offline && (
614
+ <div className="sp-resync-note" role="status" aria-live="polite" data-testid="sync-offline-note">
615
+ {safeDetail(offline, '')}
616
+ </div>
617
+ )}
554
618
  {/* The one-rule sentence, live — same aria pattern as the rail note:
555
619
  a polite announcement when the phase changes, never a focus steal. */}
556
620
  {p && (
@@ -560,8 +624,26 @@ export default function SyncPanel({
560
624
  {p.title}
561
625
  {p.next ? ` ${p.next}` : ''}
562
626
  </span>
627
+ {p.phase === 'refused' && !cloud && isNativeApp() && (
628
+ <button
629
+ type="button"
630
+ className="btn btn--sm"
631
+ data-testid="sync-signin-again"
632
+ onClick={() => setSignInAgain(true)}
633
+ >
634
+ Sign in again
635
+ </button>
636
+ )}
563
637
  </div>
564
638
  )}
639
+ {resolving && <SourceConflictPanel slug={resolving} onClose={() => setResolving(null)} />}
640
+ {signInAgain && (
641
+ <TeamProjectsDialog
642
+ title="Sign in again"
643
+ initialServer={typeof status?.url === 'string' ? status.url : ''}
644
+ onClose={() => setSignInAgain(false)}
645
+ />
646
+ )}
565
647
  </div>
566
648
 
567
649
  <div className="sp-body">
@@ -569,11 +651,42 @@ export default function SyncPanel({
569
651
  (shared-doc buffer, TSX bodies) and used to live only in a
570
652
  console.warn a desktop user never sees. Dismiss is per (notice,
571
653
  hub) on this machine — a new hub resurfaces them by design. */}
654
+ {aiHeld && (
655
+ <section aria-label="Unfinished AI edit" className="sp-notice sp-ai-held" data-testid="sync-ai-held">
656
+ <p className="sp-notice-text">
657
+ <b>An unfinished AI edit is kept on this device.</b>{' '}
658
+ {safeDetail(aiHeld.label, 'AI edit')} changed{' '}
659
+ {Array.isArray(aiHeld.canvases) ? aiHeld.canvases.length : 0} canvas
660
+ {Array.isArray(aiHeld.canvases) && aiHeld.canvases.length === 1 ? '' : 'es'} and did not finish,
661
+ so nothing of it is shared yet. Publish it as it stands, or discard it — the
662
+ discarded bytes stay in recovery.
663
+ </p>
664
+ <div className="sp-ai-actions">
665
+ <button type="button" className="btn btn--sm btn--primary" disabled={!!aiBusy} onClick={() => resolveAi('publish')} data-testid="sync-ai-publish">
666
+ {aiBusy === 'publish' ? 'Publishing…' : 'Publish'}
667
+ </button>
668
+ <button type="button" className="btn btn--sm btn--ghost" disabled={!!aiBusy} onClick={() => resolveAi('discard')} data-testid="sync-ai-discard">
669
+ {aiBusy === 'discard' ? 'Discarding…' : 'Discard'}
670
+ </button>
671
+ </div>
672
+ {aiNote && <p className="sp-notice-text" role="alert">{safeDetail(aiNote, '')}</p>}
673
+ </section>
674
+ )}
572
675
  {notices.length > 0 && (
573
676
  <section aria-label="Notices" data-testid="sync-notices">
574
677
  {notices.map((n) => (
575
678
  <div key={n.id} className="sp-notice" data-testid={`sync-notice-${n.id}`}>
576
679
  <p className="sp-notice-text">{safeNoticeText(n.text)}</p>
680
+ {n.id.startsWith('source-conflict-') && (
681
+ <button
682
+ type="button"
683
+ className="btn btn--sm"
684
+ data-testid={`sync-resolve-${n.id.slice('source-conflict-'.length)}`}
685
+ onClick={() => setResolving(n.id.slice('source-conflict-'.length))}
686
+ >
687
+ Resolve…
688
+ </button>
689
+ )}
577
690
  <button
578
691
  type="button"
579
692
  className="sp-notice-dismiss"
@@ -0,0 +1,376 @@
1
+ // Team projects — plan T22 (feature-reliable-project-multiplayer).
2
+ //
3
+ // The designer's way in: pick a project you were added to and work. No folder
4
+ // to choose, no Git, no token to paste. Three sources, one action:
5
+ //
6
+ // • Recent team projects — the copies this computer already keeps
7
+ // (`managed_projects_list`); opening one needs no network.
8
+ // • Maude Cloud — sign in with the same device flow CloudBar uses, then the
9
+ // projects your account belongs to. Viewers get the browser, not a dead
10
+ // Open (the workspace would refuse their edits).
11
+ // • Your team's server — its address plus the email and password the team
12
+ // gave you (the self-hosted hub's own sign-in).
13
+ //
14
+ // Every path ends in `openTeamProject` / `managedProjectOpen`: the studio holds
15
+ // the credential and describes the project, the shell creates or reuses the
16
+ // project's own copy and switches to it. The webview never picks a path.
17
+ //
18
+ // Rendered as an onboarding door (`variant="door"`) and as a dialog from the
19
+ // project switcher (`variant="dialog"`); same content, different frame.
20
+
21
+ import { useEffect, useRef, useState } from 'react';
22
+
23
+ import { isDisplayableUrl, openExternal, shareViewUrl } from './CloudBar.jsx';
24
+ import { managedProjectOpen, managedProjectsList, openTeamProject } from '../github.js';
25
+
26
+ const api = async (path, init) => {
27
+ try {
28
+ const res = await fetch(path, init);
29
+ const json = await res.json().catch(() => ({}));
30
+ return { ok: res.ok, status: res.status, json };
31
+ } catch {
32
+ return { ok: false, status: 0, json: { error: 'Maude isn’t reachable right now.' } };
33
+ }
34
+ };
35
+
36
+ function Icon({ name, size = 16, className }) {
37
+ const p = {
38
+ check: <polyline points="3 8.2 6.4 11.5 13 4.2" />,
39
+ 'arrow-right': (<><line x1="2.5" y1="8" x2="13" y2="8" /><polyline points="9 4 13 8 9 12" /></>),
40
+ folder: <path d="M2 4.5h4l1.3 1.5H14V13H2z" />,
41
+ server: (<><rect x="2.5" y="3" width="11" height="4" rx="1" /><rect x="2.5" y="9" width="11" height="4" rx="1" /><circle cx="5" cy="5" r="0.5" fill="currentColor" /><circle cx="5" cy="11" r="0.5" fill="currentColor" /></>),
42
+ globe: (<><circle cx="8" cy="8" r="5.5" /><path d="M2.5 8h11M8 2.5c1.7 1.5 2.6 3.5 2.6 5.5S9.7 12.5 8 13.5C6.3 12 5.4 10 5.4 8S6.3 3.5 8 2.5z" /></>),
43
+ x: (<><line x1="3.5" y1="3.5" x2="12.5" y2="12.5" /><line x1="12.5" y1="3.5" x2="3.5" y2="12.5" /></>),
44
+ external: (<><path d="M6 3.5H3.2A.7.7 0 0 0 2.5 4.2v8.6a.7.7 0 0 0 .7.7h8.6a.7.7 0 0 0 .7-.7V10" /><line x1="8" y1="8" x2="13" y2="3" /><polyline points="9.5 3 13 3 13 6.5" /></>),
45
+ copy: (<><rect x="5.5" y="5.5" width="7.5" height="7.5" rx="1.2" /><path d="M3 10.5V3.2A.7.7 0 0 1 3.7 2.5H10" /></>),
46
+ spinner: <path d="M8 2.2a5.8 5.8 0 1 0 5.8 5.8" />,
47
+ key: (<><circle cx="5" cy="5" r="2.6" /><path d="M6.9 6.9 13 13M11 11l1.4-1.4M9.2 9.2l1.6-1.6" /></>),
48
+ user: (<><circle cx="8" cy="5.5" r="2.5" /><path d="M3 13.5c.6-2.6 2.6-4 5-4s4.4 1.4 5 4" /></>),
49
+ }[name];
50
+ return (
51
+ <svg className={className} width={size} height={size} viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
52
+ {p}
53
+ </svg>
54
+ );
55
+ }
56
+
57
+ function Spark({ size = 15 }) {
58
+ return (
59
+ <svg width={size} height={size} viewBox="0 0 32 32" fill="none" aria-hidden="true">
60
+ <path d="M16 5l2.8 8.2L27 16l-8.2 2.8L16 27l-2.8-8.2L5 16l8.2-2.8z" fill="currentColor" />
61
+ </svg>
62
+ );
63
+ }
64
+
65
+ /** "https://acme.cloud.maude.sh" → "acme.cloud.maude.sh" — display only. */
66
+ export function serverLabel(url) {
67
+ try {
68
+ return new URL(url).host;
69
+ } catch {
70
+ return String(url || '');
71
+ }
72
+ }
73
+
74
+ function ErrorLine({ text }) {
75
+ if (!text) return null;
76
+ return (
77
+ <div className="callout callout--error ob-callout" role="alert" data-testid="team-error">
78
+ <span className="ob-callout-glyph" style={{ color: 'var(--status-error)' }}><Icon name="x" /></span>
79
+ <span>{text}</span>
80
+ </div>
81
+ );
82
+ }
83
+
84
+ export default function TeamProjects({ variant = 'door', initialServer = '' }) {
85
+ const [recents, setRecents] = useState(null);
86
+ const [cloud, setCloud] = useState({ state: 'loading', email: null, url: 'https://cloud.maude.sh' });
87
+ const [projects, setProjects] = useState(null);
88
+ const [device, setDevice] = useState(null);
89
+ const [copied, setCopied] = useState(false);
90
+ const [hub, setHub] = useState({ url: initialServer, email: '', password: '' });
91
+ const [busy, setBusy] = useState(''); // the key of whatever is opening
92
+ const [opening, setOpening] = useState(''); // display name once the switch started
93
+ const [err, setErr] = useState('');
94
+ const pollRef = useRef(null);
95
+
96
+ useEffect(() => {
97
+ let alive = true;
98
+ managedProjectsList()
99
+ .then((r) => alive && setRecents(Array.isArray(r) ? r : []))
100
+ .catch(() => alive && setRecents([]));
101
+ api('/_api/cloud/status').then((r) => {
102
+ if (!alive) return;
103
+ const url = r.json?.url || 'https://cloud.maude.sh';
104
+ if (r.ok && r.json?.connected) {
105
+ setCloud({ state: 'in', email: r.json.email ?? null, url });
106
+ loadProjects();
107
+ } else setCloud({ state: 'out', email: null, url });
108
+ });
109
+ return () => {
110
+ alive = false;
111
+ clearInterval(pollRef.current);
112
+ };
113
+ // eslint-disable-next-line react-hooks/exhaustive-deps
114
+ }, []);
115
+
116
+ async function loadProjects() {
117
+ setProjects(null);
118
+ const r = await api('/_api/cloud/projects');
119
+ if (r.status === 401) {
120
+ setCloud((c) => ({ ...c, state: 'out', email: null }));
121
+ setProjects([]);
122
+ return;
123
+ }
124
+ setProjects(r.ok && r.json?.ok ? r.json.projects || [] : []);
125
+ if (!r.ok) setErr(r.json?.error || 'Your Maude Cloud projects could not be listed.');
126
+ }
127
+
128
+ async function startCloudSignIn() {
129
+ setErr('');
130
+ const r = await api('/_api/cloud/signin/start', { method: 'POST' });
131
+ if (!r.ok || !r.json?.ok) {
132
+ setErr(r.json?.error || 'Maude Cloud could not be reached.');
133
+ return;
134
+ }
135
+ setDevice(r.json);
136
+ openExternal(r.json.verificationUrl);
137
+ clearInterval(pollRef.current);
138
+ pollRef.current = setInterval(async () => {
139
+ const p = await api('/_api/cloud/signin/poll', {
140
+ method: 'POST',
141
+ headers: { 'content-type': 'application/json' },
142
+ body: JSON.stringify({ deviceCode: r.json.deviceCode }),
143
+ });
144
+ if (p.json?.pending) return;
145
+ clearInterval(pollRef.current);
146
+ setDevice(null);
147
+ if (p.ok && p.json?.ok) {
148
+ setCloud((c) => ({ ...c, state: 'in', email: p.json.email ?? null }));
149
+ loadProjects();
150
+ } else setErr(p.json?.error || 'The sign-in did not finish. Try again.');
151
+ }, (r.json.interval ?? 5) * 1000);
152
+ }
153
+
154
+ function cancelCloudSignIn() {
155
+ clearInterval(pollRef.current);
156
+ setDevice(null);
157
+ }
158
+
159
+ async function run(key, name, fn) {
160
+ if (busy) return;
161
+ setErr('');
162
+ setBusy(key);
163
+ const r = await fn();
164
+ if (r.ok) {
165
+ // The shell is switching; the window reloads onto the project. Keep the
166
+ // row busy so a second click can't start another open meanwhile.
167
+ setOpening(name);
168
+ return;
169
+ }
170
+ setBusy('');
171
+ setErr(r.error || 'The project could not be opened.');
172
+ }
173
+
174
+ const openRecent = (p) =>
175
+ run(`recent:${p.key}`, p.name, async () => {
176
+ try {
177
+ await managedProjectOpen({ serverUrl: p.server_url, projectId: p.project_id, name: p.name, canvasGroups: [] });
178
+ return { ok: true };
179
+ } catch (e) {
180
+ return { ok: false, error: String(e?.message || e) };
181
+ }
182
+ });
183
+
184
+ const openCloud = (p) =>
185
+ run(`cloud:${p.id}`, p.name || p.id, () => openTeamProject({ kind: 'cloud', projectId: p.id }));
186
+
187
+ const openHub = () =>
188
+ run('hub', serverLabel(hub.url), () =>
189
+ openTeamProject({ kind: 'hub', url: hub.url.trim(), email: hub.email.trim(), password: hub.password })
190
+ );
191
+
192
+ const canHub = hub.url.trim() && hub.email.trim() && hub.password;
193
+
194
+ return (
195
+ <div className={`tp tp--${variant}`} data-testid="team-projects">
196
+ {opening && (
197
+ <div className="callout callout--info ob-callout" role="status" aria-live="polite" data-testid="team-opening">
198
+ <span className="ob-callout-glyph"><Icon name="spinner" size={15} className="ob-spin" /></span>
199
+ <span>Opening <b>{opening}</b>… your canvases arrive as they download.</span>
200
+ </div>
201
+ )}
202
+
203
+ {recents && recents.length > 0 && (
204
+ <section className="tp-section" aria-label="Recent team projects">
205
+ <div className="ob-section-label">On this computer</div>
206
+ <div className="ob-repolist">
207
+ {recents.map((p) => {
208
+ const k = `recent:${p.key}`;
209
+ return (
210
+ <button type="button" key={p.key} className="ob-repo" disabled={!!busy} onClick={() => openRecent(p)} data-testid={`team-recent-${p.key}`}>
211
+ <span className="ob-repo-icon"><Icon name="folder" size={15} /></span>
212
+ <span className="ob-repo-tx">
213
+ <span className="ob-repo-name">{p.name}</span>
214
+ <span className="ob-repo-meta">{serverLabel(p.server_url)}</span>
215
+ </span>
216
+ <span className="ob-repo-go">{busy === k ? <Icon name="spinner" size={16} className="ob-spin" /> : <><Icon name="arrow-right" size={15} /> Open</>}</span>
217
+ </button>
218
+ );
219
+ })}
220
+ </div>
221
+ </section>
222
+ )}
223
+
224
+ <section className="tp-section" aria-label="Maude Cloud">
225
+ <div className="ob-section-label">Maude Cloud</div>
226
+ {cloud.state === 'loading' && <div className="ob-foot-note">Checking your sign-in…</div>}
227
+ {cloud.state === 'out' && !device && (
228
+ <button type="button" className="ob-repo" onClick={startCloudSignIn} data-testid="team-cloud-signin">
229
+ <span className="ob-repo-icon"><Spark size={15} /></span>
230
+ <span className="ob-repo-tx">
231
+ <span className="ob-repo-name">Sign in to Maude Cloud</span>
232
+ <span className="ob-repo-meta">See the projects you were invited to</span>
233
+ </span>
234
+ <span className="ob-repo-go"><Icon name="arrow-right" size={15} /> Sign in</span>
235
+ </button>
236
+ )}
237
+ {device && (
238
+ <div className="tp-device" data-testid="team-cloud-device">
239
+ <span className="ob-field-label">Confirm this code on your Maude Cloud dashboard</span>
240
+ <div className="gi-code">
241
+ <span className="gi-code-val" data-testid="team-cloud-code">{device.userCode}</span>
242
+ <button
243
+ type="button"
244
+ className="btn btn--ghost gi-code-copy"
245
+ onClick={() => navigator.clipboard?.writeText(device.userCode).then(() => { setCopied(true); setTimeout(() => setCopied(false), 1500); }, () => {})}
246
+ aria-label="Copy the code"
247
+ >
248
+ <Icon name="copy" size={15} /> {copied ? 'Copied' : 'Copy'}
249
+ </button>
250
+ </div>
251
+ {device.verificationUrl && isDisplayableUrl(device.verificationUrl, cloud.url) && (
252
+ <span className="ob-foot-note">
253
+ If your browser didn’t open, go to <span className="gi-dc-url">{device.verificationUrl}</span>
254
+ </span>
255
+ )}
256
+ <div className="ob-form-actions">
257
+ <span className="gi-dc-status" aria-live="polite"><span className="gi-pulse" aria-hidden="true" /> Waiting for you to confirm…</span>
258
+ <button type="button" className="btn btn--ghost" onClick={cancelCloudSignIn}>Cancel</button>
259
+ </div>
260
+ </div>
261
+ )}
262
+ {cloud.state === 'in' && (
263
+ <>
264
+ {projects === null && <div className="ob-foot-note">Loading your projects…</div>}
265
+ {Array.isArray(projects) && projects.length === 0 && (
266
+ <div className="ob-foot-note" data-testid="team-cloud-empty">
267
+ You aren’t in any project yet. Ask whoever runs your team’s project to invite {cloud.email || 'you'}.
268
+ </div>
269
+ )}
270
+ {Array.isArray(projects) && projects.length > 0 && (
271
+ <div className="ob-repolist">
272
+ {projects.map((p) => {
273
+ const k = `cloud:${p.id}`;
274
+ if (p.role === 'viewer') {
275
+ return (
276
+ <button type="button" key={p.id} className="ob-repo" onClick={() => openExternal(shareViewUrl(p.url, p.id))} data-testid={`team-cloud-project-${p.id}`} title="Viewing works in the browser. Editing in the app needs the member role — ask whoever runs the project.">
277
+ <span className="ob-repo-icon"><Icon name="globe" size={15} /></span>
278
+ <span className="ob-repo-tx">
279
+ <span className="ob-repo-name">{p.name || p.id}</span>
280
+ <span className="ob-repo-meta">viewer · opens in your browser</span>
281
+ </span>
282
+ <span className="ob-repo-go"><Icon name="external" size={15} /> View</span>
283
+ </button>
284
+ );
285
+ }
286
+ return (
287
+ <button type="button" key={p.id} className="ob-repo" disabled={!!busy} onClick={() => openCloud(p)} data-testid={`team-cloud-project-${p.id}`}>
288
+ <span className="ob-repo-icon"><Spark size={15} /></span>
289
+ <span className="ob-repo-tx">
290
+ <span className="ob-repo-name">{p.name || p.id}</span>
291
+ <span className="ob-repo-meta">{p.role}{p.stateLabel ? ` · ${p.stateLabel}` : ''}</span>
292
+ </span>
293
+ <span className="ob-repo-go">{busy === k ? <Icon name="spinner" size={16} className="ob-spin" /> : <><Icon name="arrow-right" size={15} /> Open</>}</span>
294
+ </button>
295
+ );
296
+ })}
297
+ </div>
298
+ )}
299
+ </>
300
+ )}
301
+ </section>
302
+
303
+ <section className="tp-section" aria-label="Your team's server">
304
+ <div className="ob-section-label">Your team’s own server</div>
305
+ <form
306
+ className="ob-form"
307
+ onSubmit={(e) => {
308
+ e.preventDefault();
309
+ if (canHub && !busy) openHub();
310
+ }}
311
+ >
312
+ <label className="ob-field">
313
+ <span className="ob-field-label">Server address</span>
314
+ <span className="ob-field-wrap"><Icon name="server" size={14} className="ob-field-pre" />
315
+ <input className="input ob-input" type="url" inputMode="url" autoComplete="url" value={hub.url} placeholder="https://design.yourteam.com" aria-label="Server address" data-testid="team-hub-url" onChange={(e) => setHub((h) => ({ ...h, url: e.target.value }))} />
316
+ </span>
317
+ </label>
318
+ <label className="ob-field">
319
+ <span className="ob-field-label">Email</span>
320
+ <span className="ob-field-wrap"><Icon name="user" size={14} className="ob-field-pre" />
321
+ <input className="input ob-input" type="email" autoComplete="username" value={hub.email} placeholder="you@yourteam.com" aria-label="Email" data-testid="team-hub-email" onChange={(e) => setHub((h) => ({ ...h, email: e.target.value }))} />
322
+ </span>
323
+ </label>
324
+ <label className="ob-field">
325
+ <span className="ob-field-label">Password</span>
326
+ <span className="ob-field-wrap"><Icon name="key" size={14} className="ob-field-pre" />
327
+ <input className="input ob-input" type="password" autoComplete="current-password" value={hub.password} aria-label="Password" data-testid="team-hub-password" onChange={(e) => setHub((h) => ({ ...h, password: e.target.value }))} />
328
+ </span>
329
+ </label>
330
+ <div className="ob-form-actions">
331
+ <button type="submit" className="btn btn--primary" disabled={!canHub || !!busy} data-testid="team-hub-open">
332
+ {busy === 'hub' ? <><Icon name="spinner" size={15} className="ob-spin" /> Signing in…</> : <><Icon name="arrow-right" size={15} /> Sign in and open</>}
333
+ </button>
334
+ </div>
335
+ </form>
336
+ </section>
337
+
338
+ <ErrorLine text={err} />
339
+ <p className="ob-foot-note">Maude keeps the project’s copy on this computer and saves every change to your team as you work.</p>
340
+ </div>
341
+ );
342
+ }
343
+
344
+ /** The same picker as a dialog — from the project switcher. */
345
+ export function TeamProjectsDialog({ onClose, initialServer = '', title = 'Open a team project' }) {
346
+ const ref = useRef(null);
347
+ useEffect(() => {
348
+ const prev = document.activeElement;
349
+ ref.current?.querySelector('button, input')?.focus();
350
+ const onKey = (e) => {
351
+ if (e.key === 'Escape') onClose();
352
+ };
353
+ document.addEventListener('keydown', onKey);
354
+ return () => {
355
+ document.removeEventListener('keydown', onKey);
356
+ prev?.focus?.();
357
+ };
358
+ }, [onClose]);
359
+ return (
360
+ <div className="gi-modal" role="dialog" aria-modal="true" aria-labelledby="tp-dialog-title">
361
+ <div className="gi-scrim" aria-hidden="true" onClick={onClose} />
362
+ <div className="gi-dialog tp-dialog" ref={ref} data-testid="team-projects-dialog">
363
+ <div className="tp-dialog-head">
364
+ <div>
365
+ <h2 id="tp-dialog-title">{title}</h2>
366
+ <p>Projects you were added to open in their own copy on this computer.</p>
367
+ </div>
368
+ <button type="button" className="btn btn--ghost btn--sm" onClick={onClose} aria-label="Close" data-testid="team-projects-close">
369
+ <Icon name="x" size={14} />
370
+ </button>
371
+ </div>
372
+ <TeamProjects variant="dialog" initialServer={initialServer} />
373
+ </div>
374
+ </div>
375
+ );
376
+ }
@@ -0,0 +1,54 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { openLocalProject, resolveProjectForLink, openCloudUrl } from '../github.js';
3
+ import { encodeOpenPath } from '../share-link.js';
4
+ import { copyShareLink, useLinkDialogFocus } from '../share-dialog.jsx';
5
+
6
+ /** The project zone is configured locally; file links never supply an origin. */
7
+ export function fileProjectWebUrl(project, rel, cloudUrl) {
8
+ try {
9
+ const base = new URL(cloudUrl);
10
+ if (base.protocol !== 'https:' || base.port || base.username || base.password || /^[\d.]+$/.test(base.hostname) || !base.hostname.includes('.')) return null;
11
+ return `https://${project}.${base.hostname}/?open=${encodeOpenPath(rel)}`;
12
+ } catch { return null; }
13
+ }
14
+
15
+ export default function FileDeepLinkDialog({ pending, local, cloudUrl, onClose }) {
16
+ const ref = useLinkDialogFocus(onClose);
17
+ const [resolution, setResolution] = useState({ loading: true, path: null });
18
+ const [error, setError] = useState('');
19
+ const [busy, setBusy] = useState(false);
20
+ useEffect(() => {
21
+ let cancelled = false;
22
+ resolveProjectForLink(pending.project).then((path) => {
23
+ if (!cancelled) setResolution({ loading: false, path });
24
+ }).catch(() => { if (!cancelled) { setResolution({ loading: false, path: null }); setError('Could not look up local projects.'); } });
25
+ return () => { cancelled = true; };
26
+ }, [pending.project]);
27
+ const web = fileProjectWebUrl(pending.project, pending.rel, cloudUrl);
28
+ const open = async () => {
29
+ setBusy(true); setError('');
30
+ try { await openLocalProject(resolution.path, pending.rel); onClose(); }
31
+ catch (err) { setError(String(err)); setBusy(false); }
32
+ };
33
+ return (
34
+ <div className="gi-modal" role="dialog" aria-modal="true" aria-label={`Open file in ${pending.project}`}>
35
+ <div className="gi-scrim" aria-hidden="true" onClick={onClose} />
36
+ <div ref={ref} className="gi-dialog gi-dialog--code" data-testid="file-deeplink-dialog">
37
+ <div className="gi-dc-head"><h2>Open {pending.rel} in {pending.project}?</h2></div>
38
+ <p className="gi-dl-what">You are working in {local.project || 'the open project'}.</p>
39
+ {resolution.loading ? <p>Looking for this project…</p> : resolution.path ? <p>{resolution.path}</p> : <p>{pending.project} isn’t on this Mac.</p>}
40
+ {error && <p role="alert">{error}</p>}
41
+ {!resolution.loading && !resolution.path && web && (
42
+ <div className="gi-dl-note">
43
+ <a href={web} onClick={(e) => { e.preventDefault(); openCloudUrl(web).catch(() => setError('Could not open this address automatically. Copy the web link into your browser.')); }}>Open in browser</a>
44
+ <button type="button" className="btn btn--ghost" onClick={() => copyShareLink(web)}>Copy web link</button>
45
+ </div>
46
+ )}
47
+ <div className="gi-dc-foot">
48
+ <button type="button" className="btn btn--ghost" data-testid="file-deeplink-dismiss" onClick={onClose}>Not now</button>
49
+ {resolution.path && <button type="button" className="btn" disabled={busy} data-testid="file-deeplink-open" onClick={open}>{busy ? 'Opening…' : 'Open project'}</button>}
50
+ </div>
51
+ </div>
52
+ </div>
53
+ );
54
+ }
@@ -231,6 +231,9 @@ export function PhotoKnobs({ asset, initialEdit, ColorPicker, onEdit, onRemoveBa
231
231
  const before = editRef.current;
232
232
  const next = clone(before);
233
233
  fn(next);
234
+ // Reset and a number field's blur can arrive before React renders.
235
+ // The next mutation (and its undo base) must already see this edit.
236
+ editRef.current = next;
234
237
  setEditState(next);
235
238
  onEdit?.(next);
236
239
  put(next);