@backmatter/studio 0.0.18 → 0.0.20
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/dist/chunks/{UiKitApp-DkuQBiQZ.js → UiKitApp-C269OA8v.js} +528 -481
- package/dist/chunks/{WorkspaceRoutes-DVvb3N-V.js → WorkspaceRoutes-B4B5jjje.js} +24376 -23915
- package/dist/chunks/{dashboard-B4FITg6c.js → dashboard-DeNgythd.js} +586 -565
- package/dist/chunks/{index-CegtXnEI.js → index-7-TtXaMq.js} +104 -104
- package/dist/dashboard.js +2 -2
- package/dist/index.js +166 -159
- package/dist/site-widget.css +25 -6
- package/dist/site-widget.js +6925 -6840
- package/dist/studio.css +171 -36
- package/package.json +2 -2
- package/src/api.ts +48 -1
- package/src/chat/ChatMessage.tsx +4 -4
- package/src/chat/ChatProvider.tsx +6 -0
- package/src/chat/chat-helpers.ts +54 -2
- package/src/chrome/CommandPalette.tsx +3 -3
- package/src/chrome/ContentExplorerSidebar.tsx +421 -74
- package/src/chrome/WorkspaceStatusBar.tsx +24 -24
- package/src/chrome/commit-error.ts +48 -60
- package/src/chrome/commit-failure.tsx +2 -2
- package/src/chrome/content-path-tree.ts +4 -0
- package/src/chrome/explorer-row-menu.ts +28 -0
- package/src/chrome/folder-create-context.ts +14 -0
- package/src/chrome/use-publish-check.ts +75 -0
- package/src/fields/FieldControl.tsx +173 -62
- package/src/pages/BlocksList.tsx +38 -3
- package/src/pages/DocEditorPage.tsx +47 -64
- package/src/pages/EmbedPublishPage.tsx +13 -5
- package/src/pages/GithubConnectPage.tsx +1 -1
- package/src/pages/LoginPage.tsx +67 -5
- package/src/pages/MediaFieldInput.tsx +155 -63
- package/src/pages/MediaGalleryPage.tsx +56 -3
- package/src/pages/PreviewAddress.tsx +30 -0
- package/src/pages/WorkspaceHomePage.tsx +1 -1
- package/src/pages/ui-kit/colors.tsx +2 -0
- package/src/pages/ui-kit/fields.tsx +60 -0
- package/src/styles/themes.ts +2 -0
- package/src/styles/tokens.stylex.ts +1 -0
- package/src/ui/Button.tsx +14 -0
- package/src/ui/Field.tsx +12 -1
- package/src/ui/Input.tsx +191 -97
- package/src/ui/popup.ts +13 -6
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
// packages/studio/src/chrome/ContentExplorerSidebar.tsx
|
|
2
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { Fragment, createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { createPortal } from "react-dom";
|
|
4
|
+
import { ContextMenu } from "@base-ui/react/context-menu";
|
|
4
5
|
import { Link, useLocation, useNavigate, useSearchParams } from "react-router";
|
|
5
6
|
import * as stylex from "@stylexjs/stylex";
|
|
6
7
|
import {
|
|
8
|
+
deleteDoc,
|
|
7
9
|
notifyTreeChanged,
|
|
10
|
+
renameDoc,
|
|
8
11
|
saveDoc,
|
|
12
|
+
type ApiError,
|
|
9
13
|
type DocListItem,
|
|
10
14
|
type DocStatus,
|
|
11
15
|
type TreeChangeDetail,
|
|
@@ -16,6 +20,7 @@ import { Tooltip } from "../ui/Tooltip";
|
|
|
16
20
|
import {
|
|
17
21
|
contentDocPath,
|
|
18
22
|
contentRailHref,
|
|
23
|
+
contentTypePath,
|
|
19
24
|
isWorkspaceCodePath,
|
|
20
25
|
isWorkspaceEditorPath,
|
|
21
26
|
isWorkspaceMediaPath,
|
|
@@ -57,12 +62,16 @@ import {
|
|
|
57
62
|
} from "./content-path-tree";
|
|
58
63
|
import {
|
|
59
64
|
isValidContentSlug,
|
|
65
|
+
renameFieldExit,
|
|
60
66
|
resolveFolderCreateContext,
|
|
61
67
|
slugFromNewFileName,
|
|
62
68
|
withModelFolderPlaceholders,
|
|
63
69
|
type FolderCreateContext,
|
|
64
70
|
} from "./folder-create-context";
|
|
65
71
|
import { canWriteContent } from "../workspace/permissions";
|
|
72
|
+
import { fileExplorerMenu, folderExplorerMenu } from "./explorer-row-menu";
|
|
73
|
+
import { ConfirmDialog } from "../ui/ConfirmDialog";
|
|
74
|
+
import { cx, popup, popupClassName } from "../ui/popup";
|
|
66
75
|
import {
|
|
67
76
|
contentRailCurrent,
|
|
68
77
|
contentTreeVisible,
|
|
@@ -389,6 +398,21 @@ export function ActivityRail({
|
|
|
389
398
|
);
|
|
390
399
|
}
|
|
391
400
|
|
|
401
|
+
type ExplorerRowActions = {
|
|
402
|
+
canWrite: boolean;
|
|
403
|
+
renamingKey: string | null;
|
|
404
|
+
renameError: string | null;
|
|
405
|
+
renaming: boolean;
|
|
406
|
+
onStartRename: (node: PathTreeFile) => void;
|
|
407
|
+
onCancelRename: () => void;
|
|
408
|
+
onSubmitRename: (node: PathTreeFile, name: string) => void;
|
|
409
|
+
onRequestDelete: (node: PathTreeFile) => void;
|
|
410
|
+
onStartNewFile: (pathKey: string) => void;
|
|
411
|
+
models: ContentTypeNav[];
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
const ExplorerRowActionsContext = createContext<ExplorerRowActions | null>(null);
|
|
415
|
+
|
|
392
416
|
function ExplorerSection({
|
|
393
417
|
section,
|
|
394
418
|
models,
|
|
@@ -414,6 +438,12 @@ function ExplorerSection({
|
|
|
414
438
|
const [newFileFolder, setNewFileFolder] = useState<string | null>(null);
|
|
415
439
|
const [newFileError, setNewFileError] = useState<string | null>(null);
|
|
416
440
|
const [creating, setCreating] = useState(false);
|
|
441
|
+
const [renamingKey, setRenamingKey] = useState<string | null>(null);
|
|
442
|
+
const [renameError, setRenameError] = useState<string | null>(null);
|
|
443
|
+
const [renaming, setRenaming] = useState(false);
|
|
444
|
+
const [pendingDelete, setPendingDelete] = useState<PathTreeFile | null>(null);
|
|
445
|
+
const [deleteError, setDeleteError] = useState<string | null>(null);
|
|
446
|
+
const [deleting, setDeleting] = useState(false);
|
|
417
447
|
|
|
418
448
|
const tree = useMemo(() => {
|
|
419
449
|
const leaves: PathTreeFile[] = [];
|
|
@@ -429,6 +459,9 @@ function ExplorerSection({
|
|
|
429
459
|
href: contentDocPath(workspace.workspaceSlug, doc.type, doc.slug),
|
|
430
460
|
active: docMatchesRoute(route, doc),
|
|
431
461
|
dirty: isDirtyStatus(doc.status),
|
|
462
|
+
type: doc.type,
|
|
463
|
+
slug: doc.slug,
|
|
464
|
+
slugInPath: model.path.includes("{slug}"),
|
|
432
465
|
});
|
|
433
466
|
}
|
|
434
467
|
}
|
|
@@ -439,12 +472,95 @@ function ExplorerSection({
|
|
|
439
472
|
const startNewFile = useCallback(
|
|
440
473
|
(pathKey: string) => {
|
|
441
474
|
setNewFileError(null);
|
|
475
|
+
setRenamingKey(null);
|
|
476
|
+
setRenameError(null);
|
|
442
477
|
setNewFileFolder(pathKey);
|
|
443
478
|
onExpandFolderPath(pathKey);
|
|
444
479
|
},
|
|
445
480
|
[onExpandFolderPath],
|
|
446
481
|
);
|
|
447
482
|
|
|
483
|
+
const startRename = useCallback((node: PathTreeFile) => {
|
|
484
|
+
setNewFileFolder(null);
|
|
485
|
+
setNewFileError(null);
|
|
486
|
+
setRenameError(null);
|
|
487
|
+
setRenamingKey(fileMenuKey(node));
|
|
488
|
+
}, []);
|
|
489
|
+
|
|
490
|
+
const submitRename = useCallback(
|
|
491
|
+
async (node: PathTreeFile, rawName: string) => {
|
|
492
|
+
const slug = slugFromNewFileName(rawName, fileExtFromRepoPath(node.repoPath));
|
|
493
|
+
if (!slug) {
|
|
494
|
+
setRenameError("Enter a file name.");
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
if (slug === node.slug) {
|
|
498
|
+
setRenamingKey(null);
|
|
499
|
+
setRenameError(null);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (!isValidContentSlug(slug)) {
|
|
503
|
+
setRenameError("Use lowercase letters, numbers, and hyphens.");
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const list = docsByType.get(node.type) ?? [];
|
|
507
|
+
if (list.some((doc) => doc.slug === slug)) {
|
|
508
|
+
setRenameError("A file with that name already exists.");
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
setRenaming(true);
|
|
512
|
+
setRenameError(null);
|
|
513
|
+
try {
|
|
514
|
+
const { doc } = await renameDoc(workspace.workspaceId, node.type, node.slug, slug);
|
|
515
|
+
notifyTreeChanged({
|
|
516
|
+
workspaceId: workspace.workspaceId,
|
|
517
|
+
type: node.type,
|
|
518
|
+
slug: node.slug,
|
|
519
|
+
remove: true,
|
|
520
|
+
});
|
|
521
|
+
notifyTreeChanged({
|
|
522
|
+
workspaceId: workspace.workspaceId,
|
|
523
|
+
type: doc.type,
|
|
524
|
+
slug: doc.slug,
|
|
525
|
+
status: doc.status,
|
|
526
|
+
});
|
|
527
|
+
setRenamingKey(null);
|
|
528
|
+
if (route.type === node.type && route.docSlug === node.slug) {
|
|
529
|
+
navigate(contentDocPath(workspace.workspaceSlug, doc.type, doc.slug));
|
|
530
|
+
}
|
|
531
|
+
} catch (err) {
|
|
532
|
+
setRenameError(fileActionError(err, "Could not rename file."));
|
|
533
|
+
} finally {
|
|
534
|
+
setRenaming(false);
|
|
535
|
+
}
|
|
536
|
+
},
|
|
537
|
+
[docsByType, navigate, route.docSlug, route.type, workspace],
|
|
538
|
+
);
|
|
539
|
+
|
|
540
|
+
const confirmDelete = useCallback(async () => {
|
|
541
|
+
const node = pendingDelete;
|
|
542
|
+
if (!node) return;
|
|
543
|
+
setDeleting(true);
|
|
544
|
+
setDeleteError(null);
|
|
545
|
+
try {
|
|
546
|
+
await deleteDoc(workspace.workspaceId, node.type, node.slug);
|
|
547
|
+
notifyTreeChanged({
|
|
548
|
+
workspaceId: workspace.workspaceId,
|
|
549
|
+
type: node.type,
|
|
550
|
+
slug: node.slug,
|
|
551
|
+
remove: true,
|
|
552
|
+
});
|
|
553
|
+
setPendingDelete(null);
|
|
554
|
+
if (route.type === node.type && route.docSlug === node.slug) {
|
|
555
|
+
navigate(contentTypePath(workspace.workspaceSlug, node.type));
|
|
556
|
+
}
|
|
557
|
+
} catch (err) {
|
|
558
|
+
setDeleteError(fileActionError(err, "Could not delete file."));
|
|
559
|
+
} finally {
|
|
560
|
+
setDeleting(false);
|
|
561
|
+
}
|
|
562
|
+
}, [navigate, pendingDelete, route.docSlug, route.type, workspace]);
|
|
563
|
+
|
|
448
564
|
const submitNewFile = useCallback(
|
|
449
565
|
async (pathKey: string, ctx: FolderCreateContext, rawName: string) => {
|
|
450
566
|
const slug = slugFromNewFileName(rawName, ctx.ext);
|
|
@@ -488,32 +604,73 @@ function ExplorerSection({
|
|
|
488
604
|
);
|
|
489
605
|
|
|
490
606
|
const hasTree = tree.length > 0;
|
|
607
|
+
const rowActions = useMemo<ExplorerRowActions>(
|
|
608
|
+
() => ({
|
|
609
|
+
canWrite,
|
|
610
|
+
renamingKey,
|
|
611
|
+
renameError,
|
|
612
|
+
renaming,
|
|
613
|
+
onStartRename: startRename,
|
|
614
|
+
onCancelRename: () => {
|
|
615
|
+
setRenamingKey(null);
|
|
616
|
+
setRenameError(null);
|
|
617
|
+
},
|
|
618
|
+
onSubmitRename: (node, name) => {
|
|
619
|
+
void submitRename(node, name);
|
|
620
|
+
},
|
|
621
|
+
onRequestDelete: (node) => {
|
|
622
|
+
setDeleteError(null);
|
|
623
|
+
setPendingDelete(node);
|
|
624
|
+
},
|
|
625
|
+
onStartNewFile: startNewFile,
|
|
626
|
+
models,
|
|
627
|
+
}),
|
|
628
|
+
[canWrite, models, renameError, renaming, renamingKey, startNewFile, startRename, submitRename],
|
|
629
|
+
);
|
|
491
630
|
|
|
492
631
|
return (
|
|
493
|
-
<
|
|
494
|
-
<
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
632
|
+
<ExplorerRowActionsContext.Provider value={rowActions}>
|
|
633
|
+
<section {...stylex.props(styles.section)}>
|
|
634
|
+
<div {...stylex.props(styles.sectionLabel)}>{sectionTitle(section)}</div>
|
|
635
|
+
{!hasTree ? (
|
|
636
|
+
<p {...stylex.props(styles.emptySection)}>No files</p>
|
|
637
|
+
) : (
|
|
638
|
+
<PathTree
|
|
639
|
+
nodes={tree}
|
|
640
|
+
depth={0}
|
|
641
|
+
expanded={expanded}
|
|
642
|
+
onToggleFolder={onToggleFolder}
|
|
643
|
+
models={models}
|
|
644
|
+
canWrite={canWrite}
|
|
645
|
+
newFileFolder={newFileFolder}
|
|
646
|
+
newFileError={newFileError}
|
|
647
|
+
creating={creating}
|
|
648
|
+
onStartNewFile={startNewFile}
|
|
649
|
+
onCancelNewFile={() => {
|
|
650
|
+
setNewFileFolder(null);
|
|
651
|
+
setNewFileError(null);
|
|
652
|
+
}}
|
|
653
|
+
onSubmitNewFile={submitNewFile}
|
|
654
|
+
/>
|
|
655
|
+
)}
|
|
656
|
+
</section>
|
|
657
|
+
<ConfirmDialog
|
|
658
|
+
open={pendingDelete !== null}
|
|
659
|
+
onOpenChange={(next) => {
|
|
660
|
+
if (!next && !deleting) setPendingDelete(null);
|
|
661
|
+
}}
|
|
662
|
+
title="Delete file?"
|
|
663
|
+
description={
|
|
664
|
+
pendingDelete
|
|
665
|
+
? `${pendingDelete.name} leaves your working tree. A file on the branch stays hidden until you commit.${deleteError ? ` ${deleteError}` : ""}`
|
|
666
|
+
: undefined
|
|
667
|
+
}
|
|
668
|
+
confirmLabel="Delete"
|
|
669
|
+
destructive
|
|
670
|
+
busy={deleting}
|
|
671
|
+
onConfirm={confirmDelete}
|
|
672
|
+
/>
|
|
673
|
+
</ExplorerRowActionsContext.Provider>
|
|
517
674
|
);
|
|
518
675
|
}
|
|
519
676
|
|
|
@@ -659,42 +816,52 @@ function FolderTreeRow({
|
|
|
659
816
|
createContext: FolderCreateContext | null;
|
|
660
817
|
onNewFile?: () => void;
|
|
661
818
|
}) {
|
|
819
|
+
const menu = folderExplorerMenu({
|
|
820
|
+
canWrite: Boolean(onNewFile),
|
|
821
|
+
canCreate: createContext !== null,
|
|
822
|
+
});
|
|
662
823
|
return (
|
|
663
824
|
<TreeRowFrame depth={depth}>
|
|
664
|
-
<
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
825
|
+
<RowMenu label={node.name} items={menu.map((action) => ({
|
|
826
|
+
id: action,
|
|
827
|
+
label: "Create file",
|
|
828
|
+
onSelect: () => onNewFile?.(),
|
|
829
|
+
}))}>
|
|
830
|
+
<div {...stylex.props(styles.folderRowHost)}>
|
|
831
|
+
<button
|
|
832
|
+
type="button"
|
|
833
|
+
aria-expanded={open}
|
|
834
|
+
aria-label={node.name}
|
|
835
|
+
onClick={onToggle}
|
|
836
|
+
{...stylex.props(styles.treeRow, styles.folderRowBtn)}
|
|
837
|
+
style={{ paddingLeft: treeRowPad(depth) }}
|
|
838
|
+
>
|
|
839
|
+
<span {...stylex.props(styles.twistie)}>
|
|
840
|
+
<ExplorerTwistie open={open} />
|
|
841
|
+
</span>
|
|
842
|
+
<span {...stylex.props(styles.treeIcon)}>
|
|
843
|
+
<ExplorerFolderIcon />
|
|
844
|
+
</span>
|
|
845
|
+
<span {...stylex.props(styles.treeLabel)}>{node.name}</span>
|
|
846
|
+
</button>
|
|
847
|
+
{createContext && onNewFile ? (
|
|
848
|
+
<Tooltip label="New file" side="right">
|
|
849
|
+
<button
|
|
850
|
+
type="button"
|
|
851
|
+
data-folder-action
|
|
852
|
+
aria-label={`New file in ${node.name}`}
|
|
853
|
+
onClick={(e) => {
|
|
854
|
+
e.stopPropagation();
|
|
855
|
+
onNewFile();
|
|
856
|
+
}}
|
|
857
|
+
{...stylex.props(styles.folderActionBtn)}
|
|
858
|
+
>
|
|
859
|
+
<ExplorerTreeNewFileIcon />
|
|
860
|
+
</button>
|
|
861
|
+
</Tooltip>
|
|
862
|
+
) : null}
|
|
863
|
+
</div>
|
|
864
|
+
</RowMenu>
|
|
698
865
|
</TreeRowFrame>
|
|
699
866
|
);
|
|
700
867
|
}
|
|
@@ -704,21 +871,40 @@ function NewFileTreeRow({
|
|
|
704
871
|
ext,
|
|
705
872
|
error,
|
|
706
873
|
disabled,
|
|
874
|
+
initial = "",
|
|
875
|
+
label = "New file name",
|
|
876
|
+
exitOnBlur = false,
|
|
707
877
|
onCancel,
|
|
708
878
|
onSubmit,
|
|
879
|
+
onBlurExit,
|
|
709
880
|
}: {
|
|
710
881
|
depth: number;
|
|
711
882
|
ext: string;
|
|
712
883
|
error: string | null;
|
|
713
884
|
disabled: boolean;
|
|
885
|
+
initial?: string;
|
|
886
|
+
label?: string;
|
|
887
|
+
/** Rename leaves the field on blur. New file stays until Enter or Escape. */
|
|
888
|
+
exitOnBlur?: boolean;
|
|
714
889
|
onCancel: () => void;
|
|
715
890
|
onSubmit: (name: string) => void;
|
|
891
|
+
onBlurExit?: (name: string) => void;
|
|
716
892
|
}) {
|
|
717
893
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
718
|
-
const
|
|
894
|
+
const skipBlur = useRef(false);
|
|
895
|
+
const blurReady = useRef(false);
|
|
896
|
+
const [value, setValue] = useState(initial);
|
|
719
897
|
|
|
720
898
|
useEffect(() => {
|
|
721
|
-
inputRef.current
|
|
899
|
+
const input = inputRef.current;
|
|
900
|
+
if (!input) return;
|
|
901
|
+
input.focus();
|
|
902
|
+
const dot = input.value.lastIndexOf(".");
|
|
903
|
+
input.setSelectionRange(0, dot > 0 ? dot : input.value.length);
|
|
904
|
+
const frame = requestAnimationFrame(() => {
|
|
905
|
+
blurReady.current = true;
|
|
906
|
+
});
|
|
907
|
+
return () => cancelAnimationFrame(frame);
|
|
722
908
|
}, []);
|
|
723
909
|
|
|
724
910
|
return (
|
|
@@ -741,15 +927,20 @@ function NewFileTreeRow({
|
|
|
741
927
|
value={value}
|
|
742
928
|
disabled={disabled}
|
|
743
929
|
placeholder={`name.${ext}`}
|
|
744
|
-
aria-label=
|
|
930
|
+
aria-label={label}
|
|
745
931
|
aria-invalid={error ? true : undefined}
|
|
746
932
|
onChange={(e) => setValue(e.target.value)}
|
|
747
933
|
onKeyDown={(e) => {
|
|
748
934
|
if (e.key === "Escape") {
|
|
749
935
|
e.preventDefault();
|
|
936
|
+
skipBlur.current = true;
|
|
750
937
|
onCancel();
|
|
751
938
|
}
|
|
752
939
|
}}
|
|
940
|
+
onBlur={() => {
|
|
941
|
+
if (!exitOnBlur || !blurReady.current || disabled || skipBlur.current) return;
|
|
942
|
+
onBlurExit?.(value);
|
|
943
|
+
}}
|
|
753
944
|
{...stylex.props(styles.newFileInput)}
|
|
754
945
|
/>
|
|
755
946
|
</form>
|
|
@@ -773,26 +964,137 @@ function FileTreeRow({
|
|
|
773
964
|
node: PathTreeFile;
|
|
774
965
|
depth: number;
|
|
775
966
|
}) {
|
|
967
|
+
const actions = useContext(ExplorerRowActionsContext);
|
|
776
968
|
const ext = fileExtFromRepoPath(node.repoPath);
|
|
969
|
+
const key = fileMenuKey(node);
|
|
970
|
+
if (actions && actions.renamingKey === key) {
|
|
971
|
+
return (
|
|
972
|
+
<NewFileTreeRow
|
|
973
|
+
depth={depth}
|
|
974
|
+
ext={ext}
|
|
975
|
+
error={actions.renameError}
|
|
976
|
+
disabled={actions.renaming}
|
|
977
|
+
initial={node.name}
|
|
978
|
+
label="File name"
|
|
979
|
+
exitOnBlur
|
|
980
|
+
onCancel={actions.onCancelRename}
|
|
981
|
+
onSubmit={(name) => actions.onSubmitRename(node, name)}
|
|
982
|
+
onBlurExit={(name) => {
|
|
983
|
+
if (renameFieldExit(node.slug, name, ext) === "cancel") {
|
|
984
|
+
actions.onCancelRename();
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
actions.onSubmitRename(node, name);
|
|
988
|
+
}}
|
|
989
|
+
/>
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
const folderKey = parentFolderKey(node.repoPath);
|
|
993
|
+
const canCreate =
|
|
994
|
+
resolveFolderCreateContext(folderKey, actions?.models ?? []) !== null;
|
|
995
|
+
const menu = fileExplorerMenu({
|
|
996
|
+
canWrite: actions?.canWrite ?? false,
|
|
997
|
+
slugInPath: node.slugInPath,
|
|
998
|
+
canCreate,
|
|
999
|
+
});
|
|
1000
|
+
const link = (
|
|
1001
|
+
<Link
|
|
1002
|
+
to={node.href}
|
|
1003
|
+
title={`content/${node.repoPath}`}
|
|
1004
|
+
{...stylex.props(styles.treeRow, styles.treeRowLink, node.active && styles.treeRowActive)}
|
|
1005
|
+
style={{ paddingLeft: treeRowPad(depth) }}
|
|
1006
|
+
>
|
|
1007
|
+
<span {...stylex.props(styles.twistie)} aria-hidden />
|
|
1008
|
+
<span {...stylex.props(styles.treeIcon)}>
|
|
1009
|
+
<ExplorerFileIcon ext={ext} />
|
|
1010
|
+
</span>
|
|
1011
|
+
<span {...stylex.props(styles.treeLabel)}>{node.name}</span>
|
|
1012
|
+
{node.dirty ? <span {...stylex.props(styles.fileDot)} aria-hidden /> : null}
|
|
1013
|
+
</Link>
|
|
1014
|
+
);
|
|
777
1015
|
return (
|
|
778
1016
|
<TreeRowFrame depth={depth}>
|
|
779
|
-
<
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
1017
|
+
<RowMenu
|
|
1018
|
+
label={node.name}
|
|
1019
|
+
items={menu.map((action) => {
|
|
1020
|
+
if (action === "new-file") {
|
|
1021
|
+
return {
|
|
1022
|
+
id: action,
|
|
1023
|
+
label: "Create file",
|
|
1024
|
+
onSelect: () => actions?.onStartNewFile(folderKey),
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
if (action === "rename") {
|
|
1028
|
+
return { id: action, label: "Rename", onSelect: () => actions?.onStartRename(node) };
|
|
1029
|
+
}
|
|
1030
|
+
return {
|
|
1031
|
+
id: action,
|
|
1032
|
+
label: "Delete",
|
|
1033
|
+
danger: true,
|
|
1034
|
+
separatorBefore: true,
|
|
1035
|
+
onSelect: () => actions?.onRequestDelete(node),
|
|
1036
|
+
};
|
|
1037
|
+
})}
|
|
784
1038
|
>
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
<ExplorerFileIcon ext={ext} />
|
|
788
|
-
</span>
|
|
789
|
-
<span {...stylex.props(styles.treeLabel)}>{node.name}</span>
|
|
790
|
-
{node.dirty ? <span {...stylex.props(styles.fileDot)} aria-hidden /> : null}
|
|
791
|
-
</Link>
|
|
1039
|
+
{link}
|
|
1040
|
+
</RowMenu>
|
|
792
1041
|
</TreeRowFrame>
|
|
793
1042
|
);
|
|
794
1043
|
}
|
|
795
1044
|
|
|
1045
|
+
function RowMenu({
|
|
1046
|
+
label,
|
|
1047
|
+
items,
|
|
1048
|
+
children,
|
|
1049
|
+
}: {
|
|
1050
|
+
label: string;
|
|
1051
|
+
items: Array<{
|
|
1052
|
+
id: string;
|
|
1053
|
+
label: string;
|
|
1054
|
+
danger?: boolean;
|
|
1055
|
+
separatorBefore?: boolean;
|
|
1056
|
+
onSelect: () => void;
|
|
1057
|
+
}>;
|
|
1058
|
+
children: React.ReactNode;
|
|
1059
|
+
}) {
|
|
1060
|
+
if (items.length === 0) return children;
|
|
1061
|
+
return (
|
|
1062
|
+
<ContextMenu.Root>
|
|
1063
|
+
<ContextMenu.Trigger className={cx(styles.menuTrigger)}>{children}</ContextMenu.Trigger>
|
|
1064
|
+
<ContextMenu.Portal>
|
|
1065
|
+
<ContextMenu.Positioner className={cx(popup.positioner)} sideOffset={8}>
|
|
1066
|
+
<ContextMenu.Popup
|
|
1067
|
+
aria-label={label}
|
|
1068
|
+
className={(state) => popupClassName(state, styles.menu)}
|
|
1069
|
+
>
|
|
1070
|
+
{items.map((item) => (
|
|
1071
|
+
<Fragment key={item.id}>
|
|
1072
|
+
{item.separatorBefore ? (
|
|
1073
|
+
<div role="separator" className={cx(styles.menuSeparator)} />
|
|
1074
|
+
) : null}
|
|
1075
|
+
<ContextMenu.Item
|
|
1076
|
+
label={item.label}
|
|
1077
|
+
onClick={item.onSelect}
|
|
1078
|
+
className={(state) =>
|
|
1079
|
+
cx(
|
|
1080
|
+
popup.item,
|
|
1081
|
+
styles.menuItem,
|
|
1082
|
+
item.danger && styles.menuDanger,
|
|
1083
|
+
state.highlighted && popup.itemHighlighted,
|
|
1084
|
+
)
|
|
1085
|
+
}
|
|
1086
|
+
>
|
|
1087
|
+
{item.label}
|
|
1088
|
+
</ContextMenu.Item>
|
|
1089
|
+
</Fragment>
|
|
1090
|
+
))}
|
|
1091
|
+
</ContextMenu.Popup>
|
|
1092
|
+
</ContextMenu.Positioner>
|
|
1093
|
+
</ContextMenu.Portal>
|
|
1094
|
+
</ContextMenu.Root>
|
|
1095
|
+
);
|
|
1096
|
+
}
|
|
1097
|
+
|
|
796
1098
|
function findActiveRepoPath(
|
|
797
1099
|
workspace: WorkspaceNav,
|
|
798
1100
|
route: ContentRoute,
|
|
@@ -843,6 +1145,25 @@ function parseContentRoute(pathname: string): ContentRoute {
|
|
|
843
1145
|
return { type, docSlug };
|
|
844
1146
|
}
|
|
845
1147
|
|
|
1148
|
+
function parentFolderKey(repoPath: string) {
|
|
1149
|
+
const parts = repoPath.split("/").filter(Boolean);
|
|
1150
|
+
parts.pop();
|
|
1151
|
+
return parts.join("/");
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
function fileMenuKey(node: Pick<PathTreeFile, "type" | "slug">) {
|
|
1155
|
+
return `${node.type}/${node.slug}`;
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
function fileActionError(err: unknown, fallback: string) {
|
|
1159
|
+
const code = err instanceof Error ? ((err as ApiError).code ?? err.message) : "";
|
|
1160
|
+
if (code === "already_exists") return "A file with that name already exists.";
|
|
1161
|
+
if (code === "invalid_slug") return "Use lowercase letters, numbers, and hyphens.";
|
|
1162
|
+
if (code === "not_found") return "That file is no longer there.";
|
|
1163
|
+
if (code === "no_change") return "Enter a different file name.";
|
|
1164
|
+
return fallback;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
846
1167
|
function docMatchesRoute(route: ContentRoute, doc: DocListItem) {
|
|
847
1168
|
return Boolean(route.type && route.docSlug === doc.slug && route.type === doc.type);
|
|
848
1169
|
}
|
|
@@ -1207,4 +1528,30 @@ const styles = stylex.create({
|
|
|
1207
1528
|
borderRadius: 999,
|
|
1208
1529
|
backgroundColor: statusDot,
|
|
1209
1530
|
},
|
|
1531
|
+
menuTrigger: {
|
|
1532
|
+
display: "block",
|
|
1533
|
+
width: "100%",
|
|
1534
|
+
minWidth: 0,
|
|
1535
|
+
},
|
|
1536
|
+
menu: {
|
|
1537
|
+
minWidth: "11.5rem",
|
|
1538
|
+
paddingBlock: space.sm,
|
|
1539
|
+
backgroundColor: colors.bgRaised,
|
|
1540
|
+
borderColor: colors.border,
|
|
1541
|
+
boxShadow: "0 18px 48px rgba(0, 0, 0, 0.42), 0 2px 8px rgba(0, 0, 0, 0.2)",
|
|
1542
|
+
},
|
|
1543
|
+
menuItem: {
|
|
1544
|
+
minHeight: 32,
|
|
1545
|
+
cursor: "pointer",
|
|
1546
|
+
fontSize: type.md,
|
|
1547
|
+
},
|
|
1548
|
+
menuSeparator: {
|
|
1549
|
+
height: 1,
|
|
1550
|
+
marginBlock: space.xs,
|
|
1551
|
+
marginInline: space.sm,
|
|
1552
|
+
backgroundColor: colors.border,
|
|
1553
|
+
},
|
|
1554
|
+
menuDanger: {
|
|
1555
|
+
color: colors.danger,
|
|
1556
|
+
},
|
|
1210
1557
|
});
|