@handylib/kai-code 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 HandyLib
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,213 @@
1
- # Temporary Holding Version
1
+ # @handylib/kai-code
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ KaiCode is an embeddable, VS Code-inspired code editor for React applications.
4
+ It combines Monaco Editor with a familiar workbench layout: an Explorer, nested
5
+ file tree, editor tabs, breadcrumbs, save controls, and a status bar. Bring your
6
+ own filesystem adapter to mount local, remote, virtual, or in-memory project
7
+ files. KaiCode is released under the MIT License; see [LICENSE](./LICENSE).
8
+
9
+ KaiCode is an editor component, not a full VS Code distribution. It does not
10
+ include VS Code extensions, a language server, a terminal, or VS Code's
11
+ proprietary services.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @handylib/kai-code react react-dom @monaco-editor/react monaco-editor
17
+ ```
18
+
19
+ React, React DOM, `@monaco-editor/react`, and `monaco-editor` are peer
20
+ dependencies and should be installed by the application.
21
+
22
+ ## Quick start
23
+
24
+ ```tsx
25
+ import "@handylib/kai-code/style.css";
26
+ import { KaiCode } from "@handylib/kai-code";
27
+
28
+ export function Playground() {
29
+ return (
30
+ <div style={{ height: 720 }}>
31
+ <KaiCode
32
+ initialFiles={{
33
+ "src/main.ts": 'console.log("Hello, KaiCode!");',
34
+ "README.md": "# My project",
35
+ }}
36
+ onSave={(path, contents) => {
37
+ console.log(`Saved ${path}`, contents);
38
+ }}
39
+ />
40
+ </div>
41
+ );
42
+ }
43
+ ```
44
+
45
+ KaiCode fills its parent by default at `640px` high; set the `height` prop or
46
+ give the component a sized parent. Monaco's worker configuration may need to be
47
+ set up by your bundler, as with any application using Monaco Editor. See the
48
+ [`@monaco-editor/react` documentation](https://github.com/suren-atoyan/monaco-react)
49
+ for bundler-specific worker setup.
50
+
51
+ ## Mount a custom filesystem
52
+
53
+ Implement `KaiCodeFileSystem` and pass the instance through `fileSystem`. Paths
54
+ in entries and file operations should use one consistent convention (relative,
55
+ slash-separated paths are recommended). Directories must have
56
+ `type: "directory"` entries and files must have `type: "file"` entries.
57
+
58
+ ```tsx
59
+ import {
60
+ KaiCode,
61
+ type KaiCodeEntry,
62
+ type KaiCodeFileSystem,
63
+ } from "@handylib/kai-code";
64
+
65
+ const fileSystem: KaiCodeFileSystem = {
66
+ async readDirectory(path = ""): Promise<readonly KaiCodeEntry[]> {
67
+ // Replace this with your storage layer. Return only direct children.
68
+ if (path === "") {
69
+ return [
70
+ { type: "directory", name: "src", path: "src" },
71
+ { type: "file", name: "README.md", path: "README.md" },
72
+ ];
73
+ }
74
+ if (path === "src") {
75
+ return [{ type: "file", name: "main.ts", path: "src/main.ts" }];
76
+ }
77
+ return [];
78
+ },
79
+ async readFile(path) {
80
+ return myStorage.readText(path);
81
+ },
82
+ async writeFile(path, contents) {
83
+ await myStorage.writeText(path, contents);
84
+ },
85
+ async createFile(path, contents = "") {
86
+ await myStorage.writeText(path, contents);
87
+ },
88
+ watch(listener) {
89
+ // Optional: call listener when files or directories change outside KaiCode.
90
+ return myStorage.subscribe(listener);
91
+ },
92
+ };
93
+
94
+ export function ProjectEditor() {
95
+ return <KaiCode fileSystem={fileSystem} initialActiveFile="src/main.ts" />;
96
+ }
97
+ ```
98
+
99
+ `initialFiles` is read once when KaiCode mounts, to initialize its in-memory
100
+ filesystem. Remount KaiCode to replace that starter content, or use a custom
101
+ `fileSystem` when the host needs to control file lifecycle.
102
+
103
+ The required adapter methods are:
104
+
105
+ | Method | Purpose |
106
+ | --- | --- |
107
+ | `readDirectory(path?)` | Return the direct file and directory children at `path`. Use `""` for the root. |
108
+ | `readFile(path)` | Resolve a file's text contents. |
109
+ | `writeFile(path, contents)` | Persist a document when the user saves. |
110
+
111
+ Optional methods:
112
+
113
+ | Method | Purpose |
114
+ | --- | --- |
115
+ | `createFile(path, contents?)` | Enables the Explorer's **New File** action. |
116
+ | `createDirectory(path)` | Enables **New Folder** and creates the directory, including empty directories. |
117
+ | `deleteFile(path)` | Enables deleting files from the Explorer context menu. |
118
+ | `deleteDirectory(path)` | Enables deleting folders. The adapter must delete the folder and all of its descendants. |
119
+ | `renameFile(oldPath, newPath)` | Reserved for file operations added by the host application. |
120
+ | `watch(listener)` | Refresh the Explorer when the mounted filesystem changes. Return an unsubscribe function. |
121
+
122
+ Directory entries are traversed recursively when loading the Explorer. Adapter
123
+ methods should reject with an `Error` when an operation fails; KaiCode displays
124
+ the failure in the workbench instead of treating it as success.
125
+
126
+ ## API
127
+
128
+ ### `KaiCode` props
129
+
130
+ | Prop | Type | Default | Description |
131
+ | --- | --- | --- | --- |
132
+ | `fileSystem` | `KaiCodeFileSystem` | In-memory filesystem | Filesystem adapter to mount. |
133
+ | `initialFiles` | `Record<string, string>` | Demo files | Initial paths and contents for the built-in in-memory filesystem. Ignored when `fileSystem` is provided. |
134
+ | `initialActiveFile` | `string` | First file in the tree | File path selected after loading. |
135
+ | `theme` | `string` | `"vs-dark"` | Monaco theme name, such as `"vs-dark"` or `"light"`. |
136
+ | `options` | `editor.IStandaloneEditorConstructionOptions` | KaiCode defaults | Additional Monaco editor options. |
137
+ | `height` | `string \| number` | `640` | Height of the workbench. |
138
+ | `readOnly` | `boolean` | `false` | Prevent editing and saving. |
139
+ | `className` | `string` | — | Class added to the outer workbench element. |
140
+ | `onFileChange` | `(path, contents) => void` | — | Called when the active document changes in the editor. |
141
+ | `onSave` | `(path, contents) => void` | — | Called after `writeFile` succeeds. |
142
+
143
+ Documents are saved on **Save** or `Ctrl+S` / `Cmd+S`; editing does not write
144
+ through to the adapter until a save succeeds. The in-memory filesystem can also
145
+ be created directly with `createMemoryFileSystem(initialFiles)`.
146
+
147
+ ## Explorer controls
148
+
149
+ - 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.
151
+ - Use **New File** and **New Folder** in the Explorer header to create at the
152
+ workspace root. Context-menu create actions use the selected folder (or the
153
+ selected file's parent).
154
+ - Deleting a folder asks for confirmation and removes all descendant documents
155
+ from the open tabs. Unsaved changes in deleted files are discarded.
156
+ - Drag the divider beside the Explorer to resize it. You can also focus the
157
+ divider and use the arrow keys.
158
+ - Press `Ctrl+B` / `Cmd+B` to toggle the Explorer.
159
+ - Press `Ctrl+K`, then `Ctrl+0` (or `Cmd+K`, then `Cmd+0` on macOS) to collapse
160
+ all folders.
161
+
162
+ ## Styling and theming
163
+
164
+ Import the stylesheet once in your application entry point:
165
+
166
+ ```ts
167
+ import "@handylib/kai-code/style.css";
168
+ ```
169
+
170
+ 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. The layout is
172
+ scoped under `.kai-code`; `className` can be used to set a width or add
173
+ application-specific styling.
174
+
175
+ ## Development
176
+
177
+ ```bash
178
+ bun install
179
+ bun run typecheck
180
+ bun run test
181
+ bun run build
182
+ ```
183
+
184
+ `bun run build` creates ESM, CommonJS, TypeScript declaration, and CSS outputs
185
+ under `dist/`. The package's `prepublishOnly` script builds these artifacts
186
+ before publishing. The root `LICENSE` file is included in the published
187
+ package.
188
+
189
+ ## Playground
190
+
191
+ Run the local interactive playground to try the editor, theme switcher, save
192
+ shortcut, and in-memory filesystem:
193
+
194
+ ```bash
195
+ bun run playground
196
+ ```
197
+
198
+ Then open the URL printed by Vite (by default
199
+ [`http://localhost:5173`](http://localhost:5173)). The playground imports the
200
+ component from `src/` and configures Monaco's language workers locally, so it
201
+ does not need a separate package build or a CDN connection.
202
+
203
+ ## Publish to npm
204
+
205
+ The package is scoped as `@handylib/kai-code`, licensed under MIT, and
206
+ `publishConfig.access` is set to `public`. Sign in to an npm account with
207
+ permission to publish under the `@handylib` scope, then run:
208
+
209
+ ```bash
210
+ npm publish
211
+ ```
212
+
213
+ The `prepublishOnly` script builds the distribution before publishing.