-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
74 lines (70 loc) · 2.34 KB
/
index.tsx
File metadata and controls
74 lines (70 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Box } from "@mui/material";
import nullthrows from "nullthrows";
import { useState } from "react";
import { theme } from "../../../common/theme";
import { ComponentPropertyDialog } from "../../../components/ComponentPropertyDialog";
import type { CCComponentId } from "../../../store/component";
import { useStore } from "../../../store/react";
import CCComponentEditorContextMenu from "./components/ContextMenu";
import CCComponentEditorGrid from "./components/Grid";
import { CCComponentEditorNodePinPropertyEditor } from "./components/NodePinPropertyEditor";
import CCComponentEditorTitleBar from "./components/TitleBar";
import CCComponentEditorViewModeSwitcher from "./components/ViewModeSwitcher";
import CCComponentEditorRenderer from "./renderer";
import { ComponentEditorStoreProvider } from "./store";
export type CCComponentEditorProps = {
componentId: CCComponentId;
onEditComponent: (componentId: CCComponentId) => void;
onClose: () => void;
};
function CCComponentEditorContent({
componentId,
onEditComponent,
onClose,
}: CCComponentEditorProps) {
const { store } = useStore();
const component = nullthrows(store.components.get(componentId));
const [isComponentPropertyDialogOpen, setIsComponentPropertyDialogOpen] =
useState(false);
return (
<Box
sx={{
position: "relative",
overflow: "hidden",
backgroundColor: theme.palette.editorBackground,
}}
>
<CCComponentEditorGrid />
<CCComponentEditorRenderer />
<CCComponentEditorTitleBar
onComponentPropertyDialogOpen={() =>
setIsComponentPropertyDialogOpen(true)
}
onEditorClose={onClose}
/>
<CCComponentEditorViewModeSwitcher />
<CCComponentEditorContextMenu onEditComponent={onEditComponent} />
<CCComponentEditorNodePinPropertyEditor />
{isComponentPropertyDialogOpen && (
<ComponentPropertyDialog
defaultName={component.name}
onAccept={(newName) => {
store.components.update(componentId, { name: newName });
setIsComponentPropertyDialogOpen(false);
}}
onCancel={() => {
setIsComponentPropertyDialogOpen(false);
}}
/>
)}
</Box>
);
}
export default function CCComponentEditor(props: CCComponentEditorProps) {
const { componentId } = props;
return (
<ComponentEditorStoreProvider componentId={componentId}>
<CCComponentEditorContent {...props} />
</ComponentEditorStoreProvider>
);
}