Feat: add shortcut to open code modal (Ctrl shift C)
This commit is contained in:
parent
9af9647fb3
commit
0e55a4f8c8
7 changed files with 64 additions and 0 deletions
|
|
@ -21,6 +21,7 @@ import { useDarkStore } from "./stores/darkStore";
|
||||||
import useFlowsManagerStore from "./stores/flowsManagerStore";
|
import useFlowsManagerStore from "./stores/flowsManagerStore";
|
||||||
import { useStoreStore } from "./stores/storeStore";
|
import { useStoreStore } from "./stores/storeStore";
|
||||||
import { useTypesStore } from "./stores/typesStore";
|
import { useTypesStore } from "./stores/typesStore";
|
||||||
|
import useFlowStore from "./stores/flowStore";
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const removeFromTempNotificationList = useAlertStore(
|
const removeFromTempNotificationList = useAlertStore(
|
||||||
|
|
@ -44,6 +45,25 @@ export default function App() {
|
||||||
const refreshStars = useDarkStore((state) => state.refreshStars);
|
const refreshStars = useDarkStore((state) => state.refreshStars);
|
||||||
const checkHasStore = useStoreStore((state) => state.checkHasStore);
|
const checkHasStore = useStoreStore((state) => state.checkHasStore);
|
||||||
|
|
||||||
|
const handleModalWShortcut = useFlowStore(state => state.handleModalWShortcut);
|
||||||
|
const nodes = useFlowStore(state => state.nodes);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onKeyDown = (event: KeyboardEvent) => {
|
||||||
|
const selectedNode = nodes.filter((obj) => obj.selected);
|
||||||
|
if ((event.ctrlKey || event.metaKey) && event.shiftKey && event.key === "C" && selectedNode.length > 0) {
|
||||||
|
event.preventDefault();
|
||||||
|
handleModalWShortcut("code");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("keydown", onKeyDown);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("keydown", onKeyDown);
|
||||||
|
};
|
||||||
|
}, [handleModalWShortcut, nodes]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refreshStars();
|
refreshStars();
|
||||||
refreshVersion();
|
refreshVersion();
|
||||||
|
|
|
||||||
|
|
@ -267,6 +267,7 @@ export default function GenericNode({
|
||||||
showNode={showNode}
|
showNode={showNode}
|
||||||
openAdvancedModal={false}
|
openAdvancedModal={false}
|
||||||
onCloseAdvancedModal={() => {}}
|
onCloseAdvancedModal={() => {}}
|
||||||
|
selected={selected}
|
||||||
></NodeToolbarComponent>
|
></NodeToolbarComponent>
|
||||||
</NodeToolbar>
|
</NodeToolbar>
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,27 @@ export default function CodeAreaModal({
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleModalWShortcut = useFlowStore((state) => state.handleModalWShortcut)
|
||||||
|
const openCodeModalWShortcut = useFlowStore(state => state.openCodeModalWShortcut);
|
||||||
|
const nodes = useFlowStore(state => state.nodes);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onKeyDown = (event: KeyboardEvent) => {
|
||||||
|
|
||||||
|
const selectedNode = nodes.filter((obj) => obj.selected);
|
||||||
|
if ((event.ctrlKey || event.metaKey) && event.shiftKey && event.key === "C" && selectedNode.length > 0) {
|
||||||
|
event.preventDefault();
|
||||||
|
setOpen(openCodeModalWShortcut)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
document.addEventListener("keydown", onKeyDown);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("keydown", onKeyDown);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (openModal) setOpen(true);
|
if (openModal) setOpen(true);
|
||||||
}, [openModal]);
|
}, [openModal]);
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ export default function NodeToolbarComponent({
|
||||||
numberOfHandles,
|
numberOfHandles,
|
||||||
showNode,
|
showNode,
|
||||||
name = "code",
|
name = "code",
|
||||||
|
selected,
|
||||||
onCloseAdvancedModal,
|
onCloseAdvancedModal,
|
||||||
}: nodeToolbarPropsType): JSX.Element {
|
}: nodeToolbarPropsType): JSX.Element {
|
||||||
const nodeLength = Object.keys(data.node!.template).filter(
|
const nodeLength = Object.keys(data.node!.template).filter(
|
||||||
|
|
@ -89,6 +90,14 @@ export default function NodeToolbarComponent({
|
||||||
}, [showModalAdvanced]);
|
}, [showModalAdvanced]);
|
||||||
const updateNodeInternals = useUpdateNodeInternals();
|
const updateNodeInternals = useUpdateNodeInternals();
|
||||||
|
|
||||||
|
const openCodeModalWShortcut = useFlowStore(state => state.openCodeModalWShortcut);
|
||||||
|
const handleModalWShortcut = useFlowStore(state => state.handleModalWShortcut);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(openCodeModalWShortcut)
|
||||||
|
setOpenModal(openCodeModalWShortcut)
|
||||||
|
}, [openCodeModalWShortcut, handleModalWShortcut])
|
||||||
|
|
||||||
const setLastCopiedSelection = useFlowStore(state => state.setLastCopiedSelection);
|
const setLastCopiedSelection = useFlowStore(state => state.setLastCopiedSelection);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFlowComponent(createFlowComponent(cloneDeep(data), version));
|
setFlowComponent(createFlowComponent(cloneDeep(data), version));
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,16 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
flowPool: {},
|
flowPool: {},
|
||||||
inputs: [],
|
inputs: [],
|
||||||
outputs: [],
|
outputs: [],
|
||||||
|
openCodeModalWShortcut: false,
|
||||||
|
handleModalWShortcut: ((modal) => {
|
||||||
|
switch (modal) {
|
||||||
|
case "code":
|
||||||
|
set((state) => ({
|
||||||
|
openCodeModalWShortcut: !state.openCodeModalWShortcut,
|
||||||
|
}));
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}),
|
||||||
setFlowPool: (flowPool) => {
|
setFlowPool: (flowPool) => {
|
||||||
set({ flowPool });
|
set({ flowPool });
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -484,6 +484,7 @@ export type nodeToolbarPropsType = {
|
||||||
name?: string;
|
name?: string;
|
||||||
openAdvancedModal?: boolean;
|
openAdvancedModal?: boolean;
|
||||||
onCloseAdvancedModal?: (close: boolean) => void;
|
onCloseAdvancedModal?: (close: boolean) => void;
|
||||||
|
selected: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type parsedDataType = {
|
export type parsedDataType = {
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ export type FlowPoolType = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FlowStoreType = {
|
export type FlowStoreType = {
|
||||||
|
openCodeModalWShortcut: boolean;
|
||||||
|
handleModalWShortcut: (modal: string) => void
|
||||||
flowPool: FlowPoolType;
|
flowPool: FlowPoolType;
|
||||||
inputs: Array<{ type: string; id: string }>;
|
inputs: Array<{ type: string; id: string }>;
|
||||||
outputs: Array<{ type: string; id: string }>;
|
outputs: Array<{ type: string; id: string }>;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue