Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added duplicate functionality to RenderNode. #521

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions examples/landing/components/editor/RenderNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@ import styled from 'styled-components';

import ArrowUp from '../../public/icons/arrow-up.svg';
import Delete from '../../public/icons/delete.svg';
import Duplicate from '../../public/icons/duplicate.svg';
import Move from '../../public/icons/move.svg';

const IndicatorDiv = styled.div`
height: 30px;
margin-top: -29px;
font-size: 12px;
line-height: 12px;
`;

const Btn = styled.a`
padding: 0 0px;
opacity: 0.9;
display: flex;
align-items: center;
> div {
position: relative;
top: -50%;
left: -50%;
}

svg {
fill: #fff;
Expand All @@ -21,7 +34,7 @@ const IndicatorDiv = styled.div`
}
`;

const Btn = styled.a`
const DuplicateBtn = styled.a`
padding: 0 0px;
opacity: 0.9;
display: flex;
Expand All @@ -31,6 +44,11 @@ const Btn = styled.a`
top: -50%;
left: -50%;
}

svg {
width: 15px;
height: 15px;
}
`;

export const RenderNode = ({ render }) => {
Expand All @@ -47,6 +65,7 @@ export const RenderNode = ({ render }) => {
deletable,
connectors: { drag },
parent,
isCanvas,
} = useNode((node) => ({
isHover: node.events.hovered,
dom: node.dom,
Expand All @@ -55,6 +74,7 @@ export const RenderNode = ({ render }) => {
deletable: query.node(node.id).isDeletable(),
parent: node.data.parent,
props: node.data.props,
isCanvas: query.node(node.id).isCanvas(),
}));

const currentRef = useRef<HTMLDivElement>();
Expand Down Expand Up @@ -128,7 +148,7 @@ export const RenderNode = ({ render }) => {
)}
{deletable ? (
<Btn
className="cursor-pointer"
className="mr-2 cursor-pointer"
onMouseDown={(e: React.MouseEvent) => {
e.stopPropagation();
actions.delete(id);
Expand All @@ -137,6 +157,22 @@ export const RenderNode = ({ render }) => {
<Delete />
</Btn>
) : null}
{!isCanvas ? (
<DuplicateBtn
className="cursor-pointer"
onMouseDown={() => {
const {
data: { type, props },
} = query.node(id).get();
actions.add(
query.createNode(React.createElement(type, props)),
parent
);
}}
>
<Duplicate />
</DuplicateBtn>
) : null}
</IndicatorDiv>,
document.querySelector('.page-container')
)
Expand Down
1 change: 1 addition & 0 deletions examples/landing/public/icons/duplicate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.