moi-computer 0.7.0 → 0.8.1-next.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/api/workspace-keys.ts +1 -2
- package/client/app/AppRouter.tsx +10 -3
- package/client/app/routes/HomeRoute.tsx +1 -1
- package/client/app/shell/SidebarLayout.tsx +2 -14
- package/client/components/shared/BottomPanel.tsx +2 -1
- package/client/components/shared/Composer.tsx +20 -7
- package/client/components/shared/PanelHeader.tsx +8 -1
- package/client/components/ui/button.tsx +3 -3
- package/client/components/ui/dialog.tsx +1 -1
- package/client/components/ui/dropdown-menu.tsx +2 -2
- package/client/components/ui/hover-card.tsx +1 -1
- package/client/components/ui/popover.tsx +1 -1
- package/client/components/ui/resizable.tsx +40 -0
- 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/ChatEmptyState.tsx +9 -11
- package/client/features/chat/ChatPanel.tsx +76 -48
- package/client/features/chat/ChatPopup.tsx +16 -2
- package/client/features/chat/ChatPromptBubbles.tsx +6 -8
- package/client/features/chat/ChatSelector.tsx +25 -8
- package/client/features/chat/ModelPicker.tsx +5 -4
- package/client/features/chat/TurnView.tsx +108 -13
- package/client/features/chat/api.ts +1 -18
- package/client/features/chat/chat-send.ts +2 -2
- package/client/features/chat/{ChatComposer.tsx → composer/ChatComposer.tsx} +24 -9
- package/client/features/chat/composer/banners/ChatErrorBanner.tsx +28 -0
- package/client/features/chat/composer/banners/ComposerBanner.tsx +30 -0
- package/client/features/chat/composer/banners/WorkspaceAgentAvailabilityBanner.tsx +91 -0
- package/client/features/{workspace → chat/composer/banners}/WorkspaceSkillUpdateBanner.tsx +9 -7
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +74 -0
- package/client/features/{workspace → chat/composer}/useWorkspaceSkillUpdates.ts +1 -1
- package/client/features/chat/group-turns.ts +46 -28
- package/client/features/chat/interleave-notices.ts +84 -0
- package/client/features/chat/model-order.ts +9 -3
- package/client/features/chat/tool-group/TimelineRow.tsx +23 -11
- package/client/features/chat/tool-group/ToolCallGroup.tsx +38 -3
- package/client/features/chat/tool-group/format.ts +23 -7
- package/client/features/chat/useAppletChatMessage.ts +11 -16
- package/client/features/chat/useChat.ts +3 -7
- package/client/features/dev/ChatStatesPage.tsx +428 -0
- package/client/features/dev/DevIndexPage.tsx +52 -0
- package/client/features/dev/DevRoutes.tsx +6 -3
- package/client/features/dev/HarnessDebugPage.tsx +3 -3
- package/client/features/dev/chat-states-fixtures.ts +744 -0
- 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 +5 -3
- package/client/features/scratchpad/scratch-session.ts +71 -0
- package/client/features/views/ViewBuilderTab.tsx +5 -4
- package/client/features/views/ViewManager.tsx +258 -0
- package/client/features/views/useViewBuilderActions.ts +2 -2
- 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 +12 -2
- package/client/features/workspace/WorkspaceScreen.tsx +131 -201
- package/client/features/workspace/WorkspaceSplitLayout.tsx +111 -0
- package/client/features/workspace/WorkspaceTabs.tsx +1 -1
- package/client/features/workspace/api.ts +33 -8
- package/client/features/workspace/useFitsSplitLayout.ts +31 -5
- package/client/index.css +5 -2
- package/client/lib/flags.ts +4 -3
- package/client/runtime/useWorkspaceEvents.ts +18 -1
- package/client/runtime/workspace-theme.ts +29 -10
- package/client/store/ui.ts +5 -1
- package/client/theme.css +96 -6
- package/dist/{chunk-0pcdwjkp.js → chunk-2vaafjp4.js} +1 -1
- package/dist/{chunk-9y2zbzqz.js → chunk-35fq49qa.js} +1 -1
- package/dist/chunk-gny990qx.css +1 -0
- package/dist/chunk-gt7n06ef.js +1 -0
- package/dist/{chunk-rxvx4ta9.js → chunk-kkj86722.js} +75 -75
- package/dist/chunk-n7pga5x3.js +80 -0
- package/dist/chunk-xeyxk7ep.js +10 -0
- package/dist/{chunk-w3tnv51j.js → chunk-xzx7c9hq.js} +1 -1
- package/dist/index.html +1 -1
- package/lib/format.ts +17 -1
- package/lib/themes.ts +123 -51
- package/lib/types.ts +40 -13
- package/lib/workspace-layout.ts +2 -2
- package/package.json +6 -4
- package/server/agent.ts +199 -0
- package/server/api.ts +38 -90
- package/server/bundler/build-applet.ts +7 -4
- package/server/cli.ts +46 -15
- package/server/control.ts +13 -6
- package/server/env-apply.ts +4 -0
- package/server/harness/README.md +28 -12
- package/server/harness/claude-code/auth.ts +54 -0
- package/server/harness/claude-code/index.ts +6 -1
- package/server/harness/codex/adapter.ts +9 -1
- package/server/harness/codex/auth.ts +50 -0
- package/server/harness/codex/index.ts +6 -1
- package/server/harness/codex/session.ts +33 -14
- package/server/harness/openclaw/NOTES.md +518 -187
- package/server/harness/openclaw/adapter.ts +125 -31
- package/server/harness/openclaw/compat.ts +99 -0
- package/server/harness/openclaw/cron-view.ts +78 -0
- package/server/harness/openclaw/discovery.ts +145 -52
- package/server/harness/openclaw/gateway.ts +224 -36
- package/server/harness/openclaw/index.ts +56 -21
- package/server/harness/openclaw/session.ts +971 -55
- package/server/harness/openclaw/strip.ts +87 -15
- package/server/harness/openclaw/thinking.ts +198 -0
- package/server/harness/types.ts +10 -5
- package/server/layout.ts +5 -2
- package/server/moi-scaffold.ts +1 -1
- package/server/registry.ts +0 -20
- package/server/theme.ts +24 -27
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +100 -53
- package/workspace/.claude/skills/moi-workspace/SKILL.md +10 -12
- package/client/features/dev/PixelPainter.tsx +0 -94
- package/client/features/dev/PlaygroundPage.tsx +0 -69
- package/dist/chunk-175bm057.js +0 -27
- package/dist/chunk-55sh4dty.js +0 -2
- package/dist/chunk-afgbg75t.js +0 -50
- package/dist/chunk-agtetn7n.css +0 -1
- package/dist/chunk-dfs36zgc.js +0 -1
- package/dist/chunk-exj6hr30.js +0 -9
- package/dist/chunk-m11ckkxd.js +0 -51
|
@@ -29,57 +29,107 @@ spacing, or interaction patterns. They do not need to look identical.
|
|
|
29
29
|
|
|
30
30
|
## Color
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
Widgets and views use the same semantic token vocabulary. Use
|
|
33
|
+
`h-full w-full bg-background text-foreground` for most applet roots. Each token keeps the same
|
|
34
|
+
purpose in both applet types; the host changes its value to suit the surrounding surface.
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
use dark-mode values regardless of the workspace color preset. The host frame stays transparent, so
|
|
36
|
-
every widget root must cover the full frame with an opaque background.
|
|
36
|
+
### How tokens resolve
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
- **Widgets:** The host applies a widget-local semantic theme derived from the selected workspace
|
|
39
|
+
color. `background` is the workspace `primary`, `foreground` is its paired readable color, and
|
|
40
|
+
the local `primary` pair becomes the light action surface derived from that color. The host frame
|
|
41
|
+
stays transparent, so every widget root must cover the full frame with an opaque background. An
|
|
42
|
+
image or visualization may own the surface when it has an opaque fallback.
|
|
43
|
+
- **Views:** Semantic tokens inherit the workspace page theme. The default root uses the normal
|
|
44
|
+
workspace page surface and text.
|
|
45
|
+
- **Portalled UI:** Menus, tooltips, and popovers render in workspace scope and keep
|
|
46
|
+
`bg-popover text-popover-foreground`.
|
|
42
47
|
|
|
43
|
-
|
|
44
|
-
fits. In the widget scope, it resolves to a dark background with light text.
|
|
45
|
-
|
|
46
|
-
### View surfaces
|
|
47
|
-
|
|
48
|
-
Views are separate pages. Their semantic tokens inherit the workspace theme, so
|
|
49
|
-
`h-full w-full bg-background text-foreground` is a sensible default root.
|
|
48
|
+
### Semantic token reference
|
|
50
49
|
|
|
51
50
|
| Context or intent | Tailwind classes | Use |
|
|
52
51
|
| --- | --- | --- |
|
|
53
|
-
|
|
|
54
|
-
|
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
| Inset surface | `bg-card text-card-foreground` | A real contained object or raised region inside the applet |
|
|
52
|
+
| Applet root | `bg-background text-foreground` | The full widget surface or view page |
|
|
53
|
+
| Main content | `text-foreground` | Titles, labels, values, and important icons |
|
|
54
|
+
| Supporting content | `text-muted-foreground` | Descriptions and secondary information |
|
|
55
|
+
| Inset surface | `bg-card text-card-foreground` | A functionally distinct contained region, used sparingly |
|
|
58
56
|
| Floating surface | `bg-popover text-popover-foreground` | Menus, tooltips, and other floating content |
|
|
59
|
-
|
|
|
60
|
-
|
|
|
61
|
-
|
|
|
62
|
-
|
|
|
63
|
-
|
|
|
57
|
+
| Quiet fill | `bg-muted` | Inset regions, skeletons, and disabled structure |
|
|
58
|
+
| Control state | `bg-accent text-accent-foreground` | Hover, active, and selected controls |
|
|
59
|
+
| Main action | `bg-primary text-primary-foreground hover:bg-primary/90` | The most important action in a local region |
|
|
60
|
+
| Positive or active state | `text-success` / `bg-success/10` | Positive outcomes, healthy states, presence, and progress indicators |
|
|
61
|
+
| Error or danger | `text-destructive` / `bg-destructive/10` | Errors, destructive actions, and invalid states |
|
|
62
|
+
| Object edge | `ring-1 ring-border` | Complete outlines around containers and controls |
|
|
63
|
+
| Focus | `focus-visible:ring-2 focus-visible:ring-ring` | Visible keyboard focus on interactive elements |
|
|
64
|
+
| Separator | `border-b border-border` | A one-sided division between adjacent regions |
|
|
64
65
|
|
|
65
66
|
Use lower opacity from the surface's foreground only for tertiary metadata that remains readable.
|
|
66
|
-
Avoid weak alpha text for important labels or values.
|
|
67
|
-
|
|
67
|
+
Avoid weak alpha text for important labels or values.
|
|
68
|
+
|
|
69
|
+
Prefer a subtle ring for the complete outline of a container or control. Use `ring-1 ring-border` on
|
|
70
|
+
semantic surfaces. Reserve one-sided borders such as `border-b` for separators between adjacent
|
|
71
|
+
regions. Never use a border and a ring on the same element. Avoid raw high-contrast colors for
|
|
72
|
+
either treatment.
|
|
73
|
+
|
|
74
|
+
Derive extra neutral or tonal colors and custom gradients from the local semantic tokens with
|
|
75
|
+
`color-mix()`. Use Tailwind palette colors only when they have clear content meaning, distinguish
|
|
76
|
+
infographic data, or follow an explicit user request. Keep each mapping consistent and explain it
|
|
77
|
+
with labels, legends, shapes, or direct values. Do not use palette colors for generic decoration or
|
|
78
|
+
unrelated widget backgrounds. Purple, violet, and fuchsia need a content, brand, or user reason;
|
|
79
|
+
never use a purple gradient as a default creativity or technology cue. On a saturated surface,
|
|
80
|
+
choose an explicit light or dark foreground with strong contrast.
|
|
81
|
+
|
|
82
|
+
### Surfaces and grouping
|
|
83
|
+
|
|
84
|
+
Use an open layout by default. Group content with spacing, alignment, type hierarchy, and, when
|
|
85
|
+
needed, a one-sided separator. Add one surface around content that shares a functional boundary: an
|
|
86
|
+
interactive object, an independently scrolling region, a distinct state, or a self-contained work
|
|
87
|
+
region. Page headers, tab rows, summaries, metrics, and ordinary sections stay unboxed by default.
|
|
88
|
+
Standard controls keep their normal component surfaces.
|
|
89
|
+
|
|
90
|
+
Never use a large rounded surface as a second page frame around the header, navigation, summary,
|
|
91
|
+
primary content, and supporting sections. Avoid adjacent or nested cards and wrappers that only
|
|
92
|
+
repeat the page structure.
|
|
93
|
+
|
|
94
|
+
Align page-level content to shared edges or grid columns. Apply outer padding once on the root or
|
|
95
|
+
layout grid, then use gaps to group unboxed content. When removing a surface, remove its card-like
|
|
96
|
+
padding and radius and realign its children; do not leave spacing that implies an invisible card.
|
|
97
|
+
|
|
98
|
+
### Textures
|
|
99
|
+
|
|
100
|
+
Texture is optional. Choose the root treatment after the content layout is clear, and use no more
|
|
101
|
+
than one texture per applet. Pair a texture with an opaque semantic base, such as
|
|
102
|
+
`h-full w-full bg-background text-foreground texture-checker`. The same classes resolve through the
|
|
103
|
+
widget-local theme or view page theme.
|
|
104
|
+
|
|
105
|
+
| Texture | Tailwind class | Character |
|
|
106
|
+
| --- | --- | --- |
|
|
107
|
+
| Checker | `texture-checker` | Two softly tinted semantic squares with no empty cells |
|
|
108
|
+
| Grid | `texture-grid` | Fine semantic graph-paper lines over the base color |
|
|
109
|
+
| Noise | `texture-noise` | Foreground-tinted fractal grain that lets the base tint show through |
|
|
110
|
+
| Linear gradient | `texture-gradient-linear` | A restrained top-to-bottom wash derived from `primary` |
|
|
111
|
+
| Inset shadow | `texture-inset-shadow` | A soft edge glow derived from `primary` |
|
|
112
|
+
|
|
113
|
+
Textures add an effect without setting `background-color`; the base color remains visible through
|
|
114
|
+
them. Match the frequency of the background to the density of the content:
|
|
68
115
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
116
|
+
| Content and layout | Root treatment |
|
|
117
|
+
| --- | --- |
|
|
118
|
+
| Dense content placed directly on the root, such as tables, long lists, forms, detailed charts, or multi-column dashboards | Plain `bg-background`, `texture-gradient-linear`, or `texture-inset-shadow` |
|
|
119
|
+
| Sparse content with large quiet areas | Any texture that preserves contrast |
|
|
120
|
+
| Dense content inside a functionally justified opaque or tonal work surface | A checker, grid, or noise texture may appear on the exposed background |
|
|
121
|
+
| Opaque full-bleed image, map, canvas, or visualization | No texture |
|
|
72
122
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
123
|
+
Never place `texture-checker`, `texture-grid`, or `texture-noise` directly behind dense open content.
|
|
124
|
+
Do not add cards or solid wrappers only to make a busy texture readable; choose a quieter root
|
|
125
|
+
treatment instead. A texture should become easy to ignore while reading.
|
|
76
126
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
gradient only when it encodes information or is essential to the specific content.
|
|
127
|
+
Do not apply a texture to a card, panel, control, or text region, and do not stack textures or add
|
|
128
|
+
tuning variables.
|
|
80
129
|
|
|
81
|
-
|
|
82
|
-
|
|
130
|
+
Check nearby widgets and views before choosing one. Give unrelated applets different textures so
|
|
131
|
+
they remain distinct at a glance. A widget that opens, summarizes, or represents a view shares that
|
|
132
|
+
view's texture as part of the same visual language.
|
|
83
133
|
|
|
84
134
|
## Typography and hierarchy
|
|
85
135
|
|
|
@@ -154,6 +204,8 @@ Data-driven applets need the following when applicable:
|
|
|
154
204
|
|
|
155
205
|
Keep state layouts stable so loading, success, empty, and error do not cause avoidable jumps. Errors
|
|
156
206
|
and empty states should still fit the configured widget height or the view's normal content frame.
|
|
207
|
+
When a primary region uses a surface, loading, populated, empty, success, and error states keep that
|
|
208
|
+
surface in the same position and size.
|
|
157
209
|
|
|
158
210
|
## Widgets
|
|
159
211
|
|
|
@@ -234,21 +286,16 @@ stretching a widget-like card to fill the page.
|
|
|
234
286
|
|
|
235
287
|
## Final review
|
|
236
288
|
|
|
237
|
-
After implementation, do a removal pass from top to bottom. For every
|
|
238
|
-
|
|
239
|
-
|
|
289
|
+
After implementation, do a removal pass from top to bottom. For every visible element and wrapper,
|
|
290
|
+
ask what it helps the user understand, do, or recognize as a state. Remove it when the screen stays
|
|
291
|
+
clear without it, then realign the remaining content.
|
|
240
292
|
|
|
241
293
|
Before finishing an applet, confirm:
|
|
242
294
|
|
|
243
|
-
-
|
|
244
|
-
-
|
|
245
|
-
-
|
|
246
|
-
-
|
|
247
|
-
-
|
|
248
|
-
-
|
|
249
|
-
|
|
250
|
-
- Custom container outlines suit their surface and stay subtle.
|
|
251
|
-
- The layout handles realistic content and deliberate overflow.
|
|
252
|
-
- Every control is necessary, complete, and accessible.
|
|
253
|
-
- The widget or view follows its frame, sizing, and scrolling rules.
|
|
254
|
-
- It feels related to the workspace without copying the quieter host shell.
|
|
295
|
+
- The first reading and every visible element have a clear purpose.
|
|
296
|
+
- Color, texture, type, spacing, and expression support the content and remain readable.
|
|
297
|
+
- Surfaces mark real boundaries, and unboxed page content shares clear alignment axes.
|
|
298
|
+
- States remain stable, and the layout handles realistic content and deliberate overflow.
|
|
299
|
+
- Controls are necessary, complete, and accessible.
|
|
300
|
+
- The widget or view follows its frame, sizing, and scrolling rules and feels related to the
|
|
301
|
+
workspace.
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: moi-workspace
|
|
3
|
-
description:
|
|
4
|
-
The moi workspace — the web UI the user chats from, extended with agent-authored applets
|
|
5
|
-
(widgets, views) plus theme & config. Read this FIRST in two cases. (a) A message carries a hidden
|
|
6
|
-
moi-context envelope: it was fired from a moi workspace, so you are running inside one even if
|
|
7
|
-
nothing else says so. (b) The user uses moi vocab — workspace, applet, widget, view, scratchpad,
|
|
8
|
-
dashboard, or a `moi` command — or asks to build, edit, customize, or theme the workspace UI or
|
|
9
|
-
its layout.
|
|
3
|
+
description: The moi workspace — the web UI the user chats from, extended with agent-authored applets (widgets, views) plus theme & config. Read this FIRST when a message carries a hidden moi-context envelope or the user uses moi vocab such as workspace, applet, widget, view, scratchpad, dashboard, or a `moi` command, or asks to build, edit, customize, or theme the workspace UI or its layout.
|
|
10
4
|
---
|
|
11
5
|
|
|
12
6
|
# Workspace
|
|
@@ -127,6 +121,7 @@ never from inside `.moi/` itself. You don't pass paths; moi resolves the workspa
|
|
|
127
121
|
- `moi debug logs` — applet runtime errors on record (experimental)
|
|
128
122
|
- `moi theme --font=<key>` — change font theme (omit `--font` to list options)
|
|
129
123
|
- `moi theme --color=<key>` — change color preset (omit `--color` to list options)
|
|
124
|
+
- `moi theme --radius=<key>` — change corner-radius preset (omit `--radius` to list options)
|
|
130
125
|
- `moi config` — set the workspace name & icon (`moi config --help` for usage)
|
|
131
126
|
- `moi env` — list available env keys and where they come from (never values);
|
|
132
127
|
`moi env exec -- <cmd>` runs a command with the workspace env (see Environment & secrets)
|
|
@@ -336,9 +331,12 @@ Render **content only**: a plain `h-full w-full` region with no card chrome (`ro
|
|
|
336
331
|
own the fill, so the widget must set its own opaque background.
|
|
337
332
|
Changing `colSpan`/`rowSpan` needs `moi bundle --force`. See `DESIGN.md`.
|
|
338
333
|
|
|
339
|
-
Typical loop: check/`bun install` deps → write
|
|
340
|
-
|
|
341
|
-
|
|
334
|
+
Typical loop: check/`bun install` deps → write the applet → `moi bundle` → run any checks.
|
|
335
|
+
After the final successful bundle and any checks, always make tab focus the final workspace action:
|
|
336
|
+
|
|
337
|
+
- After building or editing a widget, run `moi tab focus widgets`.
|
|
338
|
+
- After building or editing a view, run `moi tab focus view:<view-id>`, using its file name or claimed
|
|
339
|
+
builder id.
|
|
342
340
|
|
|
343
341
|
# Debugging applets
|
|
344
342
|
|
|
@@ -381,7 +379,7 @@ moi builder set <view-id> --builder <builder-id> --kind view --title "<title>" -
|
|
|
381
379
|
Choose the icon id from the available view icons in the hidden context. The id must use lowercase
|
|
382
380
|
letters, numbers, `_`, or `-`. The first call locks the id; running the same command again may update
|
|
383
381
|
its title and icon. After claiming, write `.moi/views/<view-id>.tsx`, use the same icon id in its
|
|
384
|
-
config, and
|
|
382
|
+
config, and build it with `moi bundle --only views`. The tab uses the claimed title and icon while you
|
|
385
383
|
work and changes into the built view after a successful bundle. (Bundling marks the view ready; the
|
|
386
384
|
build state is otherwise server-managed, so you never set it to done by hand.)
|
|
387
385
|
|
|
@@ -408,4 +406,4 @@ This skill is installed with moi (via the CLI or the UI) and can fall behind whe
|
|
|
408
406
|
- **Then** — if you updated, mention it.
|
|
409
407
|
|
|
410
408
|
<!-- moi skill version marker — read by `moi skill` to detect drift; do not edit by hand -->
|
|
411
|
-
<moi-skill version="0.
|
|
409
|
+
<moi-skill version="0.11.0" />
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import { Button } from '@/client/components/ui/button'
|
|
4
|
-
import { cn } from '@/client/lib/cn'
|
|
5
|
-
|
|
6
|
-
const COLS = 5
|
|
7
|
-
const ROWS = 5
|
|
8
|
-
|
|
9
|
-
// Seed with the current M.
|
|
10
|
-
const SEED = ['.....', '####.', '#.#.#', '#.#.#', '#.#.#']
|
|
11
|
-
|
|
12
|
-
function fromRows(rows: string[]): boolean[][] {
|
|
13
|
-
return rows.map(row => [...row].map(ch => ch === '#'))
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function emptyGrid(): boolean[][] {
|
|
17
|
-
return Array.from({ length: ROWS }, () => Array.from({ length: COLS }, () => false))
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Simple 9×6 pixel painter: click or drag to toggle cells, then copy the
|
|
21
|
-
// `#`/`.` rows. Used to author the LED glyph by hand.
|
|
22
|
-
export function PixelPainter() {
|
|
23
|
-
const [grid, setGrid] = useState<boolean[][]>(() => fromRows(SEED))
|
|
24
|
-
const [painting, setPainting] = useState(false)
|
|
25
|
-
const paintValue = useRef(true)
|
|
26
|
-
const [copied, setCopied] = useState(false)
|
|
27
|
-
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
const stop = () => setPainting(false)
|
|
30
|
-
window.addEventListener('mouseup', stop)
|
|
31
|
-
return () => window.removeEventListener('mouseup', stop)
|
|
32
|
-
}, [])
|
|
33
|
-
|
|
34
|
-
function setCell(r: number, c: number, value: boolean) {
|
|
35
|
-
setGrid(g => {
|
|
36
|
-
if (g[r][c] === value) return g
|
|
37
|
-
const next = g.map(row => row.slice())
|
|
38
|
-
next[r][c] = value
|
|
39
|
-
return next
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function handleDown(r: number, c: number) {
|
|
44
|
-
const value = !grid[r][c]
|
|
45
|
-
paintValue.current = value
|
|
46
|
-
setPainting(true)
|
|
47
|
-
setCell(r, c, value)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function handleEnter(r: number, c: number) {
|
|
51
|
-
if (painting) setCell(r, c, paintValue.current)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const ascii = grid.map(row => row.map(on => (on ? '#' : '.')).join('')).join('\n')
|
|
55
|
-
|
|
56
|
-
async function copy() {
|
|
57
|
-
await navigator.clipboard.writeText(ascii)
|
|
58
|
-
setCopied(true)
|
|
59
|
-
setTimeout(() => setCopied(false), 1200)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
<div className="flex flex-col items-center gap-4">
|
|
64
|
-
<div className="grid w-fit grid-cols-[repeat(5,28px)] gap-px bg-border p-px select-none">
|
|
65
|
-
{grid.map((row, r) =>
|
|
66
|
-
row.map((on, c) => (
|
|
67
|
-
<div
|
|
68
|
-
key={`${r}-${c}`}
|
|
69
|
-
onMouseDown={() => handleDown(r, c)}
|
|
70
|
-
onMouseEnter={() => handleEnter(r, c)}
|
|
71
|
-
className={cn('size-7 cursor-pointer', on ? 'bg-foreground' : 'bg-background')}
|
|
72
|
-
/>
|
|
73
|
-
))
|
|
74
|
-
)}
|
|
75
|
-
</div>
|
|
76
|
-
|
|
77
|
-
<pre className="rounded-lg border border-border bg-card px-3 py-2 text-center font-mono text-sm leading-snug text-card-foreground">
|
|
78
|
-
{ascii}
|
|
79
|
-
</pre>
|
|
80
|
-
|
|
81
|
-
<div className="flex gap-2">
|
|
82
|
-
<Button type="button" size="sm" onClick={copy}>
|
|
83
|
-
{copied ? 'Copied!' : 'Copy'}
|
|
84
|
-
</Button>
|
|
85
|
-
<Button type="button" variant="secondary" size="sm" onClick={() => setGrid(emptyGrid())}>
|
|
86
|
-
Clear
|
|
87
|
-
</Button>
|
|
88
|
-
<Button type="button" variant="secondary" size="sm" onClick={() => setGrid(fromRows(SEED))}>
|
|
89
|
-
Reset
|
|
90
|
-
</Button>
|
|
91
|
-
</div>
|
|
92
|
-
</div>
|
|
93
|
-
)
|
|
94
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import { Button } from '@/client/components/ui/button'
|
|
4
|
-
|
|
5
|
-
import { type Effect, LedLogo, type Sprite } from '@/client/components/shared/LedLogo'
|
|
6
|
-
import { PixelPainter } from './PixelPainter'
|
|
7
|
-
|
|
8
|
-
const SPRITES: { value: Sprite; label: string }[] = [
|
|
9
|
-
{ value: 'moi', label: 'M' },
|
|
10
|
-
{ value: 'moi-full', label: 'moi' }
|
|
11
|
-
]
|
|
12
|
-
|
|
13
|
-
const EFFECTS: { value: Effect | 'none'; label: string }[] = [
|
|
14
|
-
{ value: 'none', label: 'None' },
|
|
15
|
-
{ value: 'wave', label: 'Wave' },
|
|
16
|
-
{ value: 'chaos', label: 'Random' }
|
|
17
|
-
]
|
|
18
|
-
|
|
19
|
-
type SegmentedProps<T extends string | number> = {
|
|
20
|
-
options: { value: T; label: string }[]
|
|
21
|
-
value: T
|
|
22
|
-
onChange: (value: T) => void
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function Segmented<T extends string | number>({ options, value, onChange }: SegmentedProps<T>) {
|
|
26
|
-
return (
|
|
27
|
-
<div className="flex gap-1 rounded-xl bg-accent p-1">
|
|
28
|
-
{options.map(o => (
|
|
29
|
-
<Button
|
|
30
|
-
key={String(o.value)}
|
|
31
|
-
type="button"
|
|
32
|
-
variant={value === o.value ? 'default' : 'ghost'}
|
|
33
|
-
size="sm"
|
|
34
|
-
onClick={() => onChange(o.value)}
|
|
35
|
-
>
|
|
36
|
-
{o.label}
|
|
37
|
-
</Button>
|
|
38
|
-
))}
|
|
39
|
-
</div>
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Scratch route for UI experiments. Add new experiments here over time.
|
|
44
|
-
export function PlaygroundPage() {
|
|
45
|
-
const [sprite, setSprite] = useState<Sprite>('moi')
|
|
46
|
-
const [effect, setEffect] = useState<Effect | 'none'>('none')
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<div className="relative flex min-h-dvh flex-col items-center justify-center gap-8 bg-muted">
|
|
50
|
-
<span className="absolute top-5 left-5 text-[11px] font-medium tracking-widest text-muted-foreground uppercase">
|
|
51
|
-
Playground
|
|
52
|
-
</span>
|
|
53
|
-
|
|
54
|
-
<PixelPainter />
|
|
55
|
-
|
|
56
|
-
<LedLogo
|
|
57
|
-
sprite={sprite}
|
|
58
|
-
effect={effect === 'none' ? undefined : effect}
|
|
59
|
-
pixelSize={3}
|
|
60
|
-
gap={0.5}
|
|
61
|
-
/>
|
|
62
|
-
|
|
63
|
-
<div className="flex flex-col items-center gap-2">
|
|
64
|
-
<Segmented options={SPRITES} value={sprite} onChange={setSprite} />
|
|
65
|
-
<Segmented options={EFFECTS} value={effect} onChange={setEffect} />
|
|
66
|
-
</div>
|
|
67
|
-
</div>
|
|
68
|
-
)
|
|
69
|
-
}
|