@handylib/kai-code 0.1.0 → 0.1.2
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 +87 -9
- package/dist/index.cjs +275 -43
- package/dist/index.css +138 -83
- package/dist/index.d.cts +33 -4
- package/dist/index.d.ts +33 -4
- package/dist/index.js +275 -43
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,9 +42,10 @@ export function Playground() {
|
|
|
42
42
|
}
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
KaiCode
|
|
46
|
-
give the component a sized parent. Monaco's worker
|
|
47
|
-
set up by your bundler, as with any application
|
|
45
|
+
KaiCode uses a viewport-responsive height by default. Set the `height` prop or
|
|
46
|
+
give the component a sized parent to control its dimensions. Monaco's worker
|
|
47
|
+
configuration may need to be set up by your bundler, as with any application
|
|
48
|
+
using Monaco Editor. See the
|
|
48
49
|
[`@monaco-editor/react` documentation](https://github.com/suren-atoyan/monaco-react)
|
|
49
50
|
for bundler-specific worker setup.
|
|
50
51
|
|
|
@@ -85,6 +86,18 @@ const fileSystem: KaiCodeFileSystem = {
|
|
|
85
86
|
async createFile(path, contents = "") {
|
|
86
87
|
await myStorage.writeText(path, contents);
|
|
87
88
|
},
|
|
89
|
+
async deleteFile(path) {
|
|
90
|
+
await myStorage.remove(path);
|
|
91
|
+
},
|
|
92
|
+
async deleteDirectory(path) {
|
|
93
|
+
await myStorage.removeTree(path);
|
|
94
|
+
},
|
|
95
|
+
async moveFile(oldPath, newPath) {
|
|
96
|
+
await myStorage.move(oldPath, newPath);
|
|
97
|
+
},
|
|
98
|
+
async moveDirectory(oldPath, newPath) {
|
|
99
|
+
await myStorage.moveTree(oldPath, newPath);
|
|
100
|
+
},
|
|
88
101
|
watch(listener) {
|
|
89
102
|
// Optional: call listener when files or directories change outside KaiCode.
|
|
90
103
|
return myStorage.subscribe(listener);
|
|
@@ -116,7 +129,9 @@ Optional methods:
|
|
|
116
129
|
| `createDirectory(path)` | Enables **New Folder** and creates the directory, including empty directories. |
|
|
117
130
|
| `deleteFile(path)` | Enables deleting files from the Explorer context menu. |
|
|
118
131
|
| `deleteDirectory(path)` | Enables deleting folders. The adapter must delete the folder and all of its descendants. |
|
|
119
|
-
| `
|
|
132
|
+
| `moveFile(oldPath, newPath)` | Enables moving files from the Explorer context menu. |
|
|
133
|
+
| `moveDirectory(oldPath, newPath)` | Enables moving folders. The adapter must move the folder and all of its descendants. |
|
|
134
|
+
| `renameFile(oldPath, newPath)` | Backward-compatible fallback for `moveFile`. Prefer implementing `moveFile`. |
|
|
120
135
|
| `watch(listener)` | Refresh the Explorer when the mounted filesystem changes. Return an unsubscribe function. |
|
|
121
136
|
|
|
122
137
|
Directory entries are traversed recursively when loading the Explorer. Adapter
|
|
@@ -133,8 +148,13 @@ the failure in the workbench instead of treating it as success.
|
|
|
133
148
|
| `initialFiles` | `Record<string, string>` | Demo files | Initial paths and contents for the built-in in-memory filesystem. Ignored when `fileSystem` is provided. |
|
|
134
149
|
| `initialActiveFile` | `string` | First file in the tree | File path selected after loading. |
|
|
135
150
|
| `theme` | `string` | `"vs-dark"` | Monaco theme name, such as `"vs-dark"` or `"light"`. |
|
|
151
|
+
| `workspaceName` | `string` | `"Workspace"` | Name shown in the title bar and Explorer. |
|
|
136
152
|
| `options` | `editor.IStandaloneEditorConstructionOptions` | KaiCode defaults | Additional Monaco editor options. |
|
|
137
|
-
| `height` | `
|
|
153
|
+
| `height` | `CSSProperties["height"]` | `min(80dvh, 760px)` | Workbench height. Accepts a CSS length, percentage, or expression. |
|
|
154
|
+
| `colors` | `KaiCodeColors` | Theme palette | Optional workbench color overrides. |
|
|
155
|
+
| `rounded` | `boolean` | `true` | Set `false` for flat, square outer corners. |
|
|
156
|
+
| `icons` | `Partial<Record<KaiCodeIconName, ReactNode>>` | Built-in glyphs | Override action, folder, and Explorer icons with React elements, SVGs, or emoji. |
|
|
157
|
+
| `fileIcons` | `Record<string, ReactNode>` | Built-in file glyphs | Override file icons by lowercase extension (for example `tsx`) or `default`. |
|
|
138
158
|
| `readOnly` | `boolean` | `false` | Prevent editing and saving. |
|
|
139
159
|
| `className` | `string` | — | Class added to the outer workbench element. |
|
|
140
160
|
| `onFileChange` | `(path, contents) => void` | — | Called when the active document changes in the editor. |
|
|
@@ -144,13 +164,71 @@ Documents are saved on **Save** or `Ctrl+S` / `Cmd+S`; editing does not write
|
|
|
144
164
|
through to the adapter until a save succeeds. The in-memory filesystem can also
|
|
145
165
|
be created directly with `createMemoryFileSystem(initialFiles)`.
|
|
146
166
|
|
|
167
|
+
### Responsive size and appearance
|
|
168
|
+
|
|
169
|
+
KaiCode's default height tracks the viewport (`min(80dvh, 760px)`). Set
|
|
170
|
+
`height="100%"` to fill a parent with an explicit height, or pass any valid CSS
|
|
171
|
+
height value such as `"70vh"` or `"clamp(360px, 75dvh, 900px)"`. The workbench
|
|
172
|
+
uses a responsive Explorer layout when embedded in narrower containers.
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
import { KaiCode } from "@handylib/kai-code";
|
|
176
|
+
|
|
177
|
+
export function BrandedEditor() {
|
|
178
|
+
return (
|
|
179
|
+
<div style={{ height: "min(90dvh, 1000px)" }}>
|
|
180
|
+
<KaiCode
|
|
181
|
+
height="100%"
|
|
182
|
+
workspaceName="Acme Dashboard"
|
|
183
|
+
rounded={false}
|
|
184
|
+
colors={{
|
|
185
|
+
background: "#111827",
|
|
186
|
+
sidebarBackground: "#0b1220",
|
|
187
|
+
titlebarBackground: "#0b1220",
|
|
188
|
+
panelBackground: "#1f2937",
|
|
189
|
+
foreground: "#e5e7eb",
|
|
190
|
+
mutedForeground: "#9ca3af",
|
|
191
|
+
border: "#374151",
|
|
192
|
+
accent: "#8b5cf6",
|
|
193
|
+
statusBarBackground: "#6d28d9",
|
|
194
|
+
statusBarForeground: "#ffffff",
|
|
195
|
+
fileSelectionBackground: "#312e81",
|
|
196
|
+
}}
|
|
197
|
+
icons={{
|
|
198
|
+
brand: "🚀",
|
|
199
|
+
folder: "📁",
|
|
200
|
+
newFile: "+",
|
|
201
|
+
newFolder: "📂",
|
|
202
|
+
collapseAll: "⊟",
|
|
203
|
+
delete: "🗑️",
|
|
204
|
+
}}
|
|
205
|
+
fileIcons={{
|
|
206
|
+
tsx: "⚛️",
|
|
207
|
+
ts: "🔷",
|
|
208
|
+
default: "📄",
|
|
209
|
+
}}
|
|
210
|
+
/>
|
|
211
|
+
</div>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Icon values are `ReactNode`s, so icon components from packages such as
|
|
217
|
+
`lucide-react`, inline SVG elements, and emoji are supported. For example, pass
|
|
218
|
+
`folder: <Folder size={16} />` after importing the icon from your chosen icon
|
|
219
|
+
library. `colors` customizes the KaiCode workbench; `theme` still controls
|
|
220
|
+
Monaco's editor theme independently.
|
|
221
|
+
|
|
147
222
|
## Explorer controls
|
|
148
223
|
|
|
149
224
|
- Right-click a file or folder to open its context menu. Available create and
|
|
150
|
-
delete actions depend on the optional filesystem methods you provide.
|
|
225
|
+
delete and move actions depend on the optional filesystem methods you provide.
|
|
151
226
|
- Use **New File** and **New Folder** in the Explorer header to create at the
|
|
152
227
|
workspace root. Context-menu create actions use the selected folder (or the
|
|
153
228
|
selected file's parent).
|
|
229
|
+
- **Move** opens a destination-path field. Enter a relative path from the
|
|
230
|
+
workspace root. A file can use `moveFile` (or legacy `renameFile`); folders
|
|
231
|
+
require `moveDirectory`.
|
|
154
232
|
- Deleting a folder asks for confirmation and removes all descendant documents
|
|
155
233
|
from the open tabs. Unsaved changes in deleted files are discarded.
|
|
156
234
|
- Drag the divider beside the Explorer to resize it. You can also focus the
|
|
@@ -168,9 +246,9 @@ import "@handylib/kai-code/style.css";
|
|
|
168
246
|
```
|
|
169
247
|
|
|
170
248
|
The default workbench uses a dark VS Code-inspired palette. Set `theme="light"`
|
|
171
|
-
for the matching light workbench, or pass any Monaco theme name.
|
|
172
|
-
scoped under `.kai-code`;
|
|
173
|
-
application-specific styling.
|
|
249
|
+
for the matching light workbench, or pass any Monaco theme name. Use `colors`
|
|
250
|
+
for workbench color overrides. The layout is scoped under `.kai-code`;
|
|
251
|
+
`className` can be used to set a width or add application-specific styling.
|
|
174
252
|
|
|
175
253
|
## Development
|
|
176
254
|
|