moi-computer 0.11.0 → 0.11.1-next.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/client/AGENTS.md +2 -2
- package/client/components/ui/button.tsx +1 -53
- package/client/components/ui/collapsible.tsx +1 -15
- package/client/components/ui/dialog.tsx +1 -58
- package/client/components/ui/dropdown-menu.tsx +1 -254
- package/client/components/ui/hover-card.tsx +1 -44
- package/client/components/ui/input.tsx +1 -21
- package/client/components/ui/popover.tsx +1 -88
- package/client/components/ui/resizable.tsx +1 -40
- package/client/components/ui/skeleton.tsx +1 -13
- package/client/components/ui/slider.tsx +1 -70
- package/client/components/ui/spinner.tsx +1 -18
- package/client/components/ui/switch.tsx +1 -23
- package/client/components/ui/tabs.tsx +1 -0
- package/client/components/ui/textarea.tsx +1 -18
- package/client/components/ui/tooltip.tsx +1 -51
- package/client/features/chat/ChatPanel.tsx +6 -6
- package/client/features/chat/ChatPopup.tsx +3 -4
- package/client/features/chat/TurnView.tsx +5 -4
- package/client/features/chat/api.ts +5 -14
- package/client/features/chat/chat-frames.ts +5 -2
- package/client/features/chat/composer/ChatComposer.tsx +5 -1
- package/client/features/chat/composer/ModelPicker.tsx +4 -3
- package/client/features/chat/composer/banners/ErrorBanner.tsx +20 -12
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +15 -7
- package/client/features/chat/group-turns.ts +11 -0
- package/client/features/chat/session-view.ts +53 -0
- package/client/features/chat/useChat.ts +5 -1
- package/client/features/dev/ChatStatesPage.tsx +3 -1
- package/client/features/dev/DevIndexPage.tsx +5 -0
- package/client/features/dev/DevRoutes.tsx +2 -0
- package/client/features/dev/HarnessDebugPage.tsx +1 -1
- package/client/features/dev/UiComponentPreviews.tsx +834 -0
- package/client/features/dev/UiComponentsPage.tsx +60 -0
- package/client/features/home/WorkspacePreview.tsx +1 -1
- package/client/features/home/workspace-setup/DemoDialog.tsx +3 -2
- package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +5 -8
- package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +7 -20
- package/client/features/settings/SettingsLayout.tsx +1 -1
- package/client/features/settings/WorkspaceSettings.tsx +4 -1
- package/client/features/views/ViewManager.tsx +14 -9
- package/client/features/widgets/WidgetFrame.tsx +1 -1
- package/client/features/widgets/Widgets.tsx +1 -3
- package/client/features/workspace/WorkspaceScreen.tsx +5 -1
- package/client/features/workspace/WorkspaceSplitLayout.tsx +6 -1
- package/client/features/workspace/api.ts +2 -4
- package/client/index.css +22 -29
- package/dist/{chunk-tny85yt2.js → chunk-4s15axjs.js} +2 -2
- package/dist/{chunk-c9pjqx9m.js → chunk-53a7pxcz.js} +1 -1
- package/dist/chunk-6664vxpk.css +1 -0
- package/dist/{chunk-104m57qw.js → chunk-87thzbtw.js} +2 -2
- package/dist/chunk-a6jad1a6.js +1 -0
- package/dist/chunk-dghwstd2.js +9 -0
- package/dist/chunk-eg120aca.js +1 -0
- package/dist/{chunk-v7wr1df4.js → chunk-j3wvxjr7.js} +1 -1
- package/dist/chunk-vwjeezeb.js +1 -0
- package/dist/chunk-w482ew2c.js +546 -0
- package/dist/chunk-yc471zah.js +70 -0
- package/dist/index.html +1 -1
- package/lib/format.ts +49 -1
- package/lib/themes.ts +6 -6
- package/lib/types.ts +5 -7
- package/package.json +17 -7
- package/registry.json +643 -0
- package/server/AGENTS.md +1 -0
- package/server/agent.ts +1 -1
- package/server/api.ts +25 -29
- package/server/applets.ts +30 -29
- package/server/bundler/applet-css.ts +6 -1
- package/server/bundler/build-applet.ts +5 -1
- package/server/bundler/build-worker.ts +178 -0
- package/server/cli-ui-components.ts +28 -33
- package/server/cli.ts +6 -11
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +13 -9
- package/server/harness/acp/NOTES.md +426 -0
- package/server/harness/acp/discovery.ts +27 -30
- package/server/harness/acp/model-state.ts +57 -0
- package/server/harness/acp/session.ts +18 -6
- package/server/harness/claude-code/NOTES.md +47 -12
- package/server/harness/claude-code/cli.ts +40 -0
- package/server/harness/claude-code/index.ts +11 -5
- package/server/harness/claude-code/models.ts +72 -19
- package/server/harness/claude-code/session.ts +408 -299
- package/server/harness/hermes/NOTES.md +18 -0
- package/server/harness/hermes/discovery.ts +20 -0
- package/server/harness/hermes/index.ts +9 -0
- package/server/harness/hermes/models.ts +28 -8
- package/server/harness/types.ts +4 -2
- package/server/moi-scaffold.ts +1 -1
- package/server/preview.ts +3 -1
- package/server/registry.ts +63 -41
- package/server/scratchpad-executor.ts +79 -56
- package/server/scratchpad-shape-defaults.ts +82 -0
- package/server/tldraw-package.d.ts +4 -0
- package/server/ui-components.ts +101 -434
- package/server/view-builders.ts +2 -1
- package/server/web.ts +9 -5
- package/server/workspace-env.ts +3 -2
- package/tsconfig.json +0 -1
- package/ui-components/accordion.tsx +71 -0
- package/ui-components/alert-dialog.tsx +165 -0
- package/ui-components/alert.tsx +68 -0
- package/ui-components/attachment.tsx +195 -0
- package/ui-components/avatar.tsx +90 -0
- package/ui-components/badge.tsx +49 -0
- package/ui-components/button-group.tsx +78 -0
- package/ui-components/button.tsx +55 -0
- package/ui-components/calendar.tsx +180 -0
- package/ui-components/card.tsx +84 -0
- package/ui-components/carousel.tsx +235 -0
- package/ui-components/chart.tsx +338 -0
- package/ui-components/checkbox.tsx +27 -0
- package/ui-components/collapsible.tsx +15 -0
- package/ui-components/combobox.tsx +265 -0
- package/ui-components/context-menu.tsx +244 -0
- package/ui-components/dialog.tsx +138 -0
- package/ui-components/docs/accordion.md +463 -0
- package/ui-components/docs/alert-dialog.md +481 -0
- package/ui-components/docs/alert.md +301 -0
- package/ui-components/docs/attachment.md +689 -0
- package/ui-components/docs/avatar.md +495 -0
- package/ui-components/docs/badge.md +258 -0
- package/ui-components/docs/button-group.md +879 -0
- package/ui-components/docs/button.md +26 -0
- package/ui-components/docs/calendar.md +862 -0
- package/ui-components/docs/card.md +265 -0
- package/ui-components/docs/carousel.md +627 -0
- package/ui-components/docs/chart.md +1256 -0
- package/ui-components/docs/checkbox.md +477 -0
- package/ui-components/docs/collapsible.md +446 -0
- package/ui-components/docs/combobox.md +1003 -0
- package/ui-components/docs/context-menu.md +860 -0
- package/ui-components/docs/data-table.md +1580 -0
- package/ui-components/docs/date-picker.md +614 -0
- package/ui-components/docs/dialog.md +414 -0
- package/ui-components/docs/drawer.md +51 -0
- package/ui-components/docs/dropdown-menu.md +1000 -0
- package/ui-components/docs/field.md +1192 -0
- package/ui-components/docs/hover-card.md +275 -0
- package/ui-components/docs/input-group.md +866 -0
- package/ui-components/docs/input.md +456 -0
- package/ui-components/docs/label.md +295 -0
- package/ui-components/docs/pagination.md +416 -0
- package/ui-components/docs/popover.md +348 -0
- package/ui-components/docs/progress.md +214 -0
- package/ui-components/docs/radio-group.md +389 -0
- package/ui-components/docs/resizable.md +265 -0
- package/ui-components/docs/select.md +616 -0
- package/ui-components/docs/separator.md +216 -0
- package/ui-components/docs/skeleton.md +205 -0
- package/ui-components/docs/slider.md +226 -0
- package/ui-components/docs/spinner.md +332 -0
- package/ui-components/docs/switch.md +236 -0
- package/ui-components/docs/table.md +551 -0
- package/ui-components/docs/tabs.md +379 -0
- package/ui-components/docs/textarea.md +187 -0
- package/ui-components/docs/toggle-group.md +370 -0
- package/ui-components/docs/toggle.md +91 -0
- package/ui-components/docs/tooltip.md +290 -0
- package/ui-components/drawer.tsx +213 -0
- package/ui-components/dropdown-menu.tsx +263 -0
- package/ui-components/field.tsx +224 -0
- package/ui-components/hover-card.tsx +46 -0
- package/ui-components/input-group.tsx +146 -0
- package/ui-components/input.tsx +20 -0
- package/ui-components/label.tsx +17 -0
- package/ui-components/pagination.tsx +124 -0
- package/ui-components/popover.tsx +81 -0
- package/ui-components/progress.tsx +63 -0
- package/ui-components/radio-group.tsx +37 -0
- package/ui-components/resizable.tsx +40 -0
- package/ui-components/scoped-portal.tsx +31 -0
- package/ui-components/select.tsx +195 -0
- package/ui-components/separator.tsx +18 -0
- package/ui-components/skeleton.tsx +15 -0
- package/ui-components/slider.tsx +75 -0
- package/ui-components/spinner.tsx +20 -0
- package/ui-components/switch.tsx +26 -0
- package/ui-components/table.tsx +86 -0
- package/ui-components/tabs.tsx +75 -0
- package/ui-components/textarea.tsx +17 -0
- package/ui-components/toggle-group.tsx +85 -0
- package/ui-components/toggle.tsx +42 -0
- package/ui-components/tooltip.tsx +61 -0
- package/ui-components/utils.ts +8 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +11 -20
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +4 -3
- package/workspace/.claude/skills/moi-workspace/references/UI-COMPONENTS.md +67 -203
- package/dist/chunk-59zf0m6n.js +0 -1
- package/dist/chunk-bj3akjs2.js +0 -1
- package/dist/chunk-j2w2vak4.js +0 -546
- package/dist/chunk-k2r9c95m.js +0 -10
- package/dist/chunk-kmbxhgwv.js +0 -1
- package/dist/chunk-p1yqa71k.js +0 -83
- package/dist/chunk-r5xrenjy.css +0 -1
package/server/ui-components.ts
CHANGED
|
@@ -1,23 +1,10 @@
|
|
|
1
|
-
// The `moi ui-components`
|
|
2
|
-
//
|
|
3
|
-
// for the full spec and the research trail in PR #78).
|
|
4
|
-
//
|
|
5
|
-
// Opinions, enforced here: the upstream registry is the source of truth
|
|
6
|
-
// (style `base-nova`, Base UI primitives, Tabler icons); the command exposes
|
|
7
|
-
// only a curated subset of it; no config files ever land in the workspace —
|
|
8
|
-
// the engine takes its config as the in-memory object below; components are
|
|
9
|
-
// written to `.moi/ui/` and imported relatively (`../ui/button`). The command
|
|
10
|
-
// writes source files and nothing else: it never installs dependencies and
|
|
11
|
-
// never rebuilds — it prints next steps for the agent instead.
|
|
12
|
-
// `shadcn/registry`, `shadcn/utils` and `ts-morph` are imported at their call
|
|
13
|
-
// sites rather than here, deliberately. Together they are ~31 MB of JS across
|
|
14
|
-
// 1600 modules (ts-morph alone embeds the whole TypeScript compiler), and the
|
|
15
|
-
// cost is parse + top-level evaluation, so bundling does not help — measured
|
|
16
|
-
// at ~300 ms. Only `moi ui-components add` ever fetches or transforms; a
|
|
17
|
-
// static import here made every `moi` command pay it, `moi version` included.
|
|
18
|
-
import type { Project, SourceFile } from 'ts-morph'
|
|
1
|
+
// The `moi ui-components` catalog and local registry loader. Component sources
|
|
2
|
+
// and docs are bundled, so installs do not depend on a remote registry.
|
|
19
3
|
import { join } from 'path'
|
|
20
4
|
|
|
5
|
+
import registry from '../registry.json'
|
|
6
|
+
import { PACKAGE_ROOT } from './version'
|
|
7
|
+
|
|
21
8
|
// ---------------------------------------------------------------------------
|
|
22
9
|
// The curated catalog
|
|
23
10
|
// ---------------------------------------------------------------------------
|
|
@@ -25,450 +12,139 @@ import { join } from 'path'
|
|
|
25
12
|
export type UiComponentEntry = {
|
|
26
13
|
// One line for `moi ui-components list` and the skill cheat sheet.
|
|
27
14
|
description: string
|
|
28
|
-
// Registry items `add` actually fetches. Most entries map to themselves;
|
|
29
|
-
// pattern entries (data-table, date-picker) map to their building blocks
|
|
30
|
-
// and exist upstream only as docs.
|
|
31
|
-
registryItems: string[]
|
|
32
|
-
// npm packages the entry needs that no fetched registry item declares —
|
|
33
|
-
// pattern-only additions their docs assume (data-table → TanStack Table).
|
|
34
|
-
// Everything else flows from the resolved items' own `dependencies`.
|
|
35
|
-
extraDeps?: string[]
|
|
36
|
-
// Docs slug when it differs from the entry name (none currently).
|
|
37
|
-
docsSlug?: string
|
|
38
15
|
}
|
|
39
16
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export const UI_COMPONENTS: Record<string, UiComponentEntry> = {
|
|
46
|
-
accordion: {
|
|
47
|
-
description: 'Vertically stacked sections that expand one at a time',
|
|
48
|
-
registryItems: ['accordion']
|
|
49
|
-
},
|
|
50
|
-
alert: {
|
|
51
|
-
description: 'Callout box for statuses and short messages',
|
|
52
|
-
registryItems: ['alert']
|
|
53
|
-
},
|
|
54
|
-
'alert-dialog': {
|
|
55
|
-
description: 'Modal confirmation dialog for destructive or blocking actions',
|
|
56
|
-
registryItems: ['alert-dialog']
|
|
57
|
-
},
|
|
58
|
-
attachment: {
|
|
59
|
-
description: 'File or image attachment tile with metadata and actions',
|
|
60
|
-
registryItems: ['attachment']
|
|
61
|
-
},
|
|
62
|
-
avatar: {
|
|
63
|
-
description: 'User or entity image with fallback initials',
|
|
64
|
-
registryItems: ['avatar']
|
|
65
|
-
},
|
|
66
|
-
badge: {
|
|
67
|
-
description: 'Small status or count label',
|
|
68
|
-
registryItems: ['badge']
|
|
69
|
-
},
|
|
70
|
-
bubble: {
|
|
71
|
-
description: 'Chat message bubble',
|
|
72
|
-
registryItems: ['bubble']
|
|
73
|
-
},
|
|
74
|
-
button: {
|
|
75
|
-
description: 'The button: variants, sizes, icon support',
|
|
76
|
-
registryItems: ['button']
|
|
77
|
-
},
|
|
78
|
-
'button-group': {
|
|
79
|
-
description: 'Buttons joined into one segmented control',
|
|
80
|
-
registryItems: ['button-group']
|
|
81
|
-
},
|
|
82
|
-
calendar: {
|
|
83
|
-
description: 'Month calendar for picking dates and ranges',
|
|
84
|
-
registryItems: ['calendar']
|
|
85
|
-
},
|
|
86
|
-
carousel: {
|
|
87
|
-
description: 'Swipeable slides with prev/next controls',
|
|
88
|
-
registryItems: ['carousel']
|
|
89
|
-
},
|
|
90
|
-
chart: {
|
|
91
|
-
description: 'Recharts-based charts wired to workspace theme tokens',
|
|
92
|
-
registryItems: ['chart']
|
|
93
|
-
},
|
|
94
|
-
checkbox: {
|
|
95
|
-
description: 'Binary checkbox with indeterminate state',
|
|
96
|
-
registryItems: ['checkbox']
|
|
97
|
-
},
|
|
98
|
-
collapsible: {
|
|
99
|
-
description: 'Single section that expands and collapses',
|
|
100
|
-
registryItems: ['collapsible']
|
|
101
|
-
},
|
|
102
|
-
combobox: {
|
|
103
|
-
description: 'Text input with a filtered dropdown of options',
|
|
104
|
-
registryItems: ['combobox']
|
|
105
|
-
},
|
|
106
|
-
'context-menu': {
|
|
107
|
-
description: 'Right-click menu with items, submenus, and shortcuts',
|
|
108
|
-
registryItems: ['context-menu']
|
|
109
|
-
},
|
|
110
|
-
'data-table': {
|
|
111
|
-
description: 'Sortable, filterable table pattern built on table + TanStack Table',
|
|
112
|
-
registryItems: ['table'],
|
|
113
|
-
extraDeps: ['@tanstack/react-table']
|
|
114
|
-
},
|
|
115
|
-
'date-picker': {
|
|
116
|
-
description: 'Date picker pattern: calendar in a popover',
|
|
117
|
-
registryItems: ['calendar', 'popover', 'button']
|
|
118
|
-
},
|
|
119
|
-
dialog: {
|
|
120
|
-
description: 'Modal dialog with backdrop, header, and footer',
|
|
121
|
-
registryItems: ['dialog']
|
|
122
|
-
},
|
|
123
|
-
'dropdown-menu': {
|
|
124
|
-
description: 'Menu opened from a trigger: items, groups, submenus',
|
|
125
|
-
registryItems: ['dropdown-menu']
|
|
126
|
-
},
|
|
127
|
-
field: {
|
|
128
|
-
description: 'Form field wrapper: label, control, description, error',
|
|
129
|
-
registryItems: ['field']
|
|
130
|
-
},
|
|
131
|
-
'hover-card': {
|
|
132
|
-
description: 'Preview card shown on hover over a link or element',
|
|
133
|
-
registryItems: ['hover-card']
|
|
134
|
-
},
|
|
135
|
-
input: {
|
|
136
|
-
description: 'Single-line text input',
|
|
137
|
-
registryItems: ['input']
|
|
138
|
-
},
|
|
139
|
-
'input-group': {
|
|
140
|
-
description: 'Input with attached addons, buttons, or icons',
|
|
141
|
-
registryItems: ['input-group']
|
|
142
|
-
},
|
|
143
|
-
label: {
|
|
144
|
-
description: 'Form control label',
|
|
145
|
-
registryItems: ['label']
|
|
146
|
-
},
|
|
147
|
-
pagination: {
|
|
148
|
-
description: 'Page navigation with prev/next and page links',
|
|
149
|
-
registryItems: ['pagination']
|
|
150
|
-
},
|
|
151
|
-
popover: {
|
|
152
|
-
description: 'Floating panel anchored to a trigger',
|
|
153
|
-
registryItems: ['popover']
|
|
154
|
-
},
|
|
155
|
-
progress: {
|
|
156
|
-
description: 'Determinate progress bar',
|
|
157
|
-
registryItems: ['progress']
|
|
158
|
-
},
|
|
159
|
-
'radio-group': {
|
|
160
|
-
description: 'Single-choice radio button set',
|
|
161
|
-
registryItems: ['radio-group']
|
|
162
|
-
},
|
|
163
|
-
resizable: {
|
|
164
|
-
description: 'Resizable split panels with drag handles',
|
|
165
|
-
registryItems: ['resizable']
|
|
166
|
-
},
|
|
167
|
-
select: {
|
|
168
|
-
description: 'Native-feeling select with a styled popup',
|
|
169
|
-
registryItems: ['select']
|
|
170
|
-
},
|
|
171
|
-
separator: {
|
|
172
|
-
description: 'Horizontal or vertical dividing line',
|
|
173
|
-
registryItems: ['separator']
|
|
174
|
-
},
|
|
175
|
-
skeleton: {
|
|
176
|
-
description: 'Loading placeholder block',
|
|
177
|
-
registryItems: ['skeleton']
|
|
178
|
-
},
|
|
179
|
-
slider: {
|
|
180
|
-
description: 'Range slider with one or more thumbs',
|
|
181
|
-
registryItems: ['slider']
|
|
182
|
-
},
|
|
183
|
-
spinner: {
|
|
184
|
-
description: 'Inline loading spinner',
|
|
185
|
-
registryItems: ['spinner']
|
|
186
|
-
},
|
|
187
|
-
switch: {
|
|
188
|
-
description: 'On/off toggle switch',
|
|
189
|
-
registryItems: ['switch']
|
|
190
|
-
},
|
|
191
|
-
table: {
|
|
192
|
-
description: 'Styled table primitives (header, body, rows, cells)',
|
|
193
|
-
registryItems: ['table']
|
|
194
|
-
},
|
|
195
|
-
tabs: {
|
|
196
|
-
description: 'Tabbed panels with a tab list',
|
|
197
|
-
registryItems: ['tabs']
|
|
198
|
-
},
|
|
199
|
-
textarea: {
|
|
200
|
-
description: 'Multi-line text input',
|
|
201
|
-
registryItems: ['textarea']
|
|
202
|
-
},
|
|
203
|
-
'toggle-group': {
|
|
204
|
-
description: 'Group of two-state toggle buttons',
|
|
205
|
-
registryItems: ['toggle-group']
|
|
206
|
-
},
|
|
207
|
-
tooltip: {
|
|
208
|
-
description: 'Small label shown on hover or focus',
|
|
209
|
-
registryItems: ['tooltip']
|
|
210
|
-
}
|
|
17
|
+
type RegistryCatalogItem = {
|
|
18
|
+
name: string
|
|
19
|
+
type: string
|
|
20
|
+
files?: Array<{ path: string }>
|
|
21
|
+
registryDependencies?: string[]
|
|
211
22
|
}
|
|
212
23
|
|
|
24
|
+
const REGISTRY_ITEMS = new Map(
|
|
25
|
+
(registry.items as RegistryCatalogItem[]).map(item => [item.name, item] as const)
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
export const UI_COMPONENTS: Record<string, UiComponentEntry> = Object.fromEntries(
|
|
29
|
+
registry.items
|
|
30
|
+
.filter(item => item.type === 'registry:ui' || item.type === 'registry:block')
|
|
31
|
+
.map(item => [item.name, { description: item.description ?? item.title ?? item.name }] as const)
|
|
32
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
33
|
+
)
|
|
34
|
+
|
|
213
35
|
export const UI_COMPONENT_NAMES = Object.keys(UI_COMPONENTS)
|
|
214
36
|
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
|
|
37
|
+
// The final path segment names the component file for built-in, namespaced,
|
|
38
|
+
// and GitHub registry addresses alike.
|
|
39
|
+
export function registryItemName(registryItem: string): string {
|
|
40
|
+
const withoutRef = registryItem.split('#', 1)[0]
|
|
41
|
+
return withoutRef.split('/').at(-1) ?? withoutRef
|
|
42
|
+
}
|
|
218
43
|
|
|
219
|
-
//
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
// Cast once to `never`: the engine functions accept `Partial<Config>`, but
|
|
225
|
-
// shadcn exports no public name for that resolved Config type (only the
|
|
226
|
-
// components.json shape) — `never` is assignable to every parameter type, and
|
|
227
|
-
// nothing here reads the constant back.
|
|
228
|
-
const ENGINE_CONFIG = {
|
|
229
|
-
style: 'base-nova',
|
|
230
|
-
tailwind: { css: 'unused.css', baseColor: 'neutral', cssVariables: true },
|
|
231
|
-
rsc: false,
|
|
232
|
-
tsx: true,
|
|
233
|
-
iconLibrary: 'tabler',
|
|
234
|
-
rtl: false,
|
|
235
|
-
aliases: { ui: '@/components/ui', utils: '@/lib/utils' }
|
|
236
|
-
} as never
|
|
44
|
+
// A block has no source of its own, so its direct component dependencies are
|
|
45
|
+
// the files users install and can later update with --force.
|
|
46
|
+
export function uiComponentFiles(name: string): string[] {
|
|
47
|
+
const files = new Set<string>()
|
|
48
|
+
const visited = new Set<string>()
|
|
237
49
|
|
|
238
|
-
|
|
50
|
+
const collect = (itemName: string): void => {
|
|
51
|
+
if (visited.has(itemName)) return
|
|
52
|
+
visited.add(itemName)
|
|
239
53
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
54
|
+
const item = REGISTRY_ITEMS.get(itemName)
|
|
55
|
+
if (!item) return
|
|
56
|
+
if (item.files?.length) {
|
|
57
|
+
for (const file of item.files) files.add(uiFileName(file.path))
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
for (const dependency of item.registryDependencies ?? []) {
|
|
61
|
+
collect(registryItemName(dependency))
|
|
62
|
+
}
|
|
63
|
+
}
|
|
243
64
|
|
|
244
|
-
|
|
65
|
+
collect(registryItemName(name))
|
|
66
|
+
return [...files]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type LoadedUiFile = {
|
|
245
70
|
// File name inside `.moi/ui/` (`button.tsx`, `utils.ts`).
|
|
246
71
|
name: string
|
|
247
72
|
content: string
|
|
248
73
|
}
|
|
249
74
|
|
|
250
|
-
export type
|
|
251
|
-
files:
|
|
75
|
+
export type LoadedUiComponents = {
|
|
76
|
+
files: LoadedUiFile[]
|
|
252
77
|
// npm dependencies declared by the resolved registry items (versioned
|
|
253
78
|
// specifiers like `recharts@3.8.0` pass through as-is).
|
|
254
79
|
dependencies: string[]
|
|
255
80
|
}
|
|
256
81
|
|
|
257
|
-
// Where a registry file lands in `.moi/ui/`. Registry paths look like
|
|
258
|
-
// `registry/base-nova/ui/button.tsx`, `registry/base-nova/lib/utils.ts`,
|
|
259
|
-
// `registry/base-nova/hooks/use-mobile.ts` — everything flattens into the one
|
|
260
|
-
// ui dir so relative imports stay `./<name>`.
|
|
261
82
|
function uiFileName(registryPath: string): string {
|
|
262
83
|
const base = registryPath.split('/').pop() ?? registryPath
|
|
263
84
|
return base
|
|
264
85
|
}
|
|
265
86
|
|
|
266
|
-
//
|
|
267
|
-
//
|
|
268
|
-
//
|
|
269
|
-
export async function
|
|
87
|
+
// Load requested items and their same-repository dependencies from the
|
|
88
|
+
// bundled registry. Files flatten into `.moi/ui/` so sibling imports
|
|
89
|
+
// stay relative.
|
|
90
|
+
export async function loadUiComponents(
|
|
91
|
+
registryNames: string[],
|
|
92
|
+
registryRoot: string = PACKAGE_ROOT
|
|
93
|
+
): Promise<LoadedUiComponents> {
|
|
94
|
+
const { loadRegistryItem } = await import('shadcn/registry')
|
|
270
95
|
const files = new Map<string, string>()
|
|
271
96
|
const dependencies = new Set<string>()
|
|
272
|
-
const
|
|
273
|
-
let queue = [...new Set(['utils', ...registryNames])]
|
|
97
|
+
const loaded = new Set<string>()
|
|
274
98
|
|
|
275
|
-
const
|
|
99
|
+
const loadItem = async (address: string): Promise<void> => {
|
|
100
|
+
const itemName = registryItemName(address)
|
|
101
|
+
if (loaded.has(itemName)) return
|
|
102
|
+
loaded.add(itemName)
|
|
276
103
|
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const items = await getRegistryItems(batch, { config: ENGINE_CONFIG })
|
|
283
|
-
const next: string[] = []
|
|
284
|
-
for (const item of items ?? []) {
|
|
285
|
-
for (const dep of item.dependencies ?? []) dependencies.add(dep)
|
|
286
|
-
for (const dep of item.registryDependencies ?? []) {
|
|
287
|
-
// Registry deps are plain item names for the shadcn registry; URLs
|
|
288
|
-
// would point at third-party registries, which the curated set never
|
|
289
|
-
// references.
|
|
290
|
-
if (!fetched.has(dep)) next.push(dep)
|
|
291
|
-
}
|
|
292
|
-
for (const file of item.files ?? []) {
|
|
293
|
-
if (!file.content) continue
|
|
294
|
-
files.set(uiFileName(file.path), file.content)
|
|
104
|
+
const item = await loadRegistryItem(itemName, { cwd: registryRoot })
|
|
105
|
+
for (const file of item.files ?? []) {
|
|
106
|
+
if (!file.content) {
|
|
107
|
+
throw new Error(`Registry item "${itemName}" has a missing file: ${file.path}`)
|
|
295
108
|
}
|
|
109
|
+
files.set(uiFileName(file.path), file.content)
|
|
110
|
+
}
|
|
111
|
+
for (const dependency of item.dependencies ?? []) dependencies.add(dependency)
|
|
112
|
+
for (const registryDependency of item.registryDependencies ?? []) {
|
|
113
|
+
await loadItem(registryDependency)
|
|
296
114
|
}
|
|
297
|
-
queue = next
|
|
298
115
|
}
|
|
299
116
|
|
|
117
|
+
for (const name of new Set(registryNames)) await loadItem(name)
|
|
118
|
+
|
|
300
119
|
return {
|
|
301
120
|
files: [...files.entries()].map(([name, content]) => ({ name, content })),
|
|
302
121
|
dependencies: [...dependencies].sort()
|
|
303
122
|
}
|
|
304
123
|
}
|
|
305
124
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
function rewriteRegistryImports(sourceFile: SourceFile): void {
|
|
316
|
-
const rewrite = (spec: string): string | null => {
|
|
317
|
-
const match = /^@\/registry\/[^/]+\/(?:lib|ui|hooks)\/([\w-]+)$/.exec(spec)
|
|
318
|
-
return match ? `./${match[1]}` : null
|
|
319
|
-
}
|
|
320
|
-
for (const decl of sourceFile.getImportDeclarations()) {
|
|
321
|
-
const next = rewrite(decl.getModuleSpecifierValue())
|
|
322
|
-
if (next) decl.setModuleSpecifier(next)
|
|
323
|
-
}
|
|
324
|
-
for (const decl of sourceFile.getExportDeclarations()) {
|
|
325
|
-
const spec = decl.getModuleSpecifierValue()
|
|
326
|
-
if (!spec) continue
|
|
327
|
-
const next = rewrite(spec)
|
|
328
|
-
if (next) decl.setModuleSpecifier(next)
|
|
329
|
-
}
|
|
125
|
+
export async function loadUiComponentDocs(
|
|
126
|
+
registryName: string,
|
|
127
|
+
registryRoot: string = PACKAGE_ROOT
|
|
128
|
+
): Promise<string> {
|
|
129
|
+
const itemName = registryItemName(registryName)
|
|
130
|
+
const path = join(registryRoot, 'ui-components', 'docs', `${itemName}.md`)
|
|
131
|
+
const file = Bun.file(path)
|
|
132
|
+
if (!(await file.exists())) throw new Error(`Missing local docs for "${itemName}": ${path}`)
|
|
133
|
+
return file.text()
|
|
330
134
|
}
|
|
331
135
|
|
|
332
|
-
// The portal codemod. Base UI overlays portal into document.body — outside
|
|
333
|
-
// the applet container, so the applet's scoped styles ([data-applet="…"] …,
|
|
334
|
-
// see server/bundler/applet-css.ts) stop matching and overlays render on
|
|
335
|
-
// accidentally borrowed host styles. Overlays should keep portalling to body
|
|
336
|
-
// (escaping the widget frame's overflow/stacking is the point) — so instead
|
|
337
|
-
// of re-containering them, every `<X.Portal …>` JSX element is rewritten to
|
|
338
|
-
// `<AppletPortal portal={X.Portal} …>`, a wrapper (installed as
|
|
339
|
-
// `ui/applet-portal.tsx`) that re-establishes the scope attribute on the
|
|
340
|
-
// portalled subtree. Type positions (`X.Portal.Props`) are untouched — the
|
|
341
|
-
// rewrite only sees JSX tag names.
|
|
342
|
-
// `SyntaxKind` is passed in rather than imported: ts-morph is loaded lazily by
|
|
343
|
-
// the one caller below, so this helper cannot close over a module-level import.
|
|
344
|
-
function rewritePortals(
|
|
345
|
-
sourceFile: SourceFile,
|
|
346
|
-
SyntaxKind: typeof import('ts-morph').SyntaxKind
|
|
347
|
-
): boolean {
|
|
348
|
-
const PORTAL_TAG = /^[A-Za-z_$][\w$]*\.Portal$/
|
|
349
|
-
let touched = false
|
|
350
|
-
|
|
351
|
-
for (const el of sourceFile.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)) {
|
|
352
|
-
if (!PORTAL_TAG.test(el.getTagNameNode().getText())) continue
|
|
353
|
-
const portalExpr = el.getTagNameNode().getText()
|
|
354
|
-
el.getTagNameNode().replaceWithText('AppletPortal')
|
|
355
|
-
el.insertAttribute(0, { name: 'portal', initializer: `{${portalExpr}}` })
|
|
356
|
-
touched = true
|
|
357
|
-
}
|
|
358
|
-
for (const el of sourceFile.getDescendantsOfKind(SyntaxKind.JsxElement)) {
|
|
359
|
-
const opening = el.getOpeningElement()
|
|
360
|
-
if (!PORTAL_TAG.test(opening.getTagNameNode().getText())) continue
|
|
361
|
-
const portalExpr = opening.getTagNameNode().getText()
|
|
362
|
-
opening.getTagNameNode().replaceWithText('AppletPortal')
|
|
363
|
-
el.getClosingElement().getTagNameNode().replaceWithText('AppletPortal')
|
|
364
|
-
opening.insertAttribute(0, { name: 'portal', initializer: `{${portalExpr}}` })
|
|
365
|
-
touched = true
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
if (touched) {
|
|
369
|
-
sourceFile.addImportDeclaration({
|
|
370
|
-
moduleSpecifier: './applet-portal',
|
|
371
|
-
namedImports: [{ name: 'AppletPortal' }]
|
|
372
|
-
})
|
|
373
|
-
}
|
|
374
|
-
return touched
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
// One shared ts-morph project for all transforms in a process — creating a
|
|
378
|
-
// Project per file re-parses lib.d.ts and dominates runtime.
|
|
379
|
-
let project: Project | undefined
|
|
380
|
-
|
|
381
|
-
// Apply moi's transform pipeline to one raw registry file: shadcn's own icon
|
|
382
|
-
// transform (IconPlaceholder → @tabler/icons-react) and menu transform
|
|
383
|
-
// (cn-menu-* classes for the default menu color), then the relative-import
|
|
384
|
-
// rewrite and the portal codemod.
|
|
385
|
-
export async function transformUiComponentSource(name: string, raw: string): Promise<string> {
|
|
386
|
-
const { Project, ScriptKind, SyntaxKind } = await import('ts-morph')
|
|
387
|
-
const { transformIcons, transformMenu } = await import('shadcn/utils')
|
|
388
|
-
|
|
389
|
-
project ??= new Project({ useInMemoryFileSystem: true })
|
|
390
|
-
const sourceFile = project.createSourceFile(`moi-ui/${name}`, raw, {
|
|
391
|
-
scriptKind: name.endsWith('.tsx') ? ScriptKind.TSX : ScriptKind.TS,
|
|
392
|
-
overwrite: true
|
|
393
|
-
})
|
|
394
|
-
const opts = { sourceFile, filename: name, raw, config: ENGINE_CONFIG }
|
|
395
|
-
await transformIcons(opts)
|
|
396
|
-
await transformMenu(opts)
|
|
397
|
-
rewriteRegistryImports(sourceFile)
|
|
398
|
-
rewritePortals(sourceFile, SyntaxKind)
|
|
399
|
-
return sourceFile.getFullText()
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// ---------------------------------------------------------------------------
|
|
403
|
-
// The AppletPortal helper — installed once as `ui/applet-portal.tsx`
|
|
404
|
-
// ---------------------------------------------------------------------------
|
|
405
|
-
|
|
406
|
-
// Embedded as a string like the other scaffold templates (see
|
|
407
|
-
// moi-scaffold.ts): the file belongs to the workspace, not to moi's bundle.
|
|
408
|
-
// The hidden marker renders where the overlay is used — inside the applet's
|
|
409
|
-
// DOM — and reads the nearest `data-applet` scope; the portalled children
|
|
410
|
-
// then render under an element carrying the same attribute, so the applet's
|
|
411
|
-
// scoped CSS matches again. `display: contents` keeps the wrapper out of
|
|
412
|
-
// layout; theme variables still resolve from the host `:root`.
|
|
413
|
-
//
|
|
414
|
-
// The file header below is written for its actual reader — the workspace
|
|
415
|
-
// agent browsing `.moi/ui/` — so it stays non-technical: what the file is
|
|
416
|
-
// for, that it's auto-generated, and that it must be left alone. The
|
|
417
|
-
// mechanism belongs here, not there.
|
|
418
|
-
export const APPLET_PORTAL_SOURCE = `"use client"
|
|
419
|
-
|
|
420
|
-
// Auto-generated by \`moi ui-components add\` — do not edit or remove.
|
|
421
|
-
//
|
|
422
|
-
// Keeps overlays (dialogs, menus, popovers, tooltips) styled correctly when
|
|
423
|
-
// they render outside the applet's own container. Components in this folder
|
|
424
|
-
// use it automatically; you never import it yourself.
|
|
425
|
-
import * as React from "react"
|
|
426
|
-
|
|
427
|
-
type AppletPortalProps = {
|
|
428
|
-
portal: React.ElementType
|
|
429
|
-
children?: React.ReactNode
|
|
430
|
-
} & Record<string, unknown>
|
|
431
|
-
|
|
432
|
-
function AppletPortal({ portal: Portal, children, ...props }: AppletPortalProps) {
|
|
433
|
-
const [scope, setScope] = React.useState<string | undefined>(undefined)
|
|
434
|
-
const marker = React.useCallback((node: HTMLElement | null) => {
|
|
435
|
-
if (node) {
|
|
436
|
-
setScope(node.closest("[data-applet]")?.getAttribute("data-applet") ?? undefined)
|
|
437
|
-
}
|
|
438
|
-
}, [])
|
|
439
|
-
return (
|
|
440
|
-
<>
|
|
441
|
-
<span hidden ref={marker} />
|
|
442
|
-
<Portal {...props}>
|
|
443
|
-
<div data-applet={scope} style={{ display: "contents" }}>
|
|
444
|
-
{children}
|
|
445
|
-
</div>
|
|
446
|
-
</Portal>
|
|
447
|
-
</>
|
|
448
|
-
)
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
export { AppletPortal }
|
|
452
|
-
`
|
|
453
|
-
|
|
454
136
|
// ---------------------------------------------------------------------------
|
|
455
137
|
// Name resolution + write planning (pure — covered by tests)
|
|
456
138
|
// ---------------------------------------------------------------------------
|
|
457
139
|
|
|
458
140
|
export type ResolvedRequest = {
|
|
459
|
-
//
|
|
141
|
+
// Registry items requested, validated and deduplicated.
|
|
460
142
|
entries: string[]
|
|
461
|
-
// Registry items to fetch (patterns expanded), deduplicated, in request order.
|
|
462
|
-
registryItems: string[]
|
|
463
|
-
// Union of extraDeps across the requested entries.
|
|
464
|
-
extraDeps: string[]
|
|
465
143
|
unknown: string[]
|
|
466
144
|
}
|
|
467
145
|
|
|
468
146
|
export function resolveUiComponentRequest(names: string[]): ResolvedRequest {
|
|
469
147
|
const entries: string[] = []
|
|
470
|
-
const registryItems: string[] = []
|
|
471
|
-
const extraDeps = new Set<string>()
|
|
472
148
|
const unknown: string[] = []
|
|
473
149
|
|
|
474
150
|
for (const raw of names) {
|
|
@@ -478,14 +154,11 @@ export function resolveUiComponentRequest(names: string[]): ResolvedRequest {
|
|
|
478
154
|
unknown.push(raw)
|
|
479
155
|
continue
|
|
480
156
|
}
|
|
481
|
-
if (
|
|
482
|
-
|
|
483
|
-
if (!registryItems.includes(item)) registryItems.push(item)
|
|
484
|
-
}
|
|
485
|
-
for (const dep of entry.extraDeps ?? []) extraDeps.add(dep)
|
|
157
|
+
if (entries.includes(name)) continue
|
|
158
|
+
entries.push(name)
|
|
486
159
|
}
|
|
487
160
|
|
|
488
|
-
return { entries,
|
|
161
|
+
return { entries, unknown }
|
|
489
162
|
}
|
|
490
163
|
|
|
491
164
|
// Closest catalog names for a typo, by shared-prefix + substring heuristics —
|
|
@@ -520,7 +193,7 @@ export type PlannedWrite = {
|
|
|
520
193
|
content: string
|
|
521
194
|
// Whether a file already exists at the target path.
|
|
522
195
|
exists: boolean
|
|
523
|
-
// Support files ride along with a request (utils,
|
|
196
|
+
// Support files ride along with a request (utils, scoped-portal, registry
|
|
524
197
|
// deps of a requested component). Existing support files are never
|
|
525
198
|
// overwritten — they may carry hand customizations; existing requested
|
|
526
199
|
// files fail the add unless --force.
|
|
@@ -536,9 +209,6 @@ export type UiWritePartition = {
|
|
|
536
209
|
// Requested components already installed, skipped without --force — a bulk
|
|
537
210
|
// add proceeds past them instead of failing the whole batch.
|
|
538
211
|
skipInstalled: PlannedWrite[]
|
|
539
|
-
// Every requested file already exists and --force is off: the add would be
|
|
540
|
-
// a no-op, so the CLI fails loudly instead of quietly keeping everything.
|
|
541
|
-
allInstalled: boolean
|
|
542
212
|
}
|
|
543
213
|
|
|
544
214
|
export function partitionUiWrites(plans: PlannedWrite[], force: boolean): UiWritePartition {
|
|
@@ -547,28 +217,25 @@ export function partitionUiWrites(plans: PlannedWrite[], force: boolean): UiWrit
|
|
|
547
217
|
return {
|
|
548
218
|
write: plans.filter(plan => !plan.exists || (force && !plan.support)),
|
|
549
219
|
keepSupport: plans.filter(plan => plan.support && plan.exists),
|
|
550
|
-
skipInstalled
|
|
551
|
-
allInstalled: !force && requested.length > 0 && skipInstalled.length === requested.length
|
|
220
|
+
skipInstalled
|
|
552
221
|
}
|
|
553
222
|
}
|
|
554
223
|
|
|
555
224
|
export function planUiWrites(opts: {
|
|
556
|
-
files:
|
|
557
|
-
|
|
225
|
+
files: LoadedUiFile[]
|
|
226
|
+
requestedFiles: string[]
|
|
558
227
|
uiDir: string
|
|
559
228
|
exists: (path: string) => boolean
|
|
560
229
|
}): PlannedWrite[] {
|
|
561
|
-
const requested = new Set(opts.
|
|
562
|
-
const plans: PlannedWrite[] =
|
|
563
|
-
...opts.files.map(file => ({
|
|
564
|
-
name: file.name,
|
|
565
|
-
content: file.content,
|
|
566
|
-
support: !requested.has(file.name)
|
|
567
|
-
})),
|
|
568
|
-
{ name: 'applet-portal.tsx', content: APPLET_PORTAL_SOURCE, support: true }
|
|
569
|
-
].map(file => {
|
|
230
|
+
const requested = new Set(opts.requestedFiles)
|
|
231
|
+
const plans: PlannedWrite[] = opts.files.map(file => {
|
|
570
232
|
const path = join(opts.uiDir, file.name)
|
|
571
|
-
return {
|
|
233
|
+
return {
|
|
234
|
+
...file,
|
|
235
|
+
path,
|
|
236
|
+
exists: opts.exists(path),
|
|
237
|
+
support: !requested.has(file.name)
|
|
238
|
+
}
|
|
572
239
|
})
|
|
573
240
|
return plans
|
|
574
241
|
}
|
package/server/view-builders.ts
CHANGED
|
@@ -14,6 +14,7 @@ type ViewBuilderStore = Record<string, ViewBuilder[]>
|
|
|
14
14
|
// `waiting`, even if its session still looks live. Generous so a slow but real
|
|
15
15
|
// build is never cut off mid-flight.
|
|
16
16
|
const STALE_BUILD_MS = 10 * 60_000
|
|
17
|
+
const APP_ICON_NAMES: readonly string[] = APP_ICON_IDS
|
|
17
18
|
|
|
18
19
|
export class ViewBuilderError extends Error {
|
|
19
20
|
status: 400 | 404 | 409
|
|
@@ -198,7 +199,7 @@ export async function setBuilder(
|
|
|
198
199
|
}
|
|
199
200
|
if (input.icon !== undefined && !isAppIconId(input.icon)) {
|
|
200
201
|
throw new ViewBuilderError(
|
|
201
|
-
`Unknown view icon id "${input.icon}". Use one of: ${
|
|
202
|
+
`Unknown view icon id "${input.icon}". Use one of: ${APP_ICON_NAMES.join(', ')}`,
|
|
202
203
|
400
|
|
203
204
|
)
|
|
204
205
|
}
|