moi-computer 0.6.1-next.0 → 0.8.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.
- package/README.md +2 -2
- package/client/components/shared/BottomPanel.tsx +2 -1
- package/client/components/shared/PanelHeader.tsx +1 -1
- package/client/features/applets/AppletMount.tsx +9 -22
- package/client/features/applets/applet-cache.ts +7 -0
- package/client/features/applets/applet-styles.ts +21 -1
- package/client/features/applets/useApplet.ts +1 -1
- package/client/features/chat/ChatComposer.tsx +18 -4
- package/client/features/chat/ChatSelector.tsx +1 -1
- package/client/features/chat/TurnView.tsx +1 -1
- package/client/features/home/api.ts +0 -10
- package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +21 -64
- package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +1 -1
- package/client/features/scratchpad/Scratchpad.tsx +1 -3
- package/client/features/views/ViewManager.tsx +258 -0
- package/client/features/views/view-residency.ts +77 -0
- package/client/features/widgets/WidgetFrame.tsx +6 -2
- package/client/features/workspace/CustomizePanel.tsx +40 -24
- package/client/features/workspace/WorkspaceLayoutContext.tsx +8 -0
- package/client/features/workspace/WorkspaceScreen.tsx +51 -103
- package/client/features/workspace/WorkspaceTabs.tsx +1 -1
- package/client/index.css +4 -1
- package/client/runtime/workspace-theme.ts +29 -10
- package/client/theme.css +96 -6
- package/dist/chunk-0k7brsms.js +9 -0
- package/dist/{chunk-m11ckkxd.js → chunk-dtwxpxbg.js} +1 -1
- package/dist/{chunk-55sh4dty.js → chunk-ga7t9qsk.js} +1 -1
- package/dist/{chunk-w3tnv51j.js → chunk-h9h8f176.js} +1 -1
- package/dist/{chunk-rxvx4ta9.js → chunk-r5ce5cdg.js} +2 -2
- package/dist/chunk-tey2nq7c.js +31 -0
- package/dist/{chunk-afgbg75t.js → chunk-z73xpsa0.js} +1 -1
- package/dist/chunk-zzgredta.css +1 -0
- package/dist/index.html +1 -1
- package/lib/format.ts +18 -4
- package/lib/system-messages.ts +241 -0
- package/lib/themes.ts +123 -51
- package/lib/types.ts +2 -5
- package/package.json +5 -4
- package/server/api.ts +2 -73
- package/server/bundler/build-applet.ts +7 -4
- package/server/cli.ts +46 -15
- package/server/control.ts +13 -6
- package/server/harness/README.md +11 -0
- package/server/harness/claude-code/NOTES.md +22 -7
- package/server/harness/claude-code/adapter.ts +39 -5
- package/server/moi-scaffold.ts +1 -1
- package/server/registry.ts +0 -20
- package/server/scratchpad-executor.ts +23 -1
- package/server/theme.ts +24 -27
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +94 -57
- package/workspace/.claude/skills/moi-workspace/SKILL.md +10 -12
- package/dist/chunk-175bm057.js +0 -27
- package/dist/chunk-agtetn7n.css +0 -1
- package/dist/chunk-exj6hr30.js +0 -9
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// The workspace's view surface: every view the user has open lives here, and
|
|
2
|
+
// switching tabs picks one of them instead of tearing the old one down and
|
|
3
|
+
// building the new one up.
|
|
4
|
+
//
|
|
5
|
+
// Why no transition between views: a view is an agent-authored bundle with its
|
|
6
|
+
// own styles and its own state. Animating the swap means keeping the outgoing
|
|
7
|
+
// DOM alive past the moment React drops the applet's <style> tag, so the view
|
|
8
|
+
// spends its exit unstyled. Keeping views mounted removes the problem instead
|
|
9
|
+
// of timing around it — the switch is instant, and a view only ever loads once.
|
|
10
|
+
//
|
|
11
|
+
// The one animation left is the rebuild dissolve: when the view you are looking
|
|
12
|
+
// at is rebuilt, the new build fades in over the old one. That is safe here
|
|
13
|
+
// because both builds share the slot's style tag (see ViewSlot), and it is
|
|
14
|
+
// worth the 200ms — it is the only signal that the thing under your cursor just
|
|
15
|
+
// changed underneath you.
|
|
16
|
+
import { Activity, type ComponentType, useCallback, useEffect, useRef, useState } from 'react'
|
|
17
|
+
|
|
18
|
+
import { Spinner } from '@/client/components/ui/spinner'
|
|
19
|
+
import { appletScope, appletStyleKey } from '@/client/features/applets/applet-cache'
|
|
20
|
+
import { useAppletStyle } from '@/client/features/applets/applet-styles'
|
|
21
|
+
import {
|
|
22
|
+
type AppletComponentProps,
|
|
23
|
+
type AppletState,
|
|
24
|
+
useView
|
|
25
|
+
} from '@/client/features/applets/useApplet'
|
|
26
|
+
import { WidgetErrorBoundary } from '@/client/features/applets/WidgetErrorBoundary'
|
|
27
|
+
import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
|
|
28
|
+
import { cn } from '@/client/lib/cn'
|
|
29
|
+
import type { ViewInfo } from '@/lib/types'
|
|
30
|
+
|
|
31
|
+
import {
|
|
32
|
+
nextEvictionDelay,
|
|
33
|
+
reconcileResidents,
|
|
34
|
+
type ResidentView,
|
|
35
|
+
sameResidents
|
|
36
|
+
} from './view-residency'
|
|
37
|
+
|
|
38
|
+
type ViewManagerProps = {
|
|
39
|
+
views: ViewInfo[]
|
|
40
|
+
// The view the active tab names, or null when another tab is on screen. The
|
|
41
|
+
// manager stays mounted either way — that is what makes coming back from the
|
|
42
|
+
// agent or widgets tab instant too.
|
|
43
|
+
activeViewId: string | null
|
|
44
|
+
// The active view's addressable state, read from navigation state (focusTab /
|
|
45
|
+
// `moi tab focus`). `{}` on a fresh mount, a new browser tab, or a plain
|
|
46
|
+
// tab-bar click — a view must render sensibly with that.
|
|
47
|
+
params: Record<string, unknown>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function ViewManager({ views, activeViewId, params }: ViewManagerProps) {
|
|
51
|
+
const residents = useResidentViews(activeViewId, views)
|
|
52
|
+
// Render in workspace order, not residency order: the policy ranks views by
|
|
53
|
+
// recency, and reordering the children would make React move live DOM around
|
|
54
|
+
// on every switch. The slots are stacked absolutely with one visible, so
|
|
55
|
+
// their order on the page carries no meaning.
|
|
56
|
+
const resident = new Set(residents.map(entry => entry.id))
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
// Hidden rather than unmounted when no view tab is on screen: the parked
|
|
60
|
+
// views keep their DOM, and `display: none` keeps this layer out of the
|
|
61
|
+
// layout and out of the way of pointer events on the tab that IS on screen.
|
|
62
|
+
<div className={cn('relative min-h-0 flex-1 overflow-hidden', !activeViewId && 'hidden')}>
|
|
63
|
+
{views
|
|
64
|
+
.filter(view => resident.has(view.id))
|
|
65
|
+
.map(view => (
|
|
66
|
+
<ViewSlot key={view.id} view={view} active={view.id === activeViewId} params={params} />
|
|
67
|
+
))}
|
|
68
|
+
</div>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// The views mounted right now: the active one, plus the recently-visited ones
|
|
73
|
+
// parked offscreen. The policy (and its timing) lives in view-residency.ts.
|
|
74
|
+
function useResidentViews(activeId: string | null, views: ViewInfo[]): ResidentView[] {
|
|
75
|
+
const [residents, setResidents] = useState<ResidentView[]>([])
|
|
76
|
+
// A workspace refetch hands us a new array on every event; residency only
|
|
77
|
+
// cares whether a view appeared or disappeared. So the effect keys off the id
|
|
78
|
+
// set, and the reconcile reads the current list through the ref.
|
|
79
|
+
const viewsRef = useRef(views)
|
|
80
|
+
viewsRef.current = views
|
|
81
|
+
const availableIds = views.map(view => view.id).join('\n')
|
|
82
|
+
|
|
83
|
+
const reconcile = useCallback(() => {
|
|
84
|
+
setResidents(current => {
|
|
85
|
+
const next = reconcileResidents(current, {
|
|
86
|
+
activeId,
|
|
87
|
+
available: new Set(viewsRef.current.map(view => view.id)),
|
|
88
|
+
now: Date.now()
|
|
89
|
+
})
|
|
90
|
+
return sameResidents(current, next) ? current : next
|
|
91
|
+
})
|
|
92
|
+
}, [activeId])
|
|
93
|
+
|
|
94
|
+
// Promote the view the user switched to, and release the one it replaced.
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
reconcile()
|
|
97
|
+
}, [availableIds, reconcile])
|
|
98
|
+
|
|
99
|
+
// Then evict on the retention deadline — one timer, for the nearest one.
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
const delay = nextEvictionDelay(residents, Date.now())
|
|
102
|
+
if (delay === null) return
|
|
103
|
+
const timer = setTimeout(reconcile, delay)
|
|
104
|
+
return () => clearTimeout(timer)
|
|
105
|
+
}, [reconcile, residents])
|
|
106
|
+
|
|
107
|
+
return residents
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
type ViewSlotProps = {
|
|
111
|
+
view: ViewInfo
|
|
112
|
+
active: boolean
|
|
113
|
+
params: Record<string, unknown>
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// One resident view. The bundle it holds is loaded and kept fresh for as long
|
|
117
|
+
// as the slot lives — a view rebuilt while parked picks the new build up in
|
|
118
|
+
// place, so it is current the moment the user comes back to it.
|
|
119
|
+
function ViewSlot({ view, active, params }: ViewSlotProps) {
|
|
120
|
+
const workspaceId = useWorkspaceId()
|
|
121
|
+
const bundle = useView(view.id)
|
|
122
|
+
const { current, outgoing } = useLoadedBundle(bundle, active)
|
|
123
|
+
// A parked view keeps rendering with the params it was last shown with: the
|
|
124
|
+
// active view's `focusTab` state is not its to render.
|
|
125
|
+
const [shownParams, setShownParams] = useState(params)
|
|
126
|
+
if (active && shownParams !== params) setShownParams(params)
|
|
127
|
+
|
|
128
|
+
// The applet's <style> is acquired HERE, outside the Activity below. Hiding
|
|
129
|
+
// an Activity unmounts its children's effects, which would strip the styles
|
|
130
|
+
// off the page while the DOM they style is still parked — the exact flash
|
|
131
|
+
// this component exists to remove. The tag drops when the slot is evicted.
|
|
132
|
+
// Holding it here is also what lets the dissolve below overlap two builds:
|
|
133
|
+
// the styles belong to the slot, not to either frame. The active view's sheet
|
|
134
|
+
// is raised to the end of <head> so the global at-rule names it shares with
|
|
135
|
+
// the parked views resolve to the one on screen.
|
|
136
|
+
useAppletStyle(
|
|
137
|
+
appletStyleKey('views', workspaceId, view.id),
|
|
138
|
+
current?.version ?? bundle.version,
|
|
139
|
+
active
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
const failed = bundle.status === 'error'
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<>
|
|
146
|
+
{active && failed && (
|
|
147
|
+
<p className="absolute inset-0 p-4 text-xs text-destructive">{bundle.error}</p>
|
|
148
|
+
)}
|
|
149
|
+
{active && !failed && !current && <ViewSplash />}
|
|
150
|
+
{current &&
|
|
151
|
+
!failed && (
|
|
152
|
+
// React hides these nodes with `display: none` while the Activity is
|
|
153
|
+
// hidden, so a parked view neither paints nor swallows clicks.
|
|
154
|
+
<Activity mode={active ? 'visible' : 'hidden'}>
|
|
155
|
+
{outgoing && (
|
|
156
|
+
<ViewFrame key={outgoing.version} view={view} build={outgoing} params={shownParams} />
|
|
157
|
+
)}
|
|
158
|
+
<ViewFrame
|
|
159
|
+
key={current.version}
|
|
160
|
+
view={view}
|
|
161
|
+
build={current}
|
|
162
|
+
params={shownParams}
|
|
163
|
+
entering={outgoing !== null}
|
|
164
|
+
/>
|
|
165
|
+
</Activity>
|
|
166
|
+
)}
|
|
167
|
+
</>
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
type ViewFrameProps = {
|
|
172
|
+
view: ViewInfo
|
|
173
|
+
build: ViewBuild
|
|
174
|
+
params: Record<string, unknown>
|
|
175
|
+
// Play the rebuild dissolve. Set on the incoming build only, and only while
|
|
176
|
+
// the build it replaced is still rendered underneath it.
|
|
177
|
+
entering?: boolean
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// One build of one view, in its style scope. Frames stack absolutely, so during
|
|
181
|
+
// a rebuild the incoming one dissolves in over the outgoing one still on screen.
|
|
182
|
+
function ViewFrame({ view, build, params, entering }: ViewFrameProps) {
|
|
183
|
+
const workspaceId = useWorkspaceId()
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<div
|
|
187
|
+
data-applet={appletScope('views', view.id)}
|
|
188
|
+
className={cn(
|
|
189
|
+
'absolute inset-0 overflow-auto',
|
|
190
|
+
entering && 'animate-in duration-200 ease-out blur-in-4 fade-in'
|
|
191
|
+
)}
|
|
192
|
+
>
|
|
193
|
+
<WidgetErrorBoundary
|
|
194
|
+
name={view.id}
|
|
195
|
+
kind="view"
|
|
196
|
+
workspaceId={workspaceId}
|
|
197
|
+
resetKey={build.version}
|
|
198
|
+
>
|
|
199
|
+
<build.Component params={params} />
|
|
200
|
+
</WidgetErrorBoundary>
|
|
201
|
+
</div>
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
type ViewBuild = {
|
|
206
|
+
Component: ComponentType<AppletComponentProps>
|
|
207
|
+
version: number
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
type LoadedBundle = {
|
|
211
|
+
// The build to render, held across reloads. A rebuild flips the bundle back
|
|
212
|
+
// to `loading` for as long as the fetch takes, and swapping a live view for a
|
|
213
|
+
// spinner every time the agent edits it is worse than showing the previous
|
|
214
|
+
// build for that moment. The splash is for a view with nothing to show yet —
|
|
215
|
+
// the first time it is opened.
|
|
216
|
+
current: ViewBuild | null
|
|
217
|
+
// The build `current` just replaced, kept underneath for the length of the
|
|
218
|
+
// dissolve so the new one fades in over the view instead of over an empty
|
|
219
|
+
// panel. Null except during a rebuild swap on screen.
|
|
220
|
+
outgoing: ViewBuild | null
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// How long the outgoing build stays underneath. Matches the `duration-200` the
|
|
224
|
+
// incoming frame animates with.
|
|
225
|
+
const DISSOLVE_MS = 200
|
|
226
|
+
|
|
227
|
+
function useLoadedBundle(bundle: AppletState, dissolve: boolean): LoadedBundle {
|
|
228
|
+
const [loaded, setLoaded] = useState<LoadedBundle>({ current: null, outgoing: null })
|
|
229
|
+
|
|
230
|
+
if (bundle.status === 'ready' && loaded.current?.version !== bundle.version) {
|
|
231
|
+
const build = { Component: bundle.Component, version: bundle.version }
|
|
232
|
+
// The first build of a view has nothing to dissolve from, and a parked view
|
|
233
|
+
// has nobody watching — both swap straight in.
|
|
234
|
+
setLoaded(previous => ({ current: build, outgoing: dissolve ? previous.current : null }))
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
useEffect(() => {
|
|
238
|
+
if (!loaded.outgoing) return
|
|
239
|
+
const timer = setTimeout(
|
|
240
|
+
() => setLoaded(previous => ({ ...previous, outgoing: null })),
|
|
241
|
+
DISSOLVE_MS
|
|
242
|
+
)
|
|
243
|
+
return () => clearTimeout(timer)
|
|
244
|
+
}, [loaded.outgoing])
|
|
245
|
+
|
|
246
|
+
return loaded
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// A view's one loading moment: the first open, while its bundle is fetched. The
|
|
250
|
+
// delay keeps it off screen entirely for a fast load — the common case, since
|
|
251
|
+
// the module cache outlives eviction and only the network trip is new.
|
|
252
|
+
function ViewSplash() {
|
|
253
|
+
return (
|
|
254
|
+
<div className="absolute inset-0 flex animate-in items-center justify-center delay-150 duration-200 fill-mode-both fade-in">
|
|
255
|
+
<Spinner className="text-muted-foreground" />
|
|
256
|
+
</div>
|
|
257
|
+
)
|
|
258
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Which views the workspace keeps mounted, and for how long.
|
|
2
|
+
//
|
|
3
|
+
// A view is not remounted on every tab switch. The one on screen is visible,
|
|
4
|
+
// recently-visited ones stay mounted but hidden — DOM, component state, and
|
|
5
|
+
// styles intact — so coming back inside the retention window is instant. Past
|
|
6
|
+
// the window the view is disposed and the next visit re-loads it behind the
|
|
7
|
+
// splash. The cap bounds what fast tab-cycling can pin in memory: the least
|
|
8
|
+
// recently visited view is dropped first.
|
|
9
|
+
//
|
|
10
|
+
// The policy is pure so the timing rules stay testable; ViewManager owns the
|
|
11
|
+
// clock and the timers.
|
|
12
|
+
|
|
13
|
+
export const VIEW_RETENTION_MS = 60_000
|
|
14
|
+
export const MAX_RESIDENT_VIEWS = 4
|
|
15
|
+
|
|
16
|
+
export type ResidentView = {
|
|
17
|
+
id: string
|
|
18
|
+
// When the view stopped being the active one — null while it is active. The
|
|
19
|
+
// retention deadline is measured from here, and it is set ONCE per departure:
|
|
20
|
+
// re-running the policy must not restart the clock.
|
|
21
|
+
releasedAt: number | null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type ReconcileInput = {
|
|
25
|
+
// The view the active tab names, or null when another tab is on screen —
|
|
26
|
+
// which releases every resident, so parking on the chat expires them too.
|
|
27
|
+
activeId: string | null
|
|
28
|
+
// View ids that still exist. A deleted view is dropped immediately; its
|
|
29
|
+
// bundle is gone and its parked DOM would only hold dead styles.
|
|
30
|
+
available: ReadonlySet<string>
|
|
31
|
+
now: number
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// The resident set after promoting the active view and expiring the rest.
|
|
35
|
+
// Ordered most-recently-active first, so the cap drops the coldest view.
|
|
36
|
+
export function reconcileResidents(
|
|
37
|
+
residents: readonly ResidentView[],
|
|
38
|
+
{ activeId, available, now }: ReconcileInput
|
|
39
|
+
): ResidentView[] {
|
|
40
|
+
const next: ResidentView[] = []
|
|
41
|
+
if (activeId !== null && available.has(activeId)) next.push({ id: activeId, releasedAt: null })
|
|
42
|
+
|
|
43
|
+
for (const resident of residents) {
|
|
44
|
+
if (resident.id === activeId || !available.has(resident.id)) continue
|
|
45
|
+
const releasedAt = resident.releasedAt ?? now
|
|
46
|
+
if (now - releasedAt >= VIEW_RETENTION_MS) continue
|
|
47
|
+
if (next.length >= MAX_RESIDENT_VIEWS) break
|
|
48
|
+
next.push({ id: resident.id, releasedAt })
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return next
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Milliseconds until the next resident falls out of the retention window, or
|
|
55
|
+
// null when nothing is on the clock (every resident is active). ViewManager
|
|
56
|
+
// arms a single timer on this instead of one timer per view.
|
|
57
|
+
export function nextEvictionDelay(residents: readonly ResidentView[], now: number): number | null {
|
|
58
|
+
let earliest: number | null = null
|
|
59
|
+
for (const { releasedAt } of residents) {
|
|
60
|
+
if (releasedAt === null) continue
|
|
61
|
+
const deadline = releasedAt + VIEW_RETENTION_MS
|
|
62
|
+
if (earliest === null || deadline < earliest) earliest = deadline
|
|
63
|
+
}
|
|
64
|
+
return earliest === null ? null : Math.max(0, earliest - now)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Whether a reconcile changed anything — lets the caller keep the previous
|
|
68
|
+
// array identity and skip the re-render (and the timer effect it would rerun).
|
|
69
|
+
export function sameResidents(a: readonly ResidentView[], b: readonly ResidentView[]): boolean {
|
|
70
|
+
return (
|
|
71
|
+
a.length === b.length &&
|
|
72
|
+
a.every((resident, index) => {
|
|
73
|
+
const other = b[index]
|
|
74
|
+
return resident.id === other.id && resident.releasedAt === other.releasedAt
|
|
75
|
+
})
|
|
76
|
+
)
|
|
77
|
+
}
|
|
@@ -7,6 +7,8 @@ import { IconMinus, IconPlus } from '@tabler/icons-react'
|
|
|
7
7
|
import { cn } from '@/client/lib/cn'
|
|
8
8
|
|
|
9
9
|
import { Button } from '@/client/components/ui/button'
|
|
10
|
+
import { useWorkspaceThemeSetting } from '@/client/features/workspace/WorkspaceLayoutContext'
|
|
11
|
+
import { getWorkspaceThemeStyle } from '@/client/runtime/workspace-theme'
|
|
10
12
|
|
|
11
13
|
type WidgetFrameProps = {
|
|
12
14
|
editing?: boolean
|
|
@@ -16,6 +18,8 @@ type WidgetFrameProps = {
|
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export function WidgetFrame({ editing, hidden, onRemove, children }: WidgetFrameProps) {
|
|
21
|
+
const theme = useWorkspaceThemeSetting()
|
|
22
|
+
|
|
19
23
|
return (
|
|
20
24
|
<motion.div
|
|
21
25
|
variants={{
|
|
@@ -35,8 +39,9 @@ export function WidgetFrame({ editing, hidden, onRemove, children }: WidgetFrame
|
|
|
35
39
|
// Stable hook for widget snapshots: the capture clone overrides this
|
|
36
40
|
// element's chrome (radius/shadow/stroke) so thumbnails come out square.
|
|
37
41
|
data-widget-chrome
|
|
42
|
+
style={getWorkspaceThemeStyle(theme, 'widget')}
|
|
38
43
|
className={cn(
|
|
39
|
-
'
|
|
44
|
+
'absolute inset-0 overflow-hidden rounded-2xl text-foreground [corner-shape:superellipse(1.2)]',
|
|
40
45
|
// Outer drop shadow on the wrapper itself.
|
|
41
46
|
'shadow-[0_1px_2px_-1px_rgba(0,0,0,0.08),0_2px_4px_0_rgba(0,0,0,0.03)]',
|
|
42
47
|
// 1px inset stroke painted on a pseudo so it lands ON TOP of the
|
|
@@ -45,7 +50,6 @@ export function WidgetFrame({ editing, hidden, onRemove, children }: WidgetFrame
|
|
|
45
50
|
'after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit]',
|
|
46
51
|
"after:content-[''] after:[corner-shape:inherit]",
|
|
47
52
|
'after:shadow-[inset_0_0_0_1px_rgba(0,0,0,0.05)]',
|
|
48
|
-
'text-foreground',
|
|
49
53
|
editing && 'pointer-events-none'
|
|
50
54
|
)}
|
|
51
55
|
>
|
|
@@ -6,16 +6,21 @@ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayo
|
|
|
6
6
|
import { BottomPanel } from '@/client/components/shared/BottomPanel'
|
|
7
7
|
import { cn } from '@/client/lib/cn'
|
|
8
8
|
import { getWorkspaceThemeStyle, usePreloadWorkspaceFonts } from '@/client/runtime/workspace-theme'
|
|
9
|
-
import {
|
|
10
|
-
|
|
9
|
+
import {
|
|
10
|
+
COLOR_THEMES,
|
|
11
|
+
type ColorThemeConfig,
|
|
12
|
+
FONT_THEMES,
|
|
13
|
+
RADIUS_THEMES,
|
|
14
|
+
type RadiusThemeConfig,
|
|
15
|
+
resolveWorkspaceTheme
|
|
16
|
+
} from '@/lib/themes'
|
|
17
|
+
import type { ColorTheme, FontTheme, RadiusTheme, WorkspaceTheme } from '@/lib/types'
|
|
11
18
|
|
|
12
19
|
const FONT_OPTIONS = Object.entries(FONT_THEMES) as [FontTheme, (typeof FONT_THEMES)[FontTheme]][]
|
|
13
20
|
|
|
14
21
|
const COLOR_OPTIONS = Object.entries(COLOR_THEMES) as [ColorTheme, ColorThemeConfig][]
|
|
15
22
|
|
|
16
|
-
|
|
17
|
-
return (preset.primary ?? undefined) === primary
|
|
18
|
-
}
|
|
23
|
+
const RADIUS_OPTIONS = Object.entries(RADIUS_THEMES) as [RadiusTheme, RadiusThemeConfig][]
|
|
19
24
|
|
|
20
25
|
type CustomizeOptionGroupProps = {
|
|
21
26
|
children: ReactNode
|
|
@@ -26,7 +31,7 @@ function CustomizeOptionGroup({ children, label }: CustomizeOptionGroupProps) {
|
|
|
26
31
|
return (
|
|
27
32
|
<div className="flex flex-col gap-2">
|
|
28
33
|
<p className="text-xs font-medium">{label}</p>
|
|
29
|
-
<div role="group" aria-label={label} className="grid grid-cols-
|
|
34
|
+
<div role="group" aria-label={label} className="grid grid-cols-4 gap-2">
|
|
30
35
|
{children}
|
|
31
36
|
</div>
|
|
32
37
|
</div>
|
|
@@ -55,7 +60,7 @@ function CustomizeOption({ active, children, className, onSelect, style }: Custo
|
|
|
55
60
|
)}
|
|
56
61
|
style={style}
|
|
57
62
|
>
|
|
58
|
-
<div className="flex-1">{children}</div>
|
|
63
|
+
<div className="flex flex-1 flex-col justify-center">{children}</div>
|
|
59
64
|
{active && <IconCircleCheckFilled size={20} stroke={1.5} aria-hidden="true" />}
|
|
60
65
|
</button>
|
|
61
66
|
)
|
|
@@ -69,11 +74,10 @@ type CustomizePanelProps = {
|
|
|
69
74
|
export function CustomizePanel({ onClose, ref }: CustomizePanelProps) {
|
|
70
75
|
usePreloadWorkspaceFonts()
|
|
71
76
|
const { layout, setLayout } = useWorkspaceLayoutCtx()
|
|
72
|
-
const
|
|
73
|
-
const currentPrimary = layout.theme?.primary
|
|
77
|
+
const theme = resolveWorkspaceTheme(layout.theme)
|
|
74
78
|
|
|
75
|
-
function setTheme(
|
|
76
|
-
setLayout({ theme: {
|
|
79
|
+
function setTheme(update: Partial<WorkspaceTheme>) {
|
|
80
|
+
setLayout({ theme: { ...theme, ...update } })
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
return (
|
|
@@ -83,14 +87,11 @@ export function CustomizePanel({ onClose, ref }: CustomizePanelProps) {
|
|
|
83
87
|
{FONT_OPTIONS.map(([key, config]) => (
|
|
84
88
|
<CustomizeOption
|
|
85
89
|
key={key}
|
|
86
|
-
active={key ===
|
|
87
|
-
onSelect={() => setTheme(key
|
|
90
|
+
active={key === theme.font}
|
|
91
|
+
onSelect={() => setTheme({ font: key })}
|
|
88
92
|
style={{ fontFamily: config.sans }}
|
|
89
93
|
>
|
|
90
|
-
<
|
|
91
|
-
<span className="text-sm font-medium">{config.label}</span>
|
|
92
|
-
<span className="text-xs text-muted-foreground">{config.feel}</span>
|
|
93
|
-
</div>
|
|
94
|
+
<span className="text-sm font-medium">{config.label}</span>
|
|
94
95
|
</CustomizeOption>
|
|
95
96
|
))}
|
|
96
97
|
</CustomizeOptionGroup>
|
|
@@ -99,14 +100,10 @@ export function CustomizePanel({ onClose, ref }: CustomizePanelProps) {
|
|
|
99
100
|
{COLOR_OPTIONS.map(([key, preset]) => (
|
|
100
101
|
<CustomizeOption
|
|
101
102
|
key={key}
|
|
102
|
-
active={
|
|
103
|
+
active={key === theme.color}
|
|
103
104
|
className={preset.primary && 'bg-background text-foreground'}
|
|
104
|
-
onSelect={() => setTheme(
|
|
105
|
-
style={
|
|
106
|
-
preset.primary
|
|
107
|
-
? getWorkspaceThemeStyle({ font: currentFont, primary: preset.primary })
|
|
108
|
-
: undefined
|
|
109
|
-
}
|
|
105
|
+
onSelect={() => setTheme({ color: key })}
|
|
106
|
+
style={getWorkspaceThemeStyle({ ...theme, color: key })}
|
|
110
107
|
>
|
|
111
108
|
<div className="flex gap-2">
|
|
112
109
|
<span
|
|
@@ -124,6 +121,25 @@ export function CustomizePanel({ onClose, ref }: CustomizePanelProps) {
|
|
|
124
121
|
</CustomizeOption>
|
|
125
122
|
))}
|
|
126
123
|
</CustomizeOptionGroup>
|
|
124
|
+
|
|
125
|
+
<CustomizeOptionGroup label="Radius">
|
|
126
|
+
{RADIUS_OPTIONS.map(([key, preset]) => (
|
|
127
|
+
<CustomizeOption
|
|
128
|
+
key={key}
|
|
129
|
+
active={key === theme.radius}
|
|
130
|
+
onSelect={() => setTheme({ radius: key })}
|
|
131
|
+
style={getWorkspaceThemeStyle({ ...theme, radius: key })}
|
|
132
|
+
>
|
|
133
|
+
<div className="flex items-center gap-2">
|
|
134
|
+
<span
|
|
135
|
+
className="size-5 shrink-0 rounded-sm bg-card texture-checker-[10px] shadow-xs"
|
|
136
|
+
aria-hidden="true"
|
|
137
|
+
/>
|
|
138
|
+
<span className="text-sm font-medium">{preset.label}</span>
|
|
139
|
+
</div>
|
|
140
|
+
</CustomizeOption>
|
|
141
|
+
))}
|
|
142
|
+
</CustomizeOptionGroup>
|
|
127
143
|
</div>
|
|
128
144
|
</BottomPanel>
|
|
129
145
|
)
|
|
@@ -41,6 +41,14 @@ export function useWorkspaceLayoutCtx(): WorkspaceLayoutContextValue {
|
|
|
41
41
|
return ctx
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
// The theme alone, for chrome that only needs to paint itself (widget frames,
|
|
45
|
+
// previews). Unlike `useWorkspaceLayoutCtx` this tolerates being read outside a
|
|
46
|
+
// provider and returns `undefined` there, which callers already treat as "use
|
|
47
|
+
// the default theme" — so the same component still renders in isolation.
|
|
48
|
+
export function useWorkspaceThemeSetting(): WorkspaceLayout['theme'] {
|
|
49
|
+
return useContext(WorkspaceLayoutContext)?.layout.theme
|
|
50
|
+
}
|
|
51
|
+
|
|
44
52
|
// Strip the server-only metadata so what we PUT back (and expose as `layout`)
|
|
45
53
|
// is just the persisted `WorkspaceLayout`.
|
|
46
54
|
function stripMeta(data: WorkspaceLayoutResponse): WorkspaceLayout {
|