auto-component 0.0.32 → 0.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/auto-component.css +46 -27
- package/src/index.jsx +48 -225
package/package.json
CHANGED
package/src/auto-component.css
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
#
|
|
2
|
-
position: relative;
|
|
1
|
+
#auto-component {
|
|
3
2
|
width: 100%;
|
|
4
3
|
display: flex;
|
|
5
4
|
flex-direction: column;
|
|
6
5
|
align-items: center;
|
|
7
|
-
margin: 40px 0;
|
|
8
6
|
font-family: Arial, Helvetica, sans-serif
|
|
9
7
|
}
|
|
10
|
-
#
|
|
11
|
-
|
|
8
|
+
#auto-component-entry {
|
|
9
|
+
position: fixed;
|
|
10
|
+
bottom: 100px;
|
|
11
|
+
left: 50%;
|
|
12
|
+
transform: translateX(-50%);
|
|
13
|
+
width: 90%;
|
|
14
|
+
max-width: 700px;
|
|
12
15
|
display: flex;
|
|
13
16
|
flex-direction: row;
|
|
14
17
|
justify-content: center;
|
|
15
18
|
align-items: center;
|
|
16
|
-
|
|
19
|
+
padding: 0 20px;
|
|
20
|
+
background: #222;
|
|
21
|
+
border-radius: 10px;
|
|
22
|
+
border: 2px solid rgb(108, 108, 246);
|
|
17
23
|
}
|
|
18
|
-
#
|
|
19
|
-
width:
|
|
24
|
+
#auto-component input {
|
|
25
|
+
width: 100%;
|
|
20
26
|
height: 40px;
|
|
21
27
|
border-radius: 5px;
|
|
22
28
|
color: #444;
|
|
@@ -24,7 +30,7 @@
|
|
|
24
30
|
border: 3px solid #ddd;
|
|
25
31
|
padding-left: 10px;
|
|
26
32
|
}
|
|
27
|
-
#
|
|
33
|
+
#auto-component button {
|
|
28
34
|
padding: 10px;
|
|
29
35
|
margin: 20px;
|
|
30
36
|
background: rgb(184, 230, 184);
|
|
@@ -32,29 +38,36 @@
|
|
|
32
38
|
border-radius: 5px;
|
|
33
39
|
box-shadow: 0px 0px 5px #fff;
|
|
34
40
|
}
|
|
35
|
-
#
|
|
41
|
+
#auto-component button:nth-child(3) {
|
|
36
42
|
padding: 10px 20px;
|
|
37
43
|
margin-left: 0px;
|
|
38
44
|
margin-right: 0px;
|
|
39
45
|
background: #db9d9d;
|
|
40
46
|
}
|
|
41
|
-
#
|
|
47
|
+
#auto-component button:hover {
|
|
42
48
|
background: green;
|
|
43
49
|
color: #eee;
|
|
44
50
|
}
|
|
45
|
-
#
|
|
51
|
+
#auto-component button:nth-child(3):hover {
|
|
46
52
|
background: #dc3c3c;
|
|
47
53
|
}
|
|
48
|
-
#
|
|
54
|
+
#auto-component-tabs {
|
|
55
|
+
position: fixed;
|
|
56
|
+
bottom: 68px;
|
|
57
|
+
left: 50%;
|
|
58
|
+
transform: translateX(-50%);
|
|
49
59
|
display: flex;
|
|
50
|
-
flex-direction:
|
|
60
|
+
flex-direction: row;
|
|
61
|
+
width: 100%;
|
|
62
|
+
max-width: 700px;
|
|
51
63
|
}
|
|
52
64
|
.tab {
|
|
65
|
+
width: 30%;
|
|
53
66
|
margin: 0 10%;
|
|
54
67
|
padding: 4px 0;
|
|
55
|
-
background: #
|
|
56
|
-
color: #
|
|
57
|
-
border-radius: 5px 5px
|
|
68
|
+
background: #c6c7d3;
|
|
69
|
+
color: #fff;
|
|
70
|
+
border-radius: 0 0 5px 5px;
|
|
58
71
|
cursor: pointer;
|
|
59
72
|
}
|
|
60
73
|
.tab:hover {
|
|
@@ -62,17 +75,20 @@
|
|
|
62
75
|
color: #eee;
|
|
63
76
|
}
|
|
64
77
|
.selected {
|
|
65
|
-
background: #
|
|
66
|
-
color: #
|
|
78
|
+
background: #444;
|
|
79
|
+
color: #aaa;
|
|
67
80
|
font-size: 1.2rem;
|
|
68
|
-
pointer-events: none;
|
|
69
81
|
}
|
|
70
|
-
#
|
|
71
|
-
position:
|
|
82
|
+
#auto-component-code {
|
|
83
|
+
position: fixed;
|
|
84
|
+
bottom: 180px;
|
|
85
|
+
left: 50%;
|
|
86
|
+
transform: translateX(-50%);
|
|
72
87
|
text-align: left;
|
|
73
|
-
max-width:
|
|
74
|
-
|
|
75
|
-
max-height:
|
|
88
|
+
max-width: 600px;
|
|
89
|
+
width: 80%;
|
|
90
|
+
max-height: 300px;
|
|
91
|
+
min-height: 300px;
|
|
76
92
|
background: #cdd1d9;
|
|
77
93
|
color: #111;
|
|
78
94
|
padding: 40px 10px 40px 10px;
|
|
@@ -82,7 +98,7 @@
|
|
|
82
98
|
box-shadow: 0px 0px 5px #fff;
|
|
83
99
|
white-space: pre-wrap;
|
|
84
100
|
}
|
|
85
|
-
.copy
|
|
101
|
+
.auto-component-copy {
|
|
86
102
|
position: absolute;
|
|
87
103
|
top: 130px;
|
|
88
104
|
right: 7%;
|
|
@@ -95,6 +111,9 @@
|
|
|
95
111
|
color: #fff;
|
|
96
112
|
}
|
|
97
113
|
|
|
98
|
-
.copy
|
|
114
|
+
.auto-component-copy:hover {
|
|
99
115
|
background: #666;
|
|
116
|
+
}
|
|
117
|
+
.hidden {
|
|
118
|
+
display: none;
|
|
100
119
|
}
|
package/src/index.jsx
CHANGED
|
@@ -1,243 +1,66 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import '
|
|
1
|
+
import {useState, useEffect} from 'react'
|
|
2
|
+
import { Link } from 'react-router-dom'
|
|
3
|
+
import { getPeople } from '../../utilities/people-service'
|
|
4
|
+
import './People.css'
|
|
5
|
+
import NewPersonForm from './NewPersonForm'
|
|
6
|
+
import AutoComponent from '../../components/Componenter'
|
|
4
7
|
|
|
5
|
-
const
|
|
8
|
+
const People = () => {
|
|
9
|
+
const [isLoading, setIsLoading] = useState(true)
|
|
10
|
+
const [people, setPeople] = useState([])
|
|
6
11
|
|
|
7
|
-
//**-----------**/
|
|
8
|
-
// ** State ** //
|
|
9
|
-
//**---------**/
|
|
10
|
-
const [ currentHtml, setHtml ] = useState('')
|
|
11
|
-
const [ currentStyle, setStyles ] = useState('')
|
|
12
|
-
const [ currentRequest, setRequest ] = useState('')
|
|
13
|
-
const [ user, setUser ] = useState('')
|
|
14
|
-
|
|
15
|
-
const [ responseData, setResponseData ] = useState(null)
|
|
16
|
-
const [ requestData, setRequestData ] = useState(null)
|
|
17
|
-
|
|
18
|
-
const [ activeTab, setActiveTab ] = useState('request')
|
|
19
|
-
const [ history, setHistory ] = useState(["No History"])
|
|
20
|
-
|
|
21
|
-
//**-------------------------**/
|
|
22
|
-
// ** HTML/CSS Formatting ** //
|
|
23
|
-
//**-----------------------**/
|
|
24
|
-
// get the html/style for the current page and set state
|
|
25
|
-
const htmlContent = () => {
|
|
26
|
-
const body = document.querySelector('body')
|
|
27
|
-
const htmlContent = body ? body.innerHTML : ''
|
|
28
|
-
const cssStyles = document.documentElement.innerHTML
|
|
29
|
-
|
|
30
|
-
const cleanedHtml = cleanExclusions(htmlContent, exclusions)
|
|
31
|
-
const cleanedStyles = cleanStyles(cssStyles)
|
|
32
|
-
|
|
33
|
-
setHtml(cleanedHtml)
|
|
34
|
-
setStyles(cleanedStyles)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// format html for display (breaks/indentation)
|
|
38
|
-
// const formatHtml = (html) => {
|
|
39
|
-
// return beautify.html(html, {
|
|
40
|
-
// indent_size: 2,
|
|
41
|
-
// wrap_line_length: 80,
|
|
42
|
-
// max_preserve_newlines: 1,
|
|
43
|
-
// })
|
|
44
|
-
// }
|
|
45
|
-
|
|
46
|
-
// clean html of exclusions:
|
|
47
|
-
// if an element className includes 'exclude'
|
|
48
|
-
// (partial) the element wrapper remains, but contents removed
|
|
49
|
-
// OR, (full) the element and it's content are excluded from output
|
|
50
|
-
|
|
51
|
-
// partial exclusion
|
|
52
|
-
const cleanExclusions = (html) => {
|
|
53
|
-
const regexExcludeClass = /(<[^>]*\sclass\s*=\s*['"]([^'"]*exclude[^'"]*)['"][^>]*>)[\s\S]*?(<\/[^>]*>)/g;
|
|
54
|
-
const cleanedHtml = html.replace(regexExcludeClass, '$1$3');
|
|
55
|
-
const scriptIndex = cleanedHtml.lastIndexOf('<script');
|
|
56
|
-
|
|
57
|
-
// return formatHtml(cleanedHtml.substring(0, scriptIndex));
|
|
58
|
-
return cleanedHtml.substring(0, scriptIndex);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// full exclusion
|
|
62
|
-
// const cleanExclusionsFull = (html) => {
|
|
63
|
-
// const regexExcludeClass = /<[^>]*\sclass\s*=\s*['"]([^'"]*exclude[^'"]*)['"][^>]*>[\s\S]*?<\/[^>]*>/g
|
|
64
|
-
// const cleanedHtml = html.replace(regexExcludeClass, '')
|
|
65
|
-
// const scriptIndex = cleanedHtml.lastIndexOf('<script')
|
|
66
|
-
//
|
|
67
|
-
// return formatHtml(cleanedHtml.substring(0, scriptIndex))
|
|
68
|
-
// }
|
|
69
|
-
|
|
70
|
-
// exclude non <style> data and remove comments
|
|
71
|
-
const cleanStyles = (css) => {
|
|
72
|
-
const styleRegex = /<style\b[^>]*>(.*?)<\/style>/gs
|
|
73
|
-
const matches = css.match(styleRegex)
|
|
74
|
-
|
|
75
|
-
if (matches) {
|
|
76
|
-
const cleanedMatches = matches.map(match => match.replace(/\/\*[\s\S]*?\*\//g, ''))
|
|
77
|
-
return cleanedMatches
|
|
78
|
-
}
|
|
79
|
-
return null
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const randomUser = () => {
|
|
83
|
-
setUser(Math.floor(Math.random()*100000))
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
htmlContent()
|
|
88
|
-
randomUser()
|
|
89
|
-
}, [])
|
|
90
|
-
|
|
91
|
-
//**---------------------------**/
|
|
92
|
-
// ** API Requests/Response ** //
|
|
93
|
-
//**-------------------------**/
|
|
94
|
-
|
|
95
|
-
// TEMP FUNCTION FOR TESTING
|
|
96
|
-
// const sendRequest = (data) => {
|
|
97
|
-
// return(response)
|
|
98
|
-
// }
|
|
99
|
-
|
|
100
|
-
const sendRequest = async () => {
|
|
101
|
-
const url = "https://server-auto-component-46830ff262f8.herokuapp.com/api";
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
const res = await fetch(url, {
|
|
105
|
-
method: 'POST',
|
|
106
|
-
headers: {
|
|
107
|
-
'Content-Type': 'application/json',
|
|
108
|
-
},
|
|
109
|
-
body: JSON.stringify(requestData),
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
if (res.ok) {
|
|
113
|
-
const jsonData = await res.json();
|
|
114
|
-
return jsonData;
|
|
115
|
-
} else {
|
|
116
|
-
throw new Error("Invalid request!");
|
|
117
|
-
}
|
|
118
|
-
} catch (err) {
|
|
119
|
-
console.log(err.message);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// make API request with updated state data
|
|
124
12
|
const handleRequest = async () => {
|
|
125
13
|
try {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
if (resData) {
|
|
129
|
-
setHistory(resData.history)
|
|
130
|
-
// setResponseData(formatHtml(resData.response.content));
|
|
131
|
-
setResponseData(resData.response.content);
|
|
132
|
-
setActiveTab('response');
|
|
133
|
-
}
|
|
14
|
+
const peopleData = await getPeople()
|
|
15
|
+
if (peopleData) setPeople(peopleData)
|
|
134
16
|
} catch (err) {
|
|
135
|
-
console.log(err)
|
|
17
|
+
console.log(err)
|
|
136
18
|
}
|
|
137
|
-
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
//**------------------------**/
|
|
141
|
-
// ** UI/Button Handling ** //
|
|
142
|
-
//**----------------------**/
|
|
143
|
-
|
|
144
|
-
const handleChange = (e) => {
|
|
145
|
-
e.preventDefault()
|
|
146
|
-
setRequest(e.target.value)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const handleGenerate = async (e) => {
|
|
150
|
-
await setRequestData({
|
|
151
|
-
"userId": user,
|
|
152
|
-
"request": currentRequest,
|
|
153
|
-
"html": currentHtml
|
|
154
|
-
})
|
|
19
|
+
setIsLoading(false)
|
|
155
20
|
}
|
|
156
21
|
|
|
157
22
|
useEffect(() => {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
},[requestData])
|
|
162
|
-
|
|
163
|
-
const handleReset = () => {
|
|
164
|
-
setRequest('')
|
|
165
|
-
setResponseData('')
|
|
166
|
-
randomUser()
|
|
167
|
-
setHistory([])
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const handleRequestTab = () => {
|
|
171
|
-
setActiveTab('request')
|
|
172
|
-
}
|
|
173
|
-
const handleResponseTab = () => {
|
|
174
|
-
setActiveTab('response')
|
|
175
|
-
}
|
|
23
|
+
handleRequest()
|
|
24
|
+
}, [])
|
|
176
25
|
|
|
177
|
-
const copyToClipboard = async () => {
|
|
178
|
-
const text = activeTab === 'response' ? responseData : requestData
|
|
179
|
-
await navigator.clipboard.writeText(text)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
//**---------------**/
|
|
183
|
-
// ** Rendering ** //
|
|
184
|
-
//**-------------**/
|
|
185
26
|
|
|
186
|
-
|
|
27
|
+
if (isLoading) {
|
|
28
|
+
return <h1>Loading...</h1>;
|
|
29
|
+
} else {
|
|
187
30
|
return (
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
index !== 0 && entry.content.split('HTML Context:')[0] + (entry.content.includes("User Request") ? '\n' : '\n\n\n')
|
|
191
|
-
)
|
|
192
|
-
))
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const requestHTML = currentHtml ? (
|
|
196
|
-
`Review the details below for accuracy and privacy concerns.
|
|
197
|
-
If the contents of an element should be excluded, add the 'exclude' class to the element.
|
|
198
|
-
Click Generate to send the request and receive the auto component AI generated code.
|
|
199
|
-
|
|
200
|
-
User ID:\n `
|
|
201
|
-
+ user
|
|
202
|
-
+ "\n\nUser Request:\n"
|
|
203
|
-
+ currentRequest
|
|
204
|
-
+ "\n\nUser HTML:\n"
|
|
205
|
-
+ currentHtml
|
|
206
|
-
) : 'There was an error collecting your HTML. Ensure no top level elements are assigned the class "exclude"'
|
|
207
|
-
|
|
208
|
-
const responseHtml = responseData ? (
|
|
209
|
-
responseData
|
|
210
|
-
) : 'No response has been generated'
|
|
31
|
+
<section>
|
|
32
|
+
{/* <NewPersonForm handleRequest={handleRequest} /> */}
|
|
211
33
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
<div id="content-creator">
|
|
217
|
-
<div>
|
|
218
|
-
<input type="text" value={currentRequest} onChange={handleChange} placeholder="Enter a request"></input>
|
|
219
|
-
<button onClick={handleGenerate}>Generate</button>
|
|
220
|
-
<button onClick={handleReset}>X</button>
|
|
221
|
-
</div>
|
|
222
|
-
<div>
|
|
223
|
-
<div>
|
|
224
|
-
<div className={`${activeTab === 'request' ? 'selected' : ''} tab`} onClick={handleRequestTab}>
|
|
225
|
-
Request
|
|
226
|
-
</div>
|
|
227
|
-
<div className={`${activeTab === 'response' ? 'selected' : ''} tab`} onClick={handleResponseTab}>
|
|
228
|
-
Response
|
|
229
|
-
</div>
|
|
34
|
+
<div id="secret-element" className='secret secret-element'>
|
|
35
|
+
this is the excluded text
|
|
36
|
+
<div className='something'>
|
|
37
|
+
and this is the excluded element
|
|
230
38
|
</div>
|
|
231
|
-
<pre>
|
|
232
|
-
{activeTab === 'request' ? getLog() : responseHtml}
|
|
233
|
-
</pre>
|
|
234
39
|
</div>
|
|
235
|
-
|
|
236
|
-
|
|
40
|
+
|
|
41
|
+
<div id="not-secret-element" className=''>
|
|
42
|
+
included
|
|
237
43
|
</div>
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
44
|
+
|
|
45
|
+
<div className="people-list">
|
|
46
|
+
{people.map((p) => (
|
|
47
|
+
<Link to={"/people/" + p._id}>
|
|
48
|
+
<div key={p._id}>
|
|
49
|
+
<h3>{p.name}</h3>
|
|
50
|
+
<img
|
|
51
|
+
className="profile-image"
|
|
52
|
+
src={p.image}
|
|
53
|
+
alt={`Image of ${p.name}`}
|
|
54
|
+
/>
|
|
55
|
+
<p>{p.title}</p>
|
|
56
|
+
</div>
|
|
57
|
+
</Link>
|
|
58
|
+
))}
|
|
59
|
+
</div>
|
|
60
|
+
<AutoComponent />
|
|
61
|
+
</section>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
241
64
|
}
|
|
242
65
|
|
|
243
|
-
export default
|
|
66
|
+
export default People
|