Skip to content

Commit 0c9612e

Browse files
Merge branch 'main' into organization
2 parents 5460a98 + fe3d282 commit 0c9612e

File tree

8 files changed

+124
-9
lines changed

8 files changed

+124
-9
lines changed

app/src/components/main/Arrow.tsx

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
const Arrow = {};
2+
3+
Arrow.renderArrow = (id : number) => {
4+
console.log("RENDER ARROW ID: ", id)
5+
if(id != null) {
6+
let canvasEle = document.getElementById(`canv${id}`)//.offsetHeight;
7+
let renderEle = document.getElementById(`rend${id}`)
8+
if( canvasEle === null || renderEle === null) {
9+
return;
10+
} else {
11+
console.log("CANVAS ELE *******", canvasEle)
12+
let canvasElePosition = canvasEle.getBoundingClientRect();
13+
let renderElePosition = renderEle.getBoundingClientRect();
14+
console.log("POSITION *******" ,canvasElePosition)
15+
const canvasEleX = canvasElePosition.left + canvasElePosition.width;
16+
const canvasEleY = canvasElePosition.top + (canvasElePosition.height / 2);
17+
const renderEleX = renderElePosition.left;
18+
const renderEleY = renderElePosition.top;
19+
Arrow.lineDraw(canvasEleX, canvasEleY, renderEleX, renderEleY);
20+
}
21+
}
22+
}
23+
24+
25+
Arrow.createLineElement = (x, y, length, angle) => {
26+
let line = document.createElement("div");
27+
line.setAttribute("class", "line");
28+
let styles = 'border: 1px solid black;'
29+
+ 'width: ' + length + 'px;'
30+
+ 'height: 0px;'
31+
+ 'z-index: 9999999999;'
32+
+ '-moz-transform: rotate(' + angle + 'rad);'
33+
+ '-webkit-transform: rotate(' + angle + 'rad);'
34+
+ '-o-transform: rotate(' + angle + 'rad);'
35+
+ '-ms-transform: rotate(' + angle + 'rad);'
36+
+ 'position: absolute;'
37+
+ 'top: ' + y + 'px;'
38+
+ 'left: ' + x + 'px;';
39+
line.setAttribute('style', styles);
40+
return line;
41+
}
42+
43+
Arrow.createHeadElement = (x, y, length, angle) => {
44+
let head = document.createElement("div");
45+
head.setAttribute("class", "head");
46+
console.log('length', length)
47+
angle = angle;
48+
console.log("ANGLE >>>>>", angle)
49+
const negative = -angle;
50+
let styles = 'width: 14px;'
51+
+ 'height: 14px;'
52+
+ 'border: solid 2px;'
53+
+ 'border-radius: 50%;'
54+
+ 'z-index: 9999999999;'
55+
// + 'display: inline-block'
56+
+ 'background-color: #00FFFF;'
57+
+ 'border-color: #bbb;'
58+
//+ '-moz-transform: rotate(' + angle + 'rad);'
59+
// + '-webkit-transform: rotate(' + angle + 'rad);'
60+
//+ '-o-transform: rotate(' + angle + 'rad);'
61+
+ 'rotate: ' + angle + 'rad;'
62+
// + '-ms-transform: rotate(' + angle + 'rad);'
63+
+ 'position: absolute;'
64+
+ 'top: ' + -12 + 'px;'
65+
+ 'left: ' + 0 + (length - 10) + 'px;';
66+
head.setAttribute('style', styles);
67+
console.log(head, "<<<<< HEAD")
68+
return head;
69+
}
70+
71+
Arrow.lineDraw = (x1, y1, x2, y2) => {
72+
let a = x1 - x2,
73+
b = y1 - y2,
74+
c = Math.sqrt(a * a + b * b);
75+
76+
let sx = (x1 + x2) / 2,
77+
sy = (y1 + y2) / 2;
78+
79+
let x = sx - c / 2,
80+
y = sy;
81+
82+
let alpha = Math.PI - Math.atan2(-b, a);
83+
84+
let line = Arrow.createLineElement(x, y, c, alpha);
85+
let head = Arrow.createHeadElement(x, y, c, alpha);
86+
console.log("HEAD HERE >>>>>>", head)
87+
Arrow.deleteLines();
88+
document.getElementsByClassName("main")[0].append(line);
89+
document.getElementsByClassName("line")[0].append(head);
90+
}
91+
92+
Arrow.deleteLines = () => {
93+
let lineArray = document.getElementsByClassName("line");
94+
let headArray = document.getElementsByClassName("head");
95+
console.log("LINE ARRAY" , lineArray);
96+
for(const line of lineArray) {
97+
line.remove();
98+
}
99+
for(const head of headArray) {
100+
head.remove();
101+
}
102+
}
103+
104+
export default Arrow;

app/src/components/main/Canvas.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import StateContext from '../../context/context';
55
import { Component, DragItem } from '../../interfaces/Interfaces';
66
import { combineStyles } from '../../helperFunctions/combineStyles';
77
import renderChildren from '../../helperFunctions/renderChildren';
8+
// Caret start
9+
import Arrow from './Arrow';
810

911
function Canvas() {
1012
const [state, dispatch] = useContext(StateContext);
13+
// Caret start
14+
Arrow.deleteLines();
1115
// find the current component to render on the canvas
1216
const currentComponent: Component = state.components.find(
1317
(elem: Component) => elem.id === state.canvasFocus.componentId
@@ -32,7 +36,7 @@ function Canvas() {
3236
//pushes the last user action on the canvas into the past array of Component
3337
state.components[focusIndex].past.push(deepCopiedState.components[focusIndex].children);
3438
};
35-
39+
3640
// This hook will allow the user to drag items from the left panel on to the canvas
3741
const [{ isOver }, drop] = useDrop({
3842
accept: ItemTypes.INSTANCE,

app/src/components/main/DemoRender.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ const DemoRender = (props): JSX.Element => {
3131
if (elementType !== 'input' && elementType !== 'img' && element.children.length > 0) {
3232
renderedChildren = componentBuilder(element.children);
3333
}
34-
if (elementType === 'input') componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={childId}></Box>);
35-
else if (elementType === 'img') componentsToRender.push(<Box component={elementType} src={activeLink} className={classRender} style={elementStyle} key={key} id={childId}></Box>);
36-
else if (elementType === 'a') componentsToRender.push(<Box component={elementType} href={activeLink} className={classRender} style={elementStyle} key={key} id={childId}>{innerText}</Box>);
37-
else componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={childId}>{innerText}{renderedChildren}</Box>);
34+
if (elementType === 'input') componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
35+
else if (elementType === 'img') componentsToRender.push(<Box component={elementType} src={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}></Box>);
36+
else if (elementType === 'a') componentsToRender.push(<Box component={elementType} href={activeLink} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}>{innerText}</Box>);
37+
else componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={`rend${childId}`}>{innerText}{renderedChildren}</Box>);
3838
key += 1;
3939
}
4040
}

app/src/components/main/DirectChildHTML.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function DirectChildHTML({
6969
);
7070

7171
return (
72-
<div onClick={onClickHandler} style={combinedStyle} ref={drag}>
72+
<div onClick={onClickHandler} style={combinedStyle} ref={drag} id={`canv${childId}`}>
7373
<strong>{HTMLType.placeHolderShort}</strong>
7474
{/* Caret start */}
7575
{` (${childId})`}

app/src/components/main/DirectChildHTMLNestable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const snapShotFunc = () => {
134134
drag(drop(ref));
135135

136136
return (
137-
<div onClick={onClickHandler} style={combinedStyle} ref={ref}>
137+
<div onClick={onClickHandler} style={combinedStyle} ref={ref} id={`canv${childId}`}>
138138
<strong>{HTMLType.placeHolderShort}</strong>
139139
{/* Caret start */}
140140
{` ( ${childId} )`}

app/src/components/main/renderDemo.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.tst-btn {
55
height: 20px;
66
width: 100px;
7-
background-color: #ffffff
7+
background-color: #ffffff;
88
}
99

1010

app/src/containers/CustomizationPanel.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import ErrorMessages from '../constants/ErrorMessages';
2828
import ProjectManager from '../components/right/ProjectManager';
2929
import StateContext from '../context/context';
3030
import FormSelector from '../components/form/Selector';
31+
// Caret
32+
import Arrow from '../components/main/Arrow';
33+
import { config } from 'ace-builds';
3134

3235
// need to pass in props to use the useHistory feature of react router
3336
const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
@@ -183,6 +186,11 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
183186
state.canvasFocus.componentId
184187
]);
185188

189+
console.log("CONFIG TARGET ****************: " , state.canvasFocus.childId);
190+
Arrow.renderArrow(state.canvasFocus.childId);
191+
192+
193+
186194
const isPage = (configTarget): boolean => {
187195
const { components, rootComponents } = state;
188196
return components

app/src/interfaces/Interfaces.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export interface Component {
4343
// Caret
4444
annotations?: string;
4545
useStateCodes: string[];
46-
4746
}
4847

4948
export interface StateProp {

0 commit comments

Comments
 (0)