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