@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/dist/index.cjs
CHANGED
|
@@ -67,6 +67,63 @@ function createMemoryFileSystem(initialFiles = {}) {
|
|
|
67
67
|
const notify = () => {
|
|
68
68
|
listeners.forEach((listener) => listener());
|
|
69
69
|
};
|
|
70
|
+
const moveFile = async (oldPath, newPath) => {
|
|
71
|
+
const oldNormalized = normalizePath(oldPath);
|
|
72
|
+
const newNormalized = normalizePath(newPath);
|
|
73
|
+
const contents = files.get(oldNormalized);
|
|
74
|
+
if (contents === void 0) {
|
|
75
|
+
throw new Error(`File not found: ${oldNormalized}`);
|
|
76
|
+
}
|
|
77
|
+
if (!newNormalized) throw new Error("Destination file path must not be empty.");
|
|
78
|
+
if (oldNormalized === newNormalized) return;
|
|
79
|
+
if (files.has(newNormalized) || directories.has(newNormalized)) {
|
|
80
|
+
throw new Error(`Path already exists: ${newNormalized}`);
|
|
81
|
+
}
|
|
82
|
+
addParentDirectories(newNormalized);
|
|
83
|
+
files.delete(oldNormalized);
|
|
84
|
+
files.set(newNormalized, contents);
|
|
85
|
+
notify();
|
|
86
|
+
};
|
|
87
|
+
const moveDirectory = async (oldPath, newPath) => {
|
|
88
|
+
const oldNormalized = normalizePath(oldPath);
|
|
89
|
+
const newNormalized = normalizePath(newPath);
|
|
90
|
+
if (!directories.has(oldNormalized)) {
|
|
91
|
+
throw new Error(`Directory not found: ${oldNormalized}`);
|
|
92
|
+
}
|
|
93
|
+
if (!newNormalized) {
|
|
94
|
+
throw new Error("Destination directory path must not be empty.");
|
|
95
|
+
}
|
|
96
|
+
if (oldNormalized === newNormalized) return;
|
|
97
|
+
if (newNormalized.startsWith(`${oldNormalized}/`)) {
|
|
98
|
+
throw new Error("A directory cannot be moved inside itself.");
|
|
99
|
+
}
|
|
100
|
+
if (files.has(newNormalized) || directories.has(newNormalized)) {
|
|
101
|
+
throw new Error(`Path already exists: ${newNormalized}`);
|
|
102
|
+
}
|
|
103
|
+
addParentDirectories(newNormalized);
|
|
104
|
+
const oldPrefix = `${oldNormalized}/`;
|
|
105
|
+
const directoriesToMove = [...directories].filter(
|
|
106
|
+
(path) => path === oldNormalized || path.startsWith(oldPrefix)
|
|
107
|
+
);
|
|
108
|
+
const filesToMove = [...files.entries()].filter(
|
|
109
|
+
([path]) => path.startsWith(oldPrefix)
|
|
110
|
+
);
|
|
111
|
+
for (const [path] of filesToMove) {
|
|
112
|
+
const destination = `${newNormalized}${path.slice(oldNormalized.length)}`;
|
|
113
|
+
if (files.has(destination) || directories.has(destination)) {
|
|
114
|
+
throw new Error(`Path already exists: ${destination}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
directoriesToMove.forEach((path) => directories.delete(path));
|
|
118
|
+
filesToMove.forEach(([path]) => files.delete(path));
|
|
119
|
+
directoriesToMove.forEach(
|
|
120
|
+
(path) => directories.add(`${newNormalized}${path.slice(oldNormalized.length)}`)
|
|
121
|
+
);
|
|
122
|
+
filesToMove.forEach(
|
|
123
|
+
([path, contents]) => files.set(`${newNormalized}${path.slice(oldNormalized.length)}`, contents)
|
|
124
|
+
);
|
|
125
|
+
notify();
|
|
126
|
+
};
|
|
70
127
|
return {
|
|
71
128
|
async readDirectory(directory = "") {
|
|
72
129
|
const base = normalizePath(directory);
|
|
@@ -178,24 +235,9 @@ function createMemoryFileSystem(initialFiles = {}) {
|
|
|
178
235
|
}
|
|
179
236
|
notify();
|
|
180
237
|
},
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const contents = files.get(oldNormalized);
|
|
185
|
-
if (contents === void 0) {
|
|
186
|
-
throw new Error(`File not found: ${oldNormalized}`);
|
|
187
|
-
}
|
|
188
|
-
if (files.has(newNormalized)) {
|
|
189
|
-
throw new Error(`File already exists: ${newNormalized}`);
|
|
190
|
-
}
|
|
191
|
-
if (!newNormalized || directories.has(newNormalized)) {
|
|
192
|
-
throw new Error(`Invalid file path: ${newNormalized}`);
|
|
193
|
-
}
|
|
194
|
-
files.delete(oldNormalized);
|
|
195
|
-
addParentDirectories(newNormalized);
|
|
196
|
-
files.set(newNormalized, contents);
|
|
197
|
-
notify();
|
|
198
|
-
},
|
|
238
|
+
moveFile,
|
|
239
|
+
moveDirectory,
|
|
240
|
+
renameFile: moveFile,
|
|
199
241
|
watch(listener) {
|
|
200
242
|
listeners.add(listener);
|
|
201
243
|
return () => listeners.delete(listener);
|
|
@@ -252,6 +294,13 @@ function getFileGlyph(path) {
|
|
|
252
294
|
if (extension === "css" || extension === "scss") return "#";
|
|
253
295
|
return "\xB7";
|
|
254
296
|
}
|
|
297
|
+
function getFileIcon(path, fileIcons, icons) {
|
|
298
|
+
const extension = path.split(".").pop()?.toLowerCase() ?? "";
|
|
299
|
+
return fileIcons?.[extension] ?? fileIcons?.default ?? icons?.file ?? getFileGlyph(path);
|
|
300
|
+
}
|
|
301
|
+
function getIcon(icons, name, fallback) {
|
|
302
|
+
return icons?.[name] ?? fallback;
|
|
303
|
+
}
|
|
255
304
|
function errorMessage(error) {
|
|
256
305
|
return error instanceof Error ? error.message : String(error);
|
|
257
306
|
}
|
|
@@ -313,6 +362,8 @@ function FileTree({
|
|
|
313
362
|
collapsedFolders,
|
|
314
363
|
onToggleDirectory,
|
|
315
364
|
onContextMenu,
|
|
365
|
+
icons,
|
|
366
|
+
fileIcons,
|
|
316
367
|
depth = 0
|
|
317
368
|
}) {
|
|
318
369
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: nodes.map(
|
|
@@ -330,7 +381,7 @@ function FileTree({
|
|
|
330
381
|
style: { "--tree-depth": depth },
|
|
331
382
|
children: [
|
|
332
383
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__chevron", "aria-hidden": "true", children: "\u25B8" }),
|
|
333
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__folder-icon", "aria-hidden": "true", children: "\u25B0" }),
|
|
384
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__folder-icon", "aria-hidden": "true", children: getIcon(icons, "folder", "\u25B0") }),
|
|
334
385
|
node.name
|
|
335
386
|
]
|
|
336
387
|
}
|
|
@@ -344,6 +395,8 @@ function FileTree({
|
|
|
344
395
|
collapsedFolders,
|
|
345
396
|
onToggleDirectory,
|
|
346
397
|
onContextMenu,
|
|
398
|
+
icons,
|
|
399
|
+
fileIcons,
|
|
347
400
|
depth: depth + 1
|
|
348
401
|
}
|
|
349
402
|
)
|
|
@@ -359,7 +412,7 @@ function FileTree({
|
|
|
359
412
|
style: { "--tree-depth": depth },
|
|
360
413
|
type: "button",
|
|
361
414
|
children: [
|
|
362
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__file-icon", "aria-hidden": "true", children:
|
|
415
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__file-icon", "aria-hidden": "true", children: getFileIcon(node.path, fileIcons, icons) }),
|
|
363
416
|
node.name
|
|
364
417
|
]
|
|
365
418
|
},
|
|
@@ -372,8 +425,13 @@ function KaiCode({
|
|
|
372
425
|
initialFiles,
|
|
373
426
|
initialActiveFile,
|
|
374
427
|
theme = "vs-dark",
|
|
428
|
+
workspaceName = "Workspace",
|
|
375
429
|
options,
|
|
376
|
-
height =
|
|
430
|
+
height = "min(80dvh, 760px)",
|
|
431
|
+
colors,
|
|
432
|
+
rounded = true,
|
|
433
|
+
icons,
|
|
434
|
+
fileIcons,
|
|
377
435
|
readOnly = false,
|
|
378
436
|
className,
|
|
379
437
|
onFileChange,
|
|
@@ -397,6 +455,8 @@ function KaiCode({
|
|
|
397
455
|
const [creationRequest, setCreationRequest] = (0, import_react2.useState)(null);
|
|
398
456
|
const [creationName, setCreationName] = (0, import_react2.useState)("");
|
|
399
457
|
const [deleteTarget, setDeleteTarget] = (0, import_react2.useState)(null);
|
|
458
|
+
const [moveTarget, setMoveTarget] = (0, import_react2.useState)(null);
|
|
459
|
+
const [moveDestination, setMoveDestination] = (0, import_react2.useState)("");
|
|
400
460
|
const [loadingTree, setLoadingTree] = (0, import_react2.useState)(true);
|
|
401
461
|
const [loadingDocument, setLoadingDocument] = (0, import_react2.useState)(false);
|
|
402
462
|
const [failedDocument, setFailedDocument] = (0, import_react2.useState)(null);
|
|
@@ -405,9 +465,12 @@ function KaiCode({
|
|
|
405
465
|
const saveRef = (0, import_react2.useRef)(async () => void 0);
|
|
406
466
|
const activeFileRef = (0, import_react2.useRef)(null);
|
|
407
467
|
const resizeStartRef = (0, import_react2.useRef)(null);
|
|
468
|
+
const suppressWatchRef = (0, import_react2.useRef)(false);
|
|
408
469
|
const createInputId = (0, import_react2.useId)();
|
|
409
470
|
const createTitleId = (0, import_react2.useId)();
|
|
410
471
|
const deleteTitleId = (0, import_react2.useId)();
|
|
472
|
+
const moveInputId = (0, import_react2.useId)();
|
|
473
|
+
const moveTitleId = (0, import_react2.useId)();
|
|
411
474
|
const isLight = theme === "light";
|
|
412
475
|
const reloadFiles = (0, import_react2.useCallback)(async () => {
|
|
413
476
|
setLoadingTree(true);
|
|
@@ -434,6 +497,7 @@ function KaiCode({
|
|
|
434
497
|
(0, import_react2.useEffect)(() => {
|
|
435
498
|
void reloadFiles();
|
|
436
499
|
return fs.watch?.(() => {
|
|
500
|
+
if (suppressWatchRef.current) return;
|
|
437
501
|
void reloadFiles();
|
|
438
502
|
});
|
|
439
503
|
}, [fs, reloadFiles]);
|
|
@@ -471,6 +535,7 @@ function KaiCode({
|
|
|
471
535
|
setContextMenu(null);
|
|
472
536
|
setCreationRequest(null);
|
|
473
537
|
setDeleteTarget(null);
|
|
538
|
+
setMoveTarget(null);
|
|
474
539
|
}
|
|
475
540
|
const modifierPressed = event.ctrlKey || event.metaKey;
|
|
476
541
|
if (awaitingCollapseChord) {
|
|
@@ -570,7 +635,8 @@ function KaiCode({
|
|
|
570
635
|
event.preventDefault();
|
|
571
636
|
event.stopPropagation();
|
|
572
637
|
const canDelete = entry.type === "file" ? fs.deleteFile : fs.deleteDirectory;
|
|
573
|
-
|
|
638
|
+
const canMove = entry.type === "file" ? fs.moveFile || fs.renameFile : fs.moveDirectory;
|
|
639
|
+
if (readOnly || !fs.createFile && !fs.createDirectory && !canDelete && !canMove) {
|
|
574
640
|
return;
|
|
575
641
|
}
|
|
576
642
|
setContextMenu({
|
|
@@ -671,6 +737,69 @@ function KaiCode({
|
|
|
671
737
|
setError(`Unable to delete ${target.path}: ${errorMessage(deleteError)}`);
|
|
672
738
|
}
|
|
673
739
|
}, [deleteTarget, documents, fs, reloadFiles, tree]);
|
|
740
|
+
const moveEntry = (0, import_react2.useCallback)(
|
|
741
|
+
async (event) => {
|
|
742
|
+
event.preventDefault();
|
|
743
|
+
if (!moveTarget) return;
|
|
744
|
+
const rawDestination = moveDestination.trim().replace(/\\/g, "/");
|
|
745
|
+
const destination = normalizePath(rawDestination);
|
|
746
|
+
if (!destination || rawDestination.startsWith("/") || destination.split("/").some((part) => !part || part === "." || part === "..")) {
|
|
747
|
+
setError("Enter a valid relative destination path.");
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
const oldPath = moveTarget.path;
|
|
751
|
+
const newPath = destination;
|
|
752
|
+
const updatePath = (path) => moveTarget.type === "file" ? path === oldPath ? newPath : path : path === oldPath || path.startsWith(`${oldPath}/`) ? `${newPath}${path.slice(oldPath.length)}` : path;
|
|
753
|
+
try {
|
|
754
|
+
suppressWatchRef.current = true;
|
|
755
|
+
try {
|
|
756
|
+
if (moveTarget.type === "file") {
|
|
757
|
+
if (fs.moveFile) {
|
|
758
|
+
await fs.moveFile(oldPath, newPath);
|
|
759
|
+
} else if (fs.renameFile) {
|
|
760
|
+
await fs.renameFile(oldPath, newPath);
|
|
761
|
+
} else {
|
|
762
|
+
throw new Error("File moving is not supported.");
|
|
763
|
+
}
|
|
764
|
+
} else {
|
|
765
|
+
if (!fs.moveDirectory) {
|
|
766
|
+
throw new Error("Folder moving is not supported.");
|
|
767
|
+
}
|
|
768
|
+
await fs.moveDirectory(oldPath, newPath);
|
|
769
|
+
}
|
|
770
|
+
} finally {
|
|
771
|
+
suppressWatchRef.current = false;
|
|
772
|
+
}
|
|
773
|
+
setDocuments((current) => {
|
|
774
|
+
const next = { ...current };
|
|
775
|
+
Object.keys(current).forEach((path) => {
|
|
776
|
+
const updatedPath = updatePath(path);
|
|
777
|
+
if (updatedPath !== path) {
|
|
778
|
+
const contents = current[path];
|
|
779
|
+
if (contents !== void 0) {
|
|
780
|
+
next[updatedPath] = contents;
|
|
781
|
+
delete next[path];
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
return next;
|
|
786
|
+
});
|
|
787
|
+
setDirtyFiles((current) => new Set([...current].map(updatePath)));
|
|
788
|
+
setOpenFiles((current) => current.map(updatePath));
|
|
789
|
+
if (activeFileRef.current) {
|
|
790
|
+
const updatedActiveFile = updatePath(activeFileRef.current);
|
|
791
|
+
activeFileRef.current = updatedActiveFile;
|
|
792
|
+
setActiveFile(updatedActiveFile);
|
|
793
|
+
}
|
|
794
|
+
setMoveTarget(null);
|
|
795
|
+
setError(null);
|
|
796
|
+
await reloadFiles();
|
|
797
|
+
} catch (moveError) {
|
|
798
|
+
setError(`Unable to move ${oldPath}: ${errorMessage(moveError)}`);
|
|
799
|
+
}
|
|
800
|
+
},
|
|
801
|
+
[fs, moveDestination, moveTarget, reloadFiles]
|
|
802
|
+
);
|
|
674
803
|
const editorOptions = (0, import_react2.useMemo)(
|
|
675
804
|
() => ({
|
|
676
805
|
automaticLayout: true,
|
|
@@ -687,18 +816,33 @@ function KaiCode({
|
|
|
687
816
|
[options, readOnly]
|
|
688
817
|
);
|
|
689
818
|
const activeLanguage = activeFile ? findFileEntry(tree, activeFile)?.language ?? getLanguage(activeFile) : null;
|
|
819
|
+
const rootStyle = {
|
|
820
|
+
height,
|
|
821
|
+
borderRadius: rounded ? 6 : 0,
|
|
822
|
+
"--kc-background": colors?.background,
|
|
823
|
+
"--kc-sidebar": colors?.sidebarBackground,
|
|
824
|
+
"--kc-titlebar": colors?.titlebarBackground,
|
|
825
|
+
"--kc-panel": colors?.panelBackground,
|
|
826
|
+
"--kc-text": colors?.foreground,
|
|
827
|
+
"--kc-muted": colors?.mutedForeground,
|
|
828
|
+
"--kc-border": colors?.border,
|
|
829
|
+
"--kc-accent": colors?.accent,
|
|
830
|
+
"--kc-status-background": colors?.statusBarBackground,
|
|
831
|
+
"--kc-status-foreground": colors?.statusBarForeground,
|
|
832
|
+
"--kc-selection": colors?.fileSelectionBackground
|
|
833
|
+
};
|
|
690
834
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
691
835
|
"section",
|
|
692
836
|
{
|
|
693
837
|
className: `kai-code${isLight ? " kai-code--light" : ""}${className ? ` ${className}` : ""}`,
|
|
694
|
-
style:
|
|
838
|
+
style: rootStyle,
|
|
695
839
|
"aria-label": "KaiCode editor",
|
|
696
840
|
children: [
|
|
697
841
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("header", { className: "kai-code__titlebar", children: [
|
|
698
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "kai-code__brand-mark", "aria-hidden": "true", children: "K" }),
|
|
842
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "kai-code__brand-mark", "aria-hidden": "true", children: getIcon(icons, "brand", "K") }),
|
|
699
843
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__brand", children: "KaiCode" }),
|
|
700
844
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__title-divider" }),
|
|
701
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__workspace-title", children:
|
|
845
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__workspace-title", children: workspaceName }),
|
|
702
846
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "kai-code__title-actions", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
703
847
|
"button",
|
|
704
848
|
{
|
|
@@ -726,10 +870,18 @@ function KaiCode({
|
|
|
726
870
|
title: "Explorer (Ctrl+B)",
|
|
727
871
|
onClick: () => setExplorerVisible((visible) => !visible),
|
|
728
872
|
type: "button",
|
|
729
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
873
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__activity-icon", "aria-hidden": "true", children: icons?.explorer ?? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
874
|
+
"svg",
|
|
875
|
+
{
|
|
876
|
+
className: "kai-code__default-explorer-icon",
|
|
877
|
+
viewBox: "0 0 24 24",
|
|
878
|
+
"aria-hidden": "true",
|
|
879
|
+
children: [
|
|
880
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3.5 5.5h6l2 2h9v11h-17z" }),
|
|
881
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3.5 8h17" })
|
|
882
|
+
]
|
|
883
|
+
}
|
|
884
|
+
) })
|
|
733
885
|
}
|
|
734
886
|
),
|
|
735
887
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "kai-code__activity-spacer" }),
|
|
@@ -753,7 +905,7 @@ function KaiCode({
|
|
|
753
905
|
title: "New File",
|
|
754
906
|
onClick: () => beginCreate("file", ""),
|
|
755
907
|
type: "button",
|
|
756
|
-
children: "+"
|
|
908
|
+
children: getIcon(icons, "newFile", "+")
|
|
757
909
|
}
|
|
758
910
|
),
|
|
759
911
|
fs.createDirectory && !readOnly && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -764,7 +916,7 @@ function KaiCode({
|
|
|
764
916
|
title: "New Folder",
|
|
765
917
|
onClick: () => beginCreate("directory", ""),
|
|
766
918
|
type: "button",
|
|
767
|
-
children: "\u25B0+"
|
|
919
|
+
children: getIcon(icons, "newFolder", "\u25B0+")
|
|
768
920
|
}
|
|
769
921
|
),
|
|
770
922
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -775,14 +927,14 @@ function KaiCode({
|
|
|
775
927
|
title: "Collapse All (Ctrl+K Ctrl+0)",
|
|
776
928
|
onClick: collapseAll,
|
|
777
929
|
type: "button",
|
|
778
|
-
children: "\u229F"
|
|
930
|
+
children: getIcon(icons, "collapseAll", "\u229F")
|
|
779
931
|
}
|
|
780
932
|
)
|
|
781
933
|
] })
|
|
782
934
|
] }),
|
|
783
935
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "kai-code__workspace-row", children: [
|
|
784
936
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__chevron", "aria-hidden": "true", children: "\u25BE" }),
|
|
785
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children:
|
|
937
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: workspaceName })
|
|
786
938
|
] }),
|
|
787
939
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "kai-code__file-tree", children: loadingTree && tree.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "kai-code__empty", children: "Loading files\u2026" }) : tree.length ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
788
940
|
FileTree,
|
|
@@ -792,7 +944,9 @@ function KaiCode({
|
|
|
792
944
|
onOpen: openFile,
|
|
793
945
|
collapsedFolders,
|
|
794
946
|
onToggleDirectory: toggleDirectory,
|
|
795
|
-
onContextMenu: openContextMenu
|
|
947
|
+
onContextMenu: openContextMenu,
|
|
948
|
+
icons,
|
|
949
|
+
fileIcons
|
|
796
950
|
}
|
|
797
951
|
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "kai-code__empty", children: "No files in this workspace" }) })
|
|
798
952
|
]
|
|
@@ -854,7 +1008,7 @@ function KaiCode({
|
|
|
854
1008
|
onClick: (event) => event.stopPropagation(),
|
|
855
1009
|
onContextMenu: (event) => event.preventDefault(),
|
|
856
1010
|
children: [
|
|
857
|
-
fs.createFile && !readOnly && /* @__PURE__ */ (0, import_jsx_runtime.
|
|
1011
|
+
fs.createFile && !readOnly && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
858
1012
|
"button",
|
|
859
1013
|
{
|
|
860
1014
|
role: "menuitem",
|
|
@@ -863,10 +1017,13 @@ function KaiCode({
|
|
|
863
1017
|
contextMenu.entry.type === "directory" ? contextMenu.entry.path : parentDirectory(contextMenu.entry.path)
|
|
864
1018
|
),
|
|
865
1019
|
type: "button",
|
|
866
|
-
children:
|
|
1020
|
+
children: [
|
|
1021
|
+
getIcon(icons, "newFile", "\uFF0B"),
|
|
1022
|
+
" New File"
|
|
1023
|
+
]
|
|
867
1024
|
}
|
|
868
1025
|
),
|
|
869
|
-
fs.createDirectory && !readOnly && /* @__PURE__ */ (0, import_jsx_runtime.
|
|
1026
|
+
fs.createDirectory && !readOnly && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
870
1027
|
"button",
|
|
871
1028
|
{
|
|
872
1029
|
role: "menuitem",
|
|
@@ -875,12 +1032,32 @@ function KaiCode({
|
|
|
875
1032
|
contextMenu.entry.type === "directory" ? contextMenu.entry.path : parentDirectory(contextMenu.entry.path)
|
|
876
1033
|
),
|
|
877
1034
|
type: "button",
|
|
878
|
-
children:
|
|
1035
|
+
children: [
|
|
1036
|
+
getIcon(icons, "newFolder", "\u25B0"),
|
|
1037
|
+
" New Folder"
|
|
1038
|
+
]
|
|
1039
|
+
}
|
|
1040
|
+
),
|
|
1041
|
+
(contextMenu.entry.type === "file" && (fs.moveFile || fs.renameFile) || contextMenu.entry.type === "directory" && fs.moveDirectory) && !readOnly && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1042
|
+
"button",
|
|
1043
|
+
{
|
|
1044
|
+
role: "menuitem",
|
|
1045
|
+
onClick: () => {
|
|
1046
|
+
setMoveTarget(contextMenu.entry);
|
|
1047
|
+
setMoveDestination("");
|
|
1048
|
+
setError(null);
|
|
1049
|
+
setContextMenu(null);
|
|
1050
|
+
},
|
|
1051
|
+
type: "button",
|
|
1052
|
+
children: [
|
|
1053
|
+
getIcon(icons, "move", "\u2197"),
|
|
1054
|
+
" Move\u2026"
|
|
1055
|
+
]
|
|
879
1056
|
}
|
|
880
1057
|
),
|
|
881
1058
|
(contextMenu.entry.type === "file" && fs.deleteFile || contextMenu.entry.type === "directory" && fs.deleteDirectory) && !readOnly && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
882
1059
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "kai-code__context-divider" }),
|
|
883
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
1060
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
884
1061
|
"button",
|
|
885
1062
|
{
|
|
886
1063
|
className: "is-danger",
|
|
@@ -891,7 +1068,10 @@ function KaiCode({
|
|
|
891
1068
|
setContextMenu(null);
|
|
892
1069
|
},
|
|
893
1070
|
type: "button",
|
|
894
|
-
children:
|
|
1071
|
+
children: [
|
|
1072
|
+
getIcon(icons, "delete", "\u232B"),
|
|
1073
|
+
" Delete"
|
|
1074
|
+
]
|
|
895
1075
|
}
|
|
896
1076
|
)
|
|
897
1077
|
] })
|
|
@@ -916,7 +1096,7 @@ function KaiCode({
|
|
|
916
1096
|
"aria-selected": activeFile === path,
|
|
917
1097
|
type: "button",
|
|
918
1098
|
children: [
|
|
919
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__file-icon", "aria-hidden": "true", children:
|
|
1099
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__file-icon", "aria-hidden": "true", children: getFileIcon(path, fileIcons, icons) }),
|
|
920
1100
|
fileName,
|
|
921
1101
|
dirtyFiles.has(path) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__dirty-dot", "aria-label": "Unsaved" })
|
|
922
1102
|
]
|
|
@@ -929,7 +1109,7 @@ function KaiCode({
|
|
|
929
1109
|
"aria-label": `Close ${fileName}`,
|
|
930
1110
|
onClick: () => closeFile(path),
|
|
931
1111
|
type: "button",
|
|
932
|
-
children: "\xD7"
|
|
1112
|
+
children: getIcon(icons, "close", "\xD7")
|
|
933
1113
|
}
|
|
934
1114
|
)
|
|
935
1115
|
]
|
|
@@ -989,7 +1169,7 @@ function KaiCode({
|
|
|
989
1169
|
},
|
|
990
1170
|
activeFile
|
|
991
1171
|
) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "kai-code__welcome", children: [
|
|
992
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "kai-code__welcome-mark", children: "K" }),
|
|
1172
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "kai-code__welcome-mark", children: getIcon(icons, "brand", "K") }),
|
|
993
1173
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { children: "KaiCode" }),
|
|
994
1174
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "Select a file from the Explorer to start editing." })
|
|
995
1175
|
] }) })
|
|
@@ -1081,6 +1261,58 @@ function KaiCode({
|
|
|
1081
1261
|
)
|
|
1082
1262
|
}
|
|
1083
1263
|
),
|
|
1264
|
+
moveTarget && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1265
|
+
"div",
|
|
1266
|
+
{
|
|
1267
|
+
className: "kai-code__dialog-backdrop",
|
|
1268
|
+
onMouseDown: (event) => {
|
|
1269
|
+
if (event.target === event.currentTarget) setMoveTarget(null);
|
|
1270
|
+
},
|
|
1271
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1272
|
+
"form",
|
|
1273
|
+
{
|
|
1274
|
+
className: "kai-code__dialog",
|
|
1275
|
+
role: "dialog",
|
|
1276
|
+
"aria-modal": "true",
|
|
1277
|
+
"aria-labelledby": moveTitleId,
|
|
1278
|
+
onSubmit: (event) => void moveEntry(event),
|
|
1279
|
+
children: [
|
|
1280
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("h2", { id: moveTitleId, children: [
|
|
1281
|
+
"Move ",
|
|
1282
|
+
moveTarget.type === "file" ? "File" : "Folder"
|
|
1283
|
+
] }),
|
|
1284
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: moveTarget.path }),
|
|
1285
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: moveInputId, children: "Destination path" }),
|
|
1286
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1287
|
+
"input",
|
|
1288
|
+
{
|
|
1289
|
+
id: moveInputId,
|
|
1290
|
+
autoFocus: true,
|
|
1291
|
+
value: moveDestination,
|
|
1292
|
+
onChange: (event) => setMoveDestination(event.target.value),
|
|
1293
|
+
placeholder: moveTarget.type === "file" ? "src/components/Example.tsx" : "src/components"
|
|
1294
|
+
}
|
|
1295
|
+
),
|
|
1296
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "kai-code__dialog-error", role: "alert", children: error }),
|
|
1297
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "kai-code__dialog-actions", children: [
|
|
1298
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1299
|
+
"button",
|
|
1300
|
+
{
|
|
1301
|
+
onClick: () => {
|
|
1302
|
+
setMoveTarget(null);
|
|
1303
|
+
setError(null);
|
|
1304
|
+
},
|
|
1305
|
+
type: "button",
|
|
1306
|
+
children: "Cancel"
|
|
1307
|
+
}
|
|
1308
|
+
),
|
|
1309
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "is-primary", type: "submit", children: "Move" })
|
|
1310
|
+
] })
|
|
1311
|
+
]
|
|
1312
|
+
}
|
|
1313
|
+
)
|
|
1314
|
+
}
|
|
1315
|
+
),
|
|
1084
1316
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("footer", { className: "kai-code__statusbar", children: [
|
|
1085
1317
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "kai-code__status-left", children: [
|
|
1086
1318
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "kai-code__status-branch", children: "\u2442 main" }),
|