Skip to content

Commit a499bbc

Browse files
authored
Merge pull request #7 from buddhajjigae/annotation-feature
Annotation feature update
2 parents da53d41 + 5887fb6 commit a499bbc

File tree

5 files changed

+154
-3
lines changed

5 files changed

+154
-3
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import React, { useContext, useRef } from 'react';
2+
import { ChildElement, HTMLType } from '../../interfaces/Interfaces';
3+
import { ItemTypes } from '../../constants/ItemTypes';
4+
import StateContext from '../../context/context';
5+
import { combineStyles } from '../../helperFunctions/combineStyles';
6+
import globalDefaultStyle from '../../public/styles/globalDefaultStyles';
7+
import Modal from '@material-ui/core/Modal';
8+
9+
function Annotation({
10+
childId,
11+
type,
12+
typeId,
13+
style,
14+
children
15+
}: ChildElement) {
16+
const [state, dispatch] = useContext(StateContext);
17+
const ref = useRef(null);
18+
19+
// find the HTML element corresponding with this instance of an HTML element
20+
// find the current component to render on the canvas
21+
const HTMLType: HTMLType = state.HTMLTypes.find(
22+
(type: HTMLType) => type.id === typeId
23+
);
24+
25+
// hook that allows component to be draggable
26+
27+
// combine all styles so that higher priority style specifications overrule lower priority style specifications
28+
// priority order is 1) style directly set for this child (style), 2) style of the referenced HTML element, and 3) default styling
29+
const defaultNestableStyle = { ...globalDefaultStyle };
30+
const separatorStyle = {
31+
padding: '5px 10px',
32+
margin: '1px 10px',
33+
};
34+
35+
36+
const combinedStyle = combineStyles(
37+
combineStyles(combineStyles(defaultNestableStyle, HTMLType.style), style),
38+
separatorStyle
39+
);
40+
41+
const [open, setOpen] = React.useState(false);
42+
43+
const handleAnnoOpen = (id) => {
44+
setOpen(true);
45+
//annotateOpen(id);
46+
};
47+
48+
const handleClose = () => {
49+
setOpen(false);
50+
};
51+
52+
const handleAnnoChange = (event) => {
53+
const { value } = event.target;
54+
55+
console.log("ID ", event.target.id)
56+
console.log(event.target);
57+
if(value === '') {
58+
document.getElementById("btn" + event.target.id).style.background = '#3ec1ac';
59+
document.getElementById("btn" + event.target.id).id = 'btn' + event.target.id;
60+
} else {
61+
document.getElementById("btn" + event.target.id).style.background = '#cc99ff';
62+
document.getElementById("btn" + event.target.id).id = 'btn' + event.target.id;
63+
}
64+
}
65+
66+
return (
67+
<div>
68+
{/* Caret start */}
69+
<button className='annotate-button-empty' id={"btn" + childId} onClick={() => handleAnnoOpen(childId)}>DIRECT CHILD HTML NESTABLE HERE</button>
70+
<Modal
71+
open={open}
72+
onClose={handleClose}
73+
keepMounted={true}
74+
>
75+
<textarea className='annotate-textarea' id={state.canvasFocus.childId} onChange={handleAnnoChange}></textarea>
76+
</Modal>
77+
{/* Caret end */}
78+
</div>
79+
);
80+
}
81+
82+
export default Annotation;

app/src/components/main/DirectChildHTMLNestable.tsx

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import React, { useContext, useRef } from 'react';
1+
import React, { useContext, useEffect, useRef } from 'react';
22
import { ChildElement, HTMLType } from '../../interfaces/Interfaces';
33
import { useDrag, useDrop, DropTargetMonitor } from 'react-dnd';
44
import { ItemTypes } from '../../constants/ItemTypes';
55
import StateContext from '../../context/context';
66
import { combineStyles } from '../../helperFunctions/combineStyles';
77
import globalDefaultStyle from '../../public/styles/globalDefaultStyles';
88
import renderChildren from '../../helperFunctions/renderChildren';
9+
import Modal from '@material-ui/core/Modal';
10+
import Annotation from './Annotation'
11+
// Caret
12+
import { makeStyles } from '@material-ui/core';
13+
// Caret
14+
import TextField from '@material-ui/core/TextField';
15+
import uniqid from 'uniqid';
916

1017
function DirectChildHTMLNestable({
1118
childId,
@@ -26,6 +33,7 @@ const snapShotFunc = () => {
2633
//pushes the last user action on the canvas into the past array of Component
2734
state.components[focusIndex].past.push(deepCopiedState.components[focusIndex].children);
2835
};
36+
2937
// find the HTML element corresponding with this instance of an HTML element
3038
// find the current component to render on the canvas
3139
const HTMLType: HTMLType = state.HTMLTypes.find(
@@ -103,6 +111,30 @@ const snapShotFunc = () => {
103111
changeFocus(state.canvasFocus.componentId, childId);
104112
}
105113

114+
// Caret Start
115+
const [open, setOpen] = React.useState(false);
116+
117+
const handleAnnoOpen = (id) => {
118+
setOpen(true);
119+
//annotateOpen(id);
120+
};
121+
122+
const handleClose = () => {
123+
setOpen(false);
124+
};
125+
126+
const handleAnnoChange = (event) => {
127+
const { value } = event.target;
128+
if(value === '') {
129+
document.getElementById("btn" + event.target.id).style.background = '#3ec1ac';
130+
document.getElementById("btn" + event.target.id).id = 'btn' + event.target.id;
131+
} else {
132+
document.getElementById("btn" + event.target.id).style.background = '#cc99ff';
133+
document.getElementById("btn" + event.target.id).id = 'btn' + event.target.id;
134+
}
135+
}
136+
// Caret End
137+
106138
// combine all styles so that higher priority style specifications overrule lower priority style specifications
107139
// priority order is 1) style directly set for this child (style), 2) style of the referenced HTML element, and 3) default styling
108140
const defaultNestableStyle = { ...globalDefaultStyle };
@@ -119,12 +151,21 @@ const snapShotFunc = () => {
119151
combineStyles(combineStyles(defaultNestableStyle, HTMLType.style), style),
120152
interactiveStyle
121153
);
122-
123154
drag(drop(ref));
124155
return (
125156
<div onClick={onClickHandler} style={combinedStyle} ref={ref}>
126157
{HTMLType.placeHolderShort}
127158
{renderChildren(children)}
159+
{/* Caret start */}
160+
<Annotation
161+
childId={childId}
162+
typeId={typeId}
163+
type={type}
164+
name={name}
165+
style={style}
166+
>
167+
</Annotation>
168+
{/* Caret end */}
128169
</div>
129170
);
130171
}

app/src/helperFunctions/renderChildren.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const renderChildren = (children: ChildElement[]) => {
4545
}
4646
// child is a nestable type of HTML element (divs and forms)
4747
else if (type === 'HTML Element' && (typeId === 11 || typeId === 2)) {
48-
return (
48+
return ( <div>
4949
<DirectChildHTMLNestable
5050
childId={childId}
5151
type={type}
@@ -55,6 +55,7 @@ const renderChildren = (children: ChildElement[]) => {
5555
key={'DirChildHTMLNest' + childId.toString() + name}
5656
name={child.name}
5757
/>
58+
</div>
5859
);
5960
}
6061
else if (type === 'HTML Element' && typeId === 1000 ) {

app/src/public/styles/style.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,32 @@ NAVBAR
403403
width: 16%;
404404
}
405405

406+
/* Caret Start
407+
/////////////////////////////////////////////////
408+
ANNOTATIONS
409+
/////////////////////////////////////////////////
410+
*/
411+
412+
.annotate-button-empty {
413+
float: right;
414+
background-color: #3ec1ac;
415+
}
416+
417+
.annotate-button-filled {
418+
float: right;
419+
}
420+
421+
.annotate-textarea {
422+
width: 400px;
423+
height: 250px;
424+
display: block;
425+
position: relative;
426+
margin-left: 35%;
427+
margin-right: auto;
428+
white-space: pre-wrap;
429+
}
430+
/* Caret End
431+
406432
/* Material-UI */
407433

408434
/* Sortable tree sorting */

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
"seamless-immutable": "^7.1.4",
162162
"source-map-support": "^0.5.19",
163163
"spectron": "^11.1.0",
164+
"uniqid": "^5.3.0",
164165
"uuid": "^8.2.0"
165166
},
166167
"devDependencies": {

0 commit comments

Comments
 (0)