auto-component 0.0.36 → 0.0.38

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,10 +1,11 @@
1
1
  {
2
2
  "name": "auto-component",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "main": "src/index.jsx",
5
5
  "peerDependencies": {
6
6
  "react": "^18.2.0",
7
- "react-dom": "*"
7
+ "react-dom": "*",
8
+ "react-jsx-parser": "^1.29.0"
8
9
  },
9
10
  "files": [
10
11
  "src"
@@ -1,22 +1,31 @@
1
- #auto-component {
1
+ #auto-component-ui {
2
2
  position: relative;
3
3
  width: 100%;
4
4
  display: flex;
5
5
  flex-direction: column;
6
6
  align-items: center;
7
- margin: 40px 0;
8
- font-family: Arial, Helvetica, sans-serif
7
+ font-family: Arial, Helvetica, sans-serif;
8
+ z-index: 9999;
9
9
  }
10
- #auto-component div {
11
- width: 100%;
10
+ #auto-component-entry {
11
+ position: fixed;
12
+ bottom: 100px;
13
+ left: 50%;
14
+ transform: translateX(-50%);
15
+ width: 90%;
16
+ max-width: 700px;
12
17
  display: flex;
13
18
  flex-direction: row;
14
19
  justify-content: center;
15
20
  align-items: center;
16
-
21
+ padding: 0 20px;
22
+ background: #222;
23
+ border-radius: 10px;
24
+ border: 2px solid rgb(108, 108, 246);
25
+ z-index: 9999;
17
26
  }
18
- #auto-component input {
19
- width: 60%;
27
+ #auto-component-ui input {
28
+ width: 100%;
20
29
  height: 40px;
21
30
  border-radius: 5px;
22
31
  color: #444;
@@ -24,7 +33,7 @@
24
33
  border: 3px solid #ddd;
25
34
  padding-left: 10px;
26
35
  }
27
- #auto-component button {
36
+ #auto-component-ui button {
28
37
  padding: 10px;
29
38
  margin: 20px;
30
39
  background: rgb(184, 230, 184);
@@ -32,69 +41,99 @@
32
41
  border-radius: 5px;
33
42
  box-shadow: 0px 0px 5px #fff;
34
43
  }
35
- #auto-component button:nth-child(3) {
44
+ #auto-component-ui button:nth-child(3) {
36
45
  padding: 10px 20px;
37
46
  margin-left: 0px;
38
47
  margin-right: 0px;
39
48
  background: #db9d9d;
40
49
  }
41
- #auto-component button:hover {
50
+ #auto-component-ui button:hover {
42
51
  background: green;
43
52
  color: #eee;
44
53
  }
45
- #auto-component button:nth-child(3):hover {
54
+ #auto-component-ui button:nth-child(3):hover {
46
55
  background: #dc3c3c;
47
56
  }
48
- #auto-component div:nth-child(2) {
57
+ #auto-component-tabs {
58
+ position: fixed;
59
+ bottom: 68px;
60
+ left: 50%;
61
+ transform: translateX(-50%);
49
62
  display: flex;
50
- flex-direction: column;
63
+ flex-direction: row;
64
+ justify-content: center;
65
+ text-align: center;
66
+ width: 100%;
67
+ max-width: 700px;
68
+ z-index: 9998;
51
69
  }
52
70
  .tab {
71
+ width: 30%;
53
72
  margin: 0 10%;
54
73
  padding: 4px 0;
55
- background: #444;
56
- color: #aaa;
57
- border-radius: 5px 5px 0 0;
74
+ background: #c6c7d3 !important;
75
+ color: #fff !important;
76
+ border-radius: 0 0 5px 5px;
58
77
  cursor: pointer;
59
78
  }
60
79
  .tab:hover {
61
- background: #666;
62
- color: #eee;
80
+ background: #666 !important;
81
+ color: #eee !important;
63
82
  }
64
- .selected {
65
- background: #c6c7d3;
66
- color: #fff;
83
+ .auto-component-selected {
84
+ background: #444 !important;
85
+ color: #aaa !important;
67
86
  font-size: 1.2rem;
68
- pointer-events: none;
69
87
  }
70
- #auto-component pre {
71
- position: relative;
88
+ #auto-component-code-container {
89
+ position: fixed;
90
+ bottom: 180px;
91
+ left: 50%;
92
+ transform: translateX(-50%);
93
+ width: 80%;
94
+ max-width: 600px;
95
+ max-height: 300px;
96
+ height: 300px;
97
+ }
98
+
99
+ #auto-component-code {
100
+ width: 100%;
101
+ max-width: 600px;
102
+ max-height: 300px;
103
+ height: 300px;
72
104
  text-align: left;
73
- max-width: 90%;
74
- min-width: 90%;
75
- max-height: 60vh;
76
105
  background: #cdd1d9;
77
106
  color: #111;
78
107
  padding: 40px 10px 40px 10px;
79
- overflow: auto;
108
+ overflow-y: auto;
80
109
  border: 2px solid black;
81
110
  border-radius: 10px;
82
111
  box-shadow: 0px 0px 5px #fff;
83
- white-space: pre-wrap;
112
+ white-space: pre-wrap !important;
113
+ word-wrap: break-word !important;
114
+ z-index: 9999;
84
115
  }
85
- .copy-btn {
116
+ .auto-component-copy {
86
117
  position: absolute;
87
- top: 130px;
88
- right: 7%;
118
+ top: 2px;
119
+ right: 2px;
120
+ display: flex;
121
+ justify-content: center;
122
+ align-items: center;
123
+ background: red;
89
124
  max-width: 50px;
90
125
  max-height: 30px;
91
126
  cursor: pointer;
92
127
  background: rgba(0, 0, 0, 0.2);
93
- border-radius: 5px;
128
+ border-radius: 0 8px 0 8px;
94
129
  padding: 10px 20px;
95
130
  color: #fff;
131
+ z-index: 9999;
96
132
  }
97
133
 
98
- .copy-btn:hover {
134
+ .auto-component-copy:hover {
99
135
  background: #666;
136
+ }
137
+ .auto-component-hidden {
138
+ display: none;
100
139
  }
package/src/index.jsx CHANGED
@@ -1,8 +1,11 @@
1
+ /* eslint-disable no-unused-vars */
2
+ /* eslint-disable react-hooks/exhaustive-deps */
3
+ import JSXParser from 'react-jsx-parser'
1
4
  import { useState, useEffect } from 'react'
2
5
  // import beautify from 'js-beautify';
3
6
  import './auto-component.css'
4
7
 
5
- const AutoComponent = ({ exclusions }) => {
8
+ const AutoComponent = () => {
6
9
 
7
10
  //**-----------**/
8
11
  // ** State ** //
@@ -12,10 +15,10 @@ const AutoComponent = ({ exclusions }) => {
12
15
  const [ currentRequest, setRequest ] = useState('')
13
16
  const [ user, setUser ] = useState('')
14
17
 
15
- const [ responseData, setResponseData ] = useState(null)
18
+ const [ responseData, setResponseData ] = useState('')
16
19
  const [ requestData, setRequestData ] = useState(null)
17
20
 
18
- const [ activeTab, setActiveTab ] = useState('request')
21
+ const [ activeTab, setActiveTab ] = useState('')
19
22
  const [ history, setHistory ] = useState(["No History"])
20
23
 
21
24
  //**-------------------------**/
@@ -27,7 +30,7 @@ const AutoComponent = ({ exclusions }) => {
27
30
  const htmlContent = body ? body.innerHTML : ''
28
31
  const cssStyles = document.documentElement.innerHTML
29
32
 
30
- const cleanedHtml = cleanExclusions(htmlContent, exclusions)
33
+ const cleanedHtml = cleanExclusions(htmlContent)
31
34
  const cleanedStyles = cleanStyles(cssStyles)
32
35
 
33
36
  setHtml(cleanedHtml)
@@ -49,23 +52,44 @@ const AutoComponent = ({ exclusions }) => {
49
52
  // OR, (full) the element and it's content are excluded from output
50
53
 
51
54
  // 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
55
 
57
- // return formatHtml(cleanedHtml.substring(0, scriptIndex));
58
- return cleanedHtml.substring(0, scriptIndex);
56
+ const cleanExclusions = (html) => {
57
+ const parser = new DOMParser();
58
+ const doc = parser.parseFromString(html, 'text/html');
59
+
60
+ const elementsToClean = doc.querySelectorAll('.exclude');
61
+
62
+ elementsToClean.forEach((element) => {
63
+ removeAllChildNodes(element);
64
+ });
65
+
66
+ return doc.documentElement.outerHTML;
67
+ };
68
+
69
+ const removeAllChildNodes = (element) => {
70
+ Array.from(element.childNodes).forEach((child) => {
71
+ if (child.nodeType === Node.ELEMENT_NODE) {
72
+ removeAllChildNodes(child);
73
+ } else {
74
+ element.removeChild(child);
75
+ }
76
+ });
59
77
  };
78
+
60
79
 
61
80
  // 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
- // }
81
+ // const cleanExclusions = (html) => {
82
+ // const parser = new DOMParser();
83
+ // const doc = parser.parseFromString(html, 'text/html');
84
+ //
85
+ // const elementsToExclude = doc.querySelectorAll('.exclude');
86
+ //
87
+ // elementsToExclude.forEach((element) => {
88
+ // element.parentNode.removeChild(element);
89
+ // });
90
+ //
91
+ // return doc.documentElement.outerHTML;
92
+ // };
69
93
 
70
94
  // exclude non <style> data and remove comments
71
95
  const cleanStyles = (css) => {
@@ -99,7 +123,7 @@ const AutoComponent = ({ exclusions }) => {
99
123
 
100
124
  const sendRequest = async () => {
101
125
  const url = "https://server-auto-component-46830ff262f8.herokuapp.com/api";
102
-
126
+
103
127
  try {
104
128
  const res = await fetch(url, {
105
129
  method: 'POST',
@@ -119,6 +143,19 @@ const AutoComponent = ({ exclusions }) => {
119
143
  console.log(err.message);
120
144
  }
121
145
  };
146
+
147
+ const cleanId = (html) => {
148
+ const parser = new DOMParser();
149
+ const doc = parser.parseFromString(html, 'text/html');
150
+
151
+ const autoComponentContainer = doc.getElementById('auto-component-container');
152
+
153
+ if (autoComponentContainer) {
154
+ autoComponentContainer.removeAttribute('id');
155
+ }
156
+
157
+ return doc.documentElement.outerHTML;
158
+ };
122
159
 
123
160
  // make API request with updated state data
124
161
  const handleRequest = async () => {
@@ -128,6 +165,7 @@ const AutoComponent = ({ exclusions }) => {
128
165
  if (resData) {
129
166
  setHistory(resData.history)
130
167
  // setResponseData(formatHtml(resData.response.content));
168
+ // const outputHtml = cleanId(resData.response.content)
131
169
  setResponseData(resData.response.content);
132
170
  setActiveTab('response');
133
171
  }
@@ -167,11 +205,12 @@ const AutoComponent = ({ exclusions }) => {
167
205
  setHistory([])
168
206
  }
169
207
 
170
- const handleRequestTab = () => {
171
- setActiveTab('request')
208
+ const handleRequestTab = async () => {
209
+ await setActiveTab(activeTab === 'response' || activeTab === '' ? 'request' : '');
172
210
  }
173
- const handleResponseTab = () => {
174
- setActiveTab('response')
211
+
212
+ const handleResponseTab = async () => {
213
+ await setActiveTab(activeTab === 'request' || activeTab === '' ? 'response' : '');
175
214
  }
176
215
 
177
216
  const copyToClipboard = async () => {
@@ -193,6 +232,7 @@ const AutoComponent = ({ exclusions }) => {
193
232
  }
194
233
 
195
234
  const requestHTML = currentHtml ? (
235
+ getLog() +
196
236
  `Review the details below for accuracy and privacy concerns.
197
237
  If the contents of an element should be excluded, add the 'exclude' class to the element.
198
238
  Click Generate to send the request and receive the auto component AI generated code.
@@ -205,39 +245,53 @@ User ID:\n `
205
245
  + currentHtml
206
246
  ) : 'There was an error collecting your HTML. Ensure no top level elements are assigned the class "exclude"'
207
247
 
208
- const responseHtml = responseData ? (
248
+
249
+ console.log(responseData)
250
+ const responseHtml = responseData ? (
209
251
  responseData
210
252
  ) : 'No response has been generated'
211
-
212
-
253
+
213
254
  return (
214
- <>
215
- {/* create the display window */}
216
- <div id="auto-component">
217
- <div>
255
+
256
+ <div className='auto-component exclude'>
257
+
258
+ <div>
259
+ {responseData ? (
260
+ // Use {} to directly interpolate the JSX code
261
+ <JSXParser jsx={responseData} />
262
+ ) : (
263
+ '- auto component will be added here -'
264
+ )}
265
+ </div>
266
+
267
+ <div id="auto-component-ui">
268
+ <div id="auto-component-code-container" className={`${!activeTab ? 'auto-component-hidden' : ''} auto-component-code`}>
269
+ <pre id="auto-component-code">
270
+ {activeTab === 'request' ? requestHTML : responseHtml}
271
+ </pre>
272
+ <div className="auto-component-copy" onClick={copyToClipboard} style={activeTab !== 'response' ? { display: 'none' } : null}>
273
+ copy
274
+ </div>
275
+ </div>
276
+ <div id="auto-component-entry">
218
277
  <input type="text" value={currentRequest} onChange={handleChange} placeholder="Enter a request"></input>
219
278
  <button onClick={handleGenerate}>Generate</button>
220
279
  <button onClick={handleReset}>X</button>
221
280
  </div>
222
281
  <div>
223
- <div>
224
- <div className={`${activeTab === 'request' ? 'selected' : ''} tab`} onClick={handleRequestTab}>
282
+ <div id='auto-component-tabs'>
283
+ <div className={`${activeTab === 'request' ? 'auto-component-selected' : ''} tab`} onClick={handleRequestTab}>
225
284
  Request
226
285
  </div>
227
- <div className={`${activeTab === 'response' ? 'selected' : ''} tab`} onClick={handleResponseTab}>
286
+ <div className={`${activeTab === 'response' ? 'auto-component-selected' : ''} tab`} onClick={handleResponseTab}>
228
287
  Response
229
288
  </div>
230
289
  </div>
231
- <pre>
232
- {activeTab === 'request' ? getLog() : responseHtml}
233
- </pre>
234
- </div>
235
- <div className="copy-btn" onClick={copyToClipboard} style={activeTab !== 'response' ? { display: 'none' } : null}>
236
- copy
237
290
  </div>
238
291
  </div>
239
- </>
292
+ </div>
240
293
  )
241
294
  }
242
295
 
243
296
  export default AutoComponent
297
+