@1agh/maude 1.8.1 → 1.9.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.
- package/apps/studio/acp/bridge.ts +14 -2
- package/apps/studio/acp/probe.ts +51 -1
- package/apps/studio/api.ts +19 -4
- package/apps/studio/bin/_curl-local.mjs +7 -0
- package/apps/studio/bin/annotate.mjs +16 -7
- package/apps/studio/bin/read-annotations.mjs +62 -4
- package/apps/studio/client/app.jsx +428 -15977
- package/apps/studio/client/dialogs/asset-picker.jsx +331 -0
- package/apps/studio/client/dialogs/command-palette.jsx +112 -0
- package/apps/studio/client/dialogs/export-dialog.jsx +782 -0
- package/apps/studio/client/dialogs/help-modal.jsx +324 -0
- package/apps/studio/client/dialogs/shortcuts-overlay.jsx +144 -0
- package/apps/studio/client/hooks/use-canvas-bridge.jsx +2150 -0
- package/apps/studio/client/hooks/use-git-actions.jsx +236 -0
- package/apps/studio/client/hooks/use-keyboard-shortcuts.jsx +297 -0
- package/apps/studio/client/hooks/use-palette-and-panels.jsx +474 -0
- package/apps/studio/client/hooks/use-photo-and-timeline.jsx +901 -0
- package/apps/studio/client/hooks/use-project-data.jsx +90 -0
- package/apps/studio/client/hooks/use-shell-core.jsx +1212 -0
- package/apps/studio/client/hooks/use-tabs.jsx +723 -0
- package/apps/studio/client/hooks/use-web-socket.jsx +13 -0
- package/apps/studio/client/inspector/artboard-knobs.jsx +456 -0
- package/apps/studio/client/inspector/color-picker.jsx +196 -0
- package/apps/studio/client/inspector/color.js +92 -0
- package/apps/studio/client/inspector/css-knobs.jsx +1720 -0
- package/apps/studio/client/inspector/css-vocab.jsx +131 -0
- package/apps/studio/client/inspector/ds-tokens.js +90 -0
- package/apps/studio/client/inspector/grid-tracks-editor.jsx +97 -0
- package/apps/studio/client/inspector/inspect-computed.jsx +68 -0
- package/apps/studio/client/inspector/inspector-panel.jsx +769 -0
- package/apps/studio/client/inspector/layers.jsx +322 -0
- package/apps/studio/client/inspector/selection.js +65 -0
- package/apps/studio/client/inspector/token-popover.jsx +301 -0
- package/apps/studio/client/menus/menubar.jsx +856 -0
- package/apps/studio/client/selection-scope.js +40 -0
- package/apps/studio/client/shell/banners.jsx +272 -0
- package/apps/studio/client/shell/collapsed-rail.jsx +23 -0
- package/apps/studio/client/shell/comments-panel.jsx +177 -0
- package/apps/studio/client/shell/constants.js +60 -0
- package/apps/studio/client/shell/dock.jsx +131 -0
- package/apps/studio/client/shell/icons.jsx +370 -0
- package/apps/studio/client/shell/status-bar.jsx +215 -0
- package/apps/studio/client/shell/util.js +332 -0
- package/apps/studio/client/shell/viewport.jsx +254 -0
- package/apps/studio/client/system/system-view.jsx +255 -0
- package/apps/studio/client/tree/tree.jsx +1243 -0
- package/apps/studio/comments-overlay.tsx +6 -4
- package/apps/studio/config.schema.json +5 -0
- package/apps/studio/context.ts +13 -0
- package/apps/studio/dist/client.bundle.js +1337 -1337
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/exporters/_browser-bundles.ts +21 -2
- package/apps/studio/exporters/jobs.ts +75 -15
- package/apps/studio/exporters/scope.ts +15 -12
- package/apps/studio/format.ts +296 -0
- package/apps/studio/http.ts +217 -23
- package/apps/studio/server.ts +141 -30
- package/apps/studio/sync/accepted-link.ts +6 -0
- package/apps/studio/sync/agent.ts +9 -1
- package/apps/studio/sync/cold-start-apply.ts +29 -4
- package/apps/studio/sync/cold-start.ts +78 -0
- package/apps/studio/sync/file-plane.ts +61 -1
- package/apps/studio/sync/format-sync.ts +160 -0
- package/apps/studio/sync/index.ts +134 -10
- package/apps/studio/sync/journal-client.ts +25 -5
- package/apps/studio/sync/migrate-seed.ts +8 -1
- package/apps/studio/sync/status.ts +2 -0
- package/apps/studio/sync/transaction-client.ts +130 -13
- package/apps/studio/ui-prefs.ts +95 -10
- package/apps/studio/whats-new.json +9 -0
- package/apps/studio/ws.ts +19 -4
- package/cli/bin/claude-design-server.mjs +0 -0
- package/package.json +10 -8
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// shell/status-bar.jsx — moved verbatim out of client/app.jsx (Maude v2 plan V2-0.2, move-only split).
|
|
2
|
+
|
|
3
|
+
import { SYSTEM_TAB } from './constants.js';
|
|
4
|
+
import { syncPresentation } from '../../sync/presentation.ts';
|
|
5
|
+
import { StIcon } from './icons.jsx';
|
|
6
|
+
|
|
7
|
+
// ---------- Comment composer / viewer ----------
|
|
8
|
+
|
|
9
|
+
export function StatusBar({
|
|
10
|
+
activePath,
|
|
11
|
+
selected,
|
|
12
|
+
wsConnected,
|
|
13
|
+
openCount,
|
|
14
|
+
theme,
|
|
15
|
+
onToggleTheme,
|
|
16
|
+
onClearSelected,
|
|
17
|
+
syncStatus,
|
|
18
|
+
syncProject,
|
|
19
|
+
syncOpen = false,
|
|
20
|
+
onOpenSync,
|
|
21
|
+
changesCount = 0,
|
|
22
|
+
unpushed = 0,
|
|
23
|
+
// Somebody else commits this project (a cloud cell, or the cell behind a
|
|
24
|
+
// linked+credentialed desktop repo — DDR-218). The chip then names the
|
|
25
|
+
// mechanism that IS saving rather than reporting a working-tree count the
|
|
26
|
+
// user has no reason to act on. Default false = today's local-first chip.
|
|
27
|
+
savingIsManaged = false,
|
|
28
|
+
changesOpen = false,
|
|
29
|
+
onOpenChanges,
|
|
30
|
+
version,
|
|
31
|
+
}) {
|
|
32
|
+
const isSystem = activePath === SYSTEM_TAB;
|
|
33
|
+
const text =
|
|
34
|
+
selected && selected.selector
|
|
35
|
+
? selected.selector + (selected.text ? ` — "${selected.text.slice(0, 60)}"` : '')
|
|
36
|
+
: '';
|
|
37
|
+
const title =
|
|
38
|
+
selected && selected.dom_path
|
|
39
|
+
? selected.dom_path.join(' > ')
|
|
40
|
+
: selected
|
|
41
|
+
? selected.selector
|
|
42
|
+
: '';
|
|
43
|
+
const nextTheme = theme === 'dark' ? 'light' : 'dark';
|
|
44
|
+
|
|
45
|
+
// P5 (Plan C) — always-on hub-sync slot. `/_sync-status` returns one of three
|
|
46
|
+
// shapes: solo `{linked:false}` (hide), DDR-060 `{notSyncable,tsxCount,reason}`
|
|
47
|
+
// (linked but 0 syncable), or the connection-state machine `{state,queuedOps,
|
|
48
|
+
// flash,…}` (the common linked case the old notSyncable-only guard never
|
|
49
|
+
// showed — the "hub sync se neukazuje" bug).
|
|
50
|
+
//
|
|
51
|
+
// The mapping used to live here, and it referenced `docs` ZERO times: it read
|
|
52
|
+
// `state` alone, so a link whose every document the hub had refused still
|
|
53
|
+
// showed a green dot and the word "synced". `syncPresentation` is now the one
|
|
54
|
+
// rule, shared with the cloud rail's connect note, so the two surfaces cannot
|
|
55
|
+
// give a person different answers about the same payload.
|
|
56
|
+
const syncSlot = (() => {
|
|
57
|
+
const p = syncPresentation(syncStatus, { project: syncProject });
|
|
58
|
+
if (!p) return null;
|
|
59
|
+
const detail = p.names.length ? ` (${p.names.join(', ')})` : '';
|
|
60
|
+
return {
|
|
61
|
+
online: p.online,
|
|
62
|
+
phase: p.phase,
|
|
63
|
+
label: p.label,
|
|
64
|
+
title: `${p.title}${detail}${p.next ? ` — ${p.next}` : ''}`,
|
|
65
|
+
};
|
|
66
|
+
})();
|
|
67
|
+
// One body for both chip forms (button vs plain span) below.
|
|
68
|
+
const syncSlotBody = syncSlot && (
|
|
69
|
+
<>
|
|
70
|
+
<span
|
|
71
|
+
className={'st-sb-sync-dot' + (syncSlot.online ? ' is-online' : '')}
|
|
72
|
+
aria-hidden="true"
|
|
73
|
+
/>
|
|
74
|
+
<span className="lbl">hub sync</span>
|
|
75
|
+
<span
|
|
76
|
+
className="val"
|
|
77
|
+
title={syncSlot.title}
|
|
78
|
+
data-testid="statusbar-sync"
|
|
79
|
+
data-phase={syncSlot.phase}
|
|
80
|
+
>
|
|
81
|
+
{syncSlot.label}
|
|
82
|
+
</span>
|
|
83
|
+
</>
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<footer className="st-statusbar" role="contentinfo" data-testid="statusbar">
|
|
88
|
+
<span className="st-sb-slot st-sb-active" role="group" aria-label="Active file">
|
|
89
|
+
<span className="lead" aria-hidden="true" />
|
|
90
|
+
<span className="lbl">active</span>
|
|
91
|
+
<span className="val" title={activePath || ''}>
|
|
92
|
+
{isSystem ? '▦ design system' : activePath || '—'}
|
|
93
|
+
</span>
|
|
94
|
+
</span>
|
|
95
|
+
|
|
96
|
+
{/* Selection is meaningless without an open canvas — a stale _active.json
|
|
97
|
+
selection used to leave a ghost SELECTED chip on the empty shell. */}
|
|
98
|
+
{activePath && selected && selected.selector && !isSystem && (
|
|
99
|
+
<span className="st-sb-slot st-sb-sel" role="group" aria-label="Selected element">
|
|
100
|
+
<span className="lbl">selected</span>
|
|
101
|
+
<span className="val" title={title}>
|
|
102
|
+
{text}
|
|
103
|
+
</span>
|
|
104
|
+
<button
|
|
105
|
+
type="button"
|
|
106
|
+
className="st-sb-sel-clear"
|
|
107
|
+
onClick={onClearSelected}
|
|
108
|
+
data-tip="Clear · Esc inside iframe"
|
|
109
|
+
data-tip-pos="top"
|
|
110
|
+
aria-label="Clear selection"
|
|
111
|
+
>
|
|
112
|
+
×
|
|
113
|
+
</button>
|
|
114
|
+
</span>
|
|
115
|
+
)}
|
|
116
|
+
|
|
117
|
+
<span className="st-sb-slot" role="group" aria-label="Open comments">
|
|
118
|
+
<span className="lbl">comments</span>
|
|
119
|
+
<span className="val">{openCount} open</span>
|
|
120
|
+
</span>
|
|
121
|
+
|
|
122
|
+
{/* Phase 28 — changes count, click to open the Changes panel (⌘⇧G). */}
|
|
123
|
+
{onOpenChanges && (
|
|
124
|
+
<button
|
|
125
|
+
type="button"
|
|
126
|
+
className={
|
|
127
|
+
'st-sb-slot st-sb-changes' +
|
|
128
|
+
(changesOpen ? ' is-open' : '') +
|
|
129
|
+
(changesCount > 0 ? ' has-changes' : unpushed > 0 ? ' has-unpushed' : '')
|
|
130
|
+
}
|
|
131
|
+
onClick={onOpenChanges}
|
|
132
|
+
data-testid="open-changes"
|
|
133
|
+
data-tip="Open Changes · ⌘⇧G"
|
|
134
|
+
data-tip-pos="top"
|
|
135
|
+
aria-label="Open Changes panel"
|
|
136
|
+
aria-pressed={changesOpen}
|
|
137
|
+
>
|
|
138
|
+
<span className="st-sb-changes-dot" aria-hidden="true" />
|
|
139
|
+
<span className="lbl">changes</span>
|
|
140
|
+
<span className="val">
|
|
141
|
+
{savingIsManaged
|
|
142
|
+
? // Not "all saved": assets and project config are written into the
|
|
143
|
+
// cell's checkout but never committed there, so asserting a clean
|
|
144
|
+
// save would overstate what the cloud actually holds. Naming the
|
|
145
|
+
// mechanism is both honest and the thing the user needs to know.
|
|
146
|
+
'cloud saving'
|
|
147
|
+
: changesCount > 0
|
|
148
|
+
? `${changesCount} unsaved`
|
|
149
|
+
: unpushed > 0
|
|
150
|
+
? `${unpushed} to publish`
|
|
151
|
+
: 'all saved'}
|
|
152
|
+
</span>
|
|
153
|
+
</button>
|
|
154
|
+
)}
|
|
155
|
+
|
|
156
|
+
<span className="st-sb-spacer" />
|
|
157
|
+
|
|
158
|
+
<span className="st-sb-slot" role="group" aria-label="Connection">
|
|
159
|
+
<span className={'st-live-dot' + (wsConnected ? ' is-connected' : '')} aria-hidden="true" />
|
|
160
|
+
<span className="lbl">{wsConnected ? 'live' : 'reconnecting'}</span>
|
|
161
|
+
</span>
|
|
162
|
+
|
|
163
|
+
{/* P5 (Plan C) — always-on hub-sync slot (was notSyncable-only per DDR-060
|
|
164
|
+
/ 9.1-D). Now also surfaces the connection-state machine's queued/synced
|
|
165
|
+
counter for the common linked case. Solo projects render nothing.
|
|
166
|
+
feature-sync-progress-modal — a BUTTON that toggles the per-file Sync
|
|
167
|
+
panel (like the Changes chip toggles GitPanel); the plain-span form
|
|
168
|
+
stays for servers/sessions that pass no handler. */}
|
|
169
|
+
{syncSlot &&
|
|
170
|
+
(onOpenSync ? (
|
|
171
|
+
<button
|
|
172
|
+
type="button"
|
|
173
|
+
className={'st-sb-slot st-sb-sync st-sb-sync--btn' + (syncOpen ? ' is-open' : '')}
|
|
174
|
+
onClick={onOpenSync}
|
|
175
|
+
data-testid="open-sync"
|
|
176
|
+
data-tip="Open Sync panel"
|
|
177
|
+
data-tip-pos="top"
|
|
178
|
+
aria-label="Open Sync panel"
|
|
179
|
+
aria-pressed={syncOpen}
|
|
180
|
+
>
|
|
181
|
+
{syncSlotBody}
|
|
182
|
+
</button>
|
|
183
|
+
) : (
|
|
184
|
+
<span className="st-sb-slot st-sb-sync" role="group" aria-label="Hub sync">
|
|
185
|
+
{syncSlotBody}
|
|
186
|
+
</span>
|
|
187
|
+
))}
|
|
188
|
+
|
|
189
|
+
{/* Which release this is. Reading it used to mean probing production by
|
|
190
|
+
hand — and the desktop, the browser and a cloud tab all serve the same
|
|
191
|
+
client, so one slot covers all three. Absent on an older server that
|
|
192
|
+
omits `version` from /_config, exactly as `cloud` and `canvasToken`
|
|
193
|
+
already are. */}
|
|
194
|
+
{version && (
|
|
195
|
+
<span className="st-sb-slot st-sb-version" role="group" aria-label="Maude version">
|
|
196
|
+
<span className="val" data-testid="statusbar-version">
|
|
197
|
+
v{version}
|
|
198
|
+
</span>
|
|
199
|
+
</span>
|
|
200
|
+
)}
|
|
201
|
+
|
|
202
|
+
<button
|
|
203
|
+
type="button"
|
|
204
|
+
className="st-sb-theme"
|
|
205
|
+
onClick={onToggleTheme}
|
|
206
|
+
data-tip={`Switch to ${nextTheme} theme`}
|
|
207
|
+
data-tip-pos="top"
|
|
208
|
+
aria-label={`Switch to ${nextTheme} theme`}
|
|
209
|
+
>
|
|
210
|
+
<StIcon name={theme === 'dark' ? 'sun' : 'moon'} size={13} />
|
|
211
|
+
{nextTheme}
|
|
212
|
+
</button>
|
|
213
|
+
</footer>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
// shell/util.js — moved verbatim out of client/app.jsx (Maude v2 plan V2-0.2, move-only split).
|
|
2
|
+
|
|
3
|
+
import { CANVAS_EXT_RE, MODE_HINT_SEEN, THEME_STORE } from './constants.js';
|
|
4
|
+
import { invoke, isNativeApp } from '../github.js';
|
|
5
|
+
import { dismissNotice, notify } from '../../notifications.tsx';
|
|
6
|
+
|
|
7
|
+
// feature-unified-settings-modal — the Settings modal's view prefs are ALSO
|
|
8
|
+
// persisted to disk (~/.config/maude/prefs.json via /_api/ui-prefs), so they
|
|
9
|
+
// survive a restart even if localStorage is cleared (the native WKWebView
|
|
10
|
+
// case). localStorage stays the synchronous init source (no boot flash); disk
|
|
11
|
+
// is the durable, cross-restart source of truth reconciled on mount.
|
|
12
|
+
export function persistUiPrefs(patch) {
|
|
13
|
+
try {
|
|
14
|
+
fetch('/_api/ui-prefs', {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
headers: { 'content-type': 'text/plain' },
|
|
17
|
+
body: JSON.stringify(patch),
|
|
18
|
+
}).catch(() => {});
|
|
19
|
+
} catch {}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// feature-studio-file-preview — classifies a non-canvas tree row so FileRow
|
|
23
|
+
// can open an inline preview instead of the old inert no-op. Kept in sync
|
|
24
|
+
// with apps/studio/api.ts's PREVIEW_ASSET_EXTS (server won't list anything
|
|
25
|
+
// outside this set anyway, but the client stays explicit rather than
|
|
26
|
+
// assuming server-side filtering).
|
|
27
|
+
export const PREVIEW_KIND_RULES = [
|
|
28
|
+
[/\.md$/i, 'markdown'],
|
|
29
|
+
[/\.(css|json|txt|ya?ml)$/i, 'text'],
|
|
30
|
+
[/\.(svg|png|jpe?g|gif|webp|avif)$/i, 'image'],
|
|
31
|
+
[/\.(mp4|webm|mov)$/i, 'video'],
|
|
32
|
+
[/\.(mp3|wav|ogg|m4a)$/i, 'audio'],
|
|
33
|
+
[/\.(woff2?|ttf|otf)$/i, 'font'],
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
export function previewKind(name) {
|
|
37
|
+
for (const [re, kind] of PREVIEW_KIND_RULES) if (re.test(name)) return kind;
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Shared testid-slug derivation (desktop-e2e skill convention: kebab-case,
|
|
42
|
+
// designRoot-stripped, extension-stripped) — mirrors FileRow's inline
|
|
43
|
+
// `canvas-row-<slug>` computation so DirRow / the row-menu trigger use the
|
|
44
|
+
// SAME shape for `tree-folder-<slug>` / `tree-row-menu-<slug>`.
|
|
45
|
+
export function pathTestIdSlug(p) {
|
|
46
|
+
return p
|
|
47
|
+
.replace(/^\.[^/]+\//, '')
|
|
48
|
+
.replace(CANVAS_EXT_RE, '')
|
|
49
|
+
.replace(/[^a-z0-9]+/gi, '-')
|
|
50
|
+
.toLowerCase()
|
|
51
|
+
.replace(/^-+|-+$/g, '');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// A layers tree's identity: its element ids in document order. Two trees with
|
|
55
|
+
// the same signature are the same DOM as far as positional ids go.
|
|
56
|
+
export function layersTreeSig(nodes) {
|
|
57
|
+
const ids = [];
|
|
58
|
+
(function walk(list) {
|
|
59
|
+
for (const n of list || []) {
|
|
60
|
+
ids.push(n?.id ?? '');
|
|
61
|
+
walk(n?.children);
|
|
62
|
+
}
|
|
63
|
+
})(nodes);
|
|
64
|
+
return ids.join(',');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Best-effort OS notification — shared by handleAssistantFinished and
|
|
68
|
+
// handleAssistantAttention below (identical support/permission check +
|
|
69
|
+
// try/catch, only the title/body differ). The in-app badge stays the
|
|
70
|
+
// reliable signal if this silently fails for any reason.
|
|
71
|
+
//
|
|
72
|
+
// feature-acp-turn-notifications Task 6 — under Tauri, route through the
|
|
73
|
+
// native `send_notification` command (notify.rs) instead of the Web `Notification` API.
|
|
74
|
+
// This is the SAME native notifier the shell's cross-project poller uses for
|
|
75
|
+
// every OTHER project, so the visible project now goes through the identical
|
|
76
|
+
// OS-level path rather than a webview API whose behavior inside WKWebView was
|
|
77
|
+
// never empirically confirmed (see Task 1's finding in the plan). Falls back
|
|
78
|
+
// to the Web API on any failure — an older desktop build without the command,
|
|
79
|
+
// or a plain browser tab — so the signal degrades rather than disappearing.
|
|
80
|
+
export function notifyDesktop(title, body) {
|
|
81
|
+
const webFallback = () => {
|
|
82
|
+
try {
|
|
83
|
+
if (typeof Notification !== 'undefined' && Notification.permission === 'granted') {
|
|
84
|
+
new Notification(title, { body });
|
|
85
|
+
}
|
|
86
|
+
} catch {
|
|
87
|
+
/* best-effort — the in-app badge is the reliable signal */
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
if (isNativeApp()) {
|
|
91
|
+
invoke('send_notification', { title, body }).catch(webFallback);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
webFallback();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function readInitialTheme() {
|
|
98
|
+
if (typeof window === 'undefined') return 'dark';
|
|
99
|
+
try {
|
|
100
|
+
const stored = localStorage.getItem(THEME_STORE);
|
|
101
|
+
if (stored === 'light' || stored === 'dark') return stored;
|
|
102
|
+
} catch {}
|
|
103
|
+
// Match the data-theme attribute index.html ships with (dark).
|
|
104
|
+
return 'dark';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function readBoolStore(key, fallback) {
|
|
108
|
+
if (typeof window === 'undefined') return fallback;
|
|
109
|
+
try {
|
|
110
|
+
const v = localStorage.getItem(key);
|
|
111
|
+
if (v === '1') return true;
|
|
112
|
+
if (v === '0') return false;
|
|
113
|
+
} catch {}
|
|
114
|
+
return fallback;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function readJsonStore(key, fallback) {
|
|
118
|
+
if (typeof window === 'undefined') return fallback;
|
|
119
|
+
try {
|
|
120
|
+
const v = localStorage.getItem(key);
|
|
121
|
+
return v ? JSON.parse(v) : fallback;
|
|
122
|
+
} catch {
|
|
123
|
+
return fallback;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Section default-open: EVERY section starts collapsed (issue #124 — "default
|
|
128
|
+
// should be collapsed"). The user's per-section choice is remembered per
|
|
129
|
+
// project by useTreeExpansion (tree-expansion.js), next to the folder state.
|
|
130
|
+
export function sectionDefaultOpen() {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ---------- Utility ----------
|
|
135
|
+
|
|
136
|
+
// Iframe src for a canvas path. TSX canvases go through _canvas-shell.html so
|
|
137
|
+
// the bundled React 19 runtime + importmap can mount the default export. HTML
|
|
138
|
+
// canvases keep the legacy "serve the file with inspector + Babel injected"
|
|
139
|
+
// path. Phase 3.6 contract; the path argument is repo-root-relative
|
|
140
|
+
// (e.g. ".design/ui/Foo.tsx"). Pure resolver extracted to ./canvas-url.js so
|
|
141
|
+
// the token-resolution branches are unit-testable without a DOM (DDR-093).
|
|
142
|
+
|
|
143
|
+
export function basename(p) {
|
|
144
|
+
return p.split('/').pop();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Keep call sites (including Undo actions) on the shared notification stack.
|
|
148
|
+
export function shellToast(message, ok = false, action) {
|
|
149
|
+
notify({ title: message, kind: ok ? 'success' : 'error', action });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function browseFirstRunHint(readOnly = false) {
|
|
153
|
+
if (typeof document === 'undefined' || typeof localStorage === 'undefined') return;
|
|
154
|
+
try {
|
|
155
|
+
if (localStorage.getItem(MODE_HINT_SEEN) === '1') return;
|
|
156
|
+
} catch {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (browseFirstRunHint.active) return;
|
|
160
|
+
browseFirstRunHint.active = true;
|
|
161
|
+
const dismiss = () => {
|
|
162
|
+
browseFirstRunHint.active = false;
|
|
163
|
+
try { localStorage.setItem(MODE_HINT_SEEN, '1'); } catch {}
|
|
164
|
+
document.removeEventListener('keydown', onV, true);
|
|
165
|
+
};
|
|
166
|
+
const onV = (e) => {
|
|
167
|
+
if ((e.key === 'v' || e.key === 'V') && !e.metaKey && !e.ctrlKey && !e.altKey) {
|
|
168
|
+
dismissNotice('mode-hint');
|
|
169
|
+
dismiss();
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
if (readOnly) document.addEventListener('keydown', onV, true);
|
|
173
|
+
notify({ id: 'mode-hint', title: readOnly ? 'Your mock is live' : 'You’re in Edit',
|
|
174
|
+
description: readOnly ? 'Click things to try it. Press V to select & inspect.'
|
|
175
|
+
: 'Click selects, like Figma. Switch to Preview in the toolbar to use the live mock.',
|
|
176
|
+
onDismiss: dismiss });
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Strip canvas extensions for display. `Canvas Viewport.tsx` → `Canvas Viewport`.
|
|
180
|
+
// Sidecars (`.meta.json`, `.css`, `.registry.json`) keep their extensions so
|
|
181
|
+
// the file type stays unambiguous.
|
|
182
|
+
export function displayName(name) {
|
|
183
|
+
return name.replace(CANVAS_EXT_RE, '');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Primary base = name with the canvas extension stripped. `Canvas Viewport.tsx`
|
|
187
|
+
// → `Canvas Viewport`. A sidecar belongs to that primary when its name starts
|
|
188
|
+
// with `<base>.` — so `Canvas Viewport.meta.json` and `Canvas Viewport.css`
|
|
189
|
+
// both nest under `Canvas Viewport.tsx`. Naïve single-extension stripping
|
|
190
|
+
// breaks for multi-dot sidecars like `*.meta.json`.
|
|
191
|
+
export function canvasBase(name) {
|
|
192
|
+
return name.replace(CANVAS_EXT_RE, '');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Group flat file list into { primary: canvas, sidecars: [...] }. Sidecars
|
|
196
|
+
// share the primary base + `.` prefix and don't themselves match the canvas
|
|
197
|
+
// extension regex. Orphans (no canvas peer at this dir level) come back as
|
|
198
|
+
// `{ primary: orphan, sidecars: [], orphan: true }` so the caller can gate
|
|
199
|
+
// them on `showHidden`.
|
|
200
|
+
export function groupBySidecar(files) {
|
|
201
|
+
// Pass 1 — claim primaries; prefer .tsx over .html on tie.
|
|
202
|
+
const primaryByBase = new Map();
|
|
203
|
+
for (const f of files) {
|
|
204
|
+
if (!CANVAS_EXT_RE.test(f.name)) continue;
|
|
205
|
+
const base = canvasBase(f.name);
|
|
206
|
+
if (!primaryByBase.has(base) || /\.tsx$/i.test(f.name)) primaryByBase.set(base, f);
|
|
207
|
+
}
|
|
208
|
+
// Pass 2 — match non-canvas files to the longest primary base they prefix.
|
|
209
|
+
const sidecarsByBase = new Map();
|
|
210
|
+
const orphans = [];
|
|
211
|
+
for (const f of files) {
|
|
212
|
+
if (CANVAS_EXT_RE.test(f.name)) continue;
|
|
213
|
+
let matched = null;
|
|
214
|
+
for (const base of primaryByBase.keys()) {
|
|
215
|
+
if (f.name === base) continue;
|
|
216
|
+
if (f.name.startsWith(`${base}.`)) {
|
|
217
|
+
if (!matched || base.length > matched.length) matched = base;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (matched) {
|
|
221
|
+
const list = sidecarsByBase.get(matched) || [];
|
|
222
|
+
list.push(f);
|
|
223
|
+
sidecarsByBase.set(matched, list);
|
|
224
|
+
} else {
|
|
225
|
+
orphans.push(f);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const canvases = [];
|
|
229
|
+
for (const [base, primary] of primaryByBase) {
|
|
230
|
+
const sidecars = (sidecarsByBase.get(base) || []).sort((a, b) => a.name.localeCompare(b.name));
|
|
231
|
+
canvases.push({ primary, sidecars, orphan: false });
|
|
232
|
+
}
|
|
233
|
+
canvases.sort((a, b) => a.primary.name.localeCompare(b.primary.name));
|
|
234
|
+
orphans.sort((a, b) => a.name.localeCompare(b.name));
|
|
235
|
+
return {
|
|
236
|
+
canvases,
|
|
237
|
+
orphans: orphans.map((f) => ({ primary: f, sidecars: [], orphan: true })),
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// `dirs` (feature-file-tree-drag-drop-folders, Task 7) — group-relative dir
|
|
242
|
+
// paths from the server's /_index-data payload, same shape as `paths`. Seeded
|
|
243
|
+
// FIRST so an empty folder (no files inside yet) still gets a node — without
|
|
244
|
+
// this a freshly `mkdir`'d folder would be invisible until something landed
|
|
245
|
+
// inside it, since the tree is otherwise built entirely from file paths.
|
|
246
|
+
export function buildTree(paths, stripPrefix, dirs) {
|
|
247
|
+
const root = {};
|
|
248
|
+
for (const d of dirs || []) {
|
|
249
|
+
const stripped = d.startsWith(stripPrefix) ? d.slice(stripPrefix.length).replace(/^\/+/, '') : d;
|
|
250
|
+
const parts = stripped.split('/').filter(Boolean);
|
|
251
|
+
let node = root;
|
|
252
|
+
for (const key of parts) node = node[key] = node[key] || {};
|
|
253
|
+
node._files = node._files || [];
|
|
254
|
+
}
|
|
255
|
+
for (const p of paths) {
|
|
256
|
+
const stripped = p.startsWith(stripPrefix)
|
|
257
|
+
? p.slice(stripPrefix.length).replace(/^\/+/, '')
|
|
258
|
+
: p;
|
|
259
|
+
const parts = stripped.split('/');
|
|
260
|
+
let node = root;
|
|
261
|
+
for (let i = 0; i < parts.length; i++) {
|
|
262
|
+
const key = parts[i];
|
|
263
|
+
const isFile = i === parts.length - 1;
|
|
264
|
+
if (isFile) {
|
|
265
|
+
node._files = node._files || [];
|
|
266
|
+
node._files.push({ name: key, path: p });
|
|
267
|
+
} else {
|
|
268
|
+
node[key] = node[key] || {};
|
|
269
|
+
node = node[key];
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return root;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export function filterTree(node, query) {
|
|
277
|
+
if (!query) return node;
|
|
278
|
+
const q = query.toLowerCase();
|
|
279
|
+
const out = {};
|
|
280
|
+
let any = false;
|
|
281
|
+
const dirs = Object.keys(node).filter((k) => k !== '_files');
|
|
282
|
+
for (const d of dirs) {
|
|
283
|
+
const filtered = filterTree(node[d], query);
|
|
284
|
+
if (filtered) {
|
|
285
|
+
out[d] = filtered;
|
|
286
|
+
any = true;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (node._files) {
|
|
290
|
+
const files = node._files.filter(
|
|
291
|
+
(f) => f.name.toLowerCase().includes(q) || f.path.toLowerCase().includes(q)
|
|
292
|
+
);
|
|
293
|
+
if (files.length) {
|
|
294
|
+
out._files = files;
|
|
295
|
+
any = true;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return any ? out : null;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export function openCount(comments) {
|
|
302
|
+
return (comments || []).filter((c) => c.status !== 'resolved').length;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export function timeAgo(iso) {
|
|
306
|
+
if (!iso) return '';
|
|
307
|
+
const t = new Date(iso).getTime();
|
|
308
|
+
if (!t) return '';
|
|
309
|
+
const s = Math.max(0, Math.floor((Date.now() - t) / 1000));
|
|
310
|
+
if (s < 60) return s + 's';
|
|
311
|
+
const m = Math.floor(s / 60);
|
|
312
|
+
if (m < 60) return m + 'm';
|
|
313
|
+
const h = Math.floor(m / 60);
|
|
314
|
+
if (h < 24) return h + 'h';
|
|
315
|
+
const d = Math.floor(h / 24);
|
|
316
|
+
if (d < 7) return d + 'd';
|
|
317
|
+
return new Date(iso).toLocaleDateString();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export function totalCounts(commentsByFile) {
|
|
321
|
+
let all = 0,
|
|
322
|
+
open = 0,
|
|
323
|
+
resolved = 0;
|
|
324
|
+
for (const list of Object.values(commentsByFile || {})) {
|
|
325
|
+
for (const c of list || []) {
|
|
326
|
+
all++;
|
|
327
|
+
if (c.status === 'resolved') resolved++;
|
|
328
|
+
else open++;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return { all, open, resolved };
|
|
332
|
+
}
|