auto-component 0.0.44 → 0.1.0

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.
@@ -13,7 +13,7 @@
13
13
  left: 50%;
14
14
  transform: translateX(-50%);
15
15
  width: 90%;
16
- max-width: 700px;
16
+ max-width: 1000px;
17
17
  display: flex;
18
18
  flex-direction: row;
19
19
  justify-content: center;
@@ -64,7 +64,7 @@
64
64
  justify-content: center;
65
65
  text-align: center;
66
66
  width: 100%;
67
- max-width: 700px;
67
+ max-width: 1000px;
68
68
  z-index: 9998;
69
69
  }
70
70
  .tab {
@@ -91,14 +91,14 @@
91
91
  left: 50%;
92
92
  transform: translateX(-50%);
93
93
  width: 80%;
94
- max-width: 600px;
94
+ max-width: 900px;
95
95
  max-height: 300px;
96
96
  height: 300px;
97
97
  }
98
98
 
99
99
  #auto-component-code {
100
100
  width: 100%;
101
- max-width: 600px;
101
+ max-width: 900px;
102
102
  max-height: 300px;
103
103
  height: 300px;
104
104
  text-align: left;
package/lib/index.js CHANGED
@@ -20,7 +20,11 @@ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructur
20
20
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
21
21
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
22
22
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
23
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /* eslint-disable no-unused-vars */ /* eslint-disable react-hooks/exhaustive-deps */
23
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // AutoComponent
24
+ // Built By:
25
+ // https://github.com/SamPatt
26
+ // https://github.com/TimHuitt
27
+ /* eslint-disable no-unused-vars */ /* eslint-disable react-hooks/exhaustive-deps */ // Helpful in Babel transpile: https://github.com/receter/my-components
24
28
  var AutoComponent = function AutoComponent() {
25
29
  //**-----------**/
26
30
  // ** State ** //
@@ -81,45 +85,42 @@ var AutoComponent = function AutoComponent() {
81
85
  });
82
86
  };
83
87
 
84
- // clean html of exclusions:
88
+ // ** Clean HTML of Exclusions **
85
89
  // if an element className includes 'exclude'
86
90
  // (partial) the element wrapper remains, but contents removed
87
91
  // OR, (full) the element and it's content are excluded from output
92
+ // thanks gpt for these clever exclusion tools
88
93
 
89
94
  // partial exclusion
90
-
91
95
  var cleanExclusions = function cleanExclusions(html) {
92
96
  var parser = new DOMParser();
93
97
  var doc = parser.parseFromString(html, 'text/html');
94
98
  var elementsToClean = doc.querySelectorAll('.exclude');
99
+ var removeAllChildNodes = function removeAllChildNodes(element) {
100
+ Array.from(element.childNodes).forEach(function (child) {
101
+ if (child.nodeType === Node.ELEMENT_NODE) {
102
+ removeAllChildNodes(child);
103
+ } else {
104
+ element.removeChild(child);
105
+ }
106
+ });
107
+ };
95
108
  elementsToClean.forEach(function (element) {
96
109
  removeAllChildNodes(element);
97
110
  });
98
111
  return doc.documentElement.outerHTML;
99
112
  };
100
- var removeAllChildNodes = function removeAllChildNodes(element) {
101
- Array.from(element.childNodes).forEach(function (child) {
102
- if (child.nodeType === Node.ELEMENT_NODE) {
103
- removeAllChildNodes(child);
104
- } else {
105
- element.removeChild(child);
106
- }
107
- });
108
- };
109
113
 
110
114
  // full exclusion
111
- // const cleanExclusions = (html) => {
112
- // const parser = new DOMParser();
113
- // const doc = parser.parseFromString(html, 'text/html');
114
- //
115
- // const elementsToExclude = doc.querySelectorAll('.exclude');
116
- //
117
- // elementsToExclude.forEach((element) => {
118
- // element.parentNode.removeChild(element);
119
- // });
120
- //
121
- // return doc.documentElement.outerHTML;
122
- // };
115
+ var cleanExclusionsFull = function cleanExclusionsFull(html) {
116
+ var parser = new DOMParser();
117
+ var doc = parser.parseFromString(html, 'text/html');
118
+ var elementsToExclude = doc.querySelectorAll('.exclude');
119
+ elementsToExclude.forEach(function (element) {
120
+ element.parentNode.removeChild(element);
121
+ });
122
+ return doc.documentElement.outerHTML;
123
+ };
123
124
 
124
125
  // exclude non <style> data and remove comments
125
126
  var cleanStyles = function cleanStyles(css) {
@@ -133,9 +134,13 @@ var AutoComponent = function AutoComponent() {
133
134
  }
134
135
  return null;
135
136
  };
137
+
138
+ // generate a random 5 digit user id
136
139
  var randomUser = function randomUser() {
137
140
  setUser(Math.floor(Math.random() * 100000));
138
141
  };
142
+
143
+ // set initial load data
139
144
  (0, _react.useEffect)(function () {
140
145
  htmlContent();
141
146
  randomUser();
@@ -145,11 +150,8 @@ var AutoComponent = function AutoComponent() {
145
150
  // ** API Requests/Response ** //
146
151
  //**-------------------------**/
147
152
 
148
- // TEMP FUNCTION FOR TESTING
149
- // const sendRequest = (data) => {
150
- // return(response)
151
- // }
152
-
153
+ // handle sending the user request to the auto-component API
154
+ // API sends packaged request to GPT for a code based response
153
155
  var sendRequest = /*#__PURE__*/function () {
154
156
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
155
157
  var url, res, jsonData;
@@ -197,7 +199,7 @@ var AutoComponent = function AutoComponent() {
197
199
  };
198
200
  }();
199
201
 
200
- // make API request with updated state data
202
+ // handle request initialization and state updates
201
203
  var handleRequest = /*#__PURE__*/function () {
202
204
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
203
205
  var resData;
@@ -212,7 +214,7 @@ var AutoComponent = function AutoComponent() {
212
214
  if (resData) {
213
215
  setHistory(resData.history);
214
216
  setResponseData(formatHtml(resData.response.content));
215
- setActiveTab('response');
217
+ activeTab !== '' && setActiveTab('response');
216
218
  }
217
219
  _context2.next = 10;
218
220
  break;
@@ -251,6 +253,8 @@ var AutoComponent = function AutoComponent() {
251
253
  "html": currentHtml
252
254
  });
253
255
  case 2:
256
+ setRequest('');
257
+ case 3:
254
258
  case "end":
255
259
  return _context3.stop();
256
260
  }
@@ -329,20 +333,30 @@ var AutoComponent = function AutoComponent() {
329
333
  // ** Rendering ** //
330
334
  //**-------------**/
331
335
 
336
+ // get request history log and format for display
332
337
  var getLog = function getLog() {
333
338
  return history.map(function (entry, index) {
334
- return index !== 0 && entry.content.split('HTML Context:')[0] + (entry.content.includes("User Request") ? '\n' : '\n\n\n');
339
+ return index !== 0 ? entry.content.split('HTML Context:')[0] + (entry.content.includes("User Request") ? '\n\n' : '\n\n\n') : '';
335
340
  });
336
341
  };
337
- var requestHTML = currentHtml ? getLog() + "Review the details below for accuracy and privacy concerns.\nIf the contents of an element should be excluded, add the 'exclude' class to the element.\nClick Generate to send the request and receive the auto component AI generated code.\n\nUser ID:\n " + user + "\n\nUser Request:\n" + currentRequest + "\n\nUser HTML:\n" + currentHtml : 'There was an error collecting your HTML. Ensure no top level elements are assigned the class "exclude"';
338
- console.log(responseData);
342
+
343
+ // build request tab content
344
+ var requestHTML = currentHtml ? getLog() && getLog().join('') + "Review the details below for accuracy and privacy concerns.\n\nIf the contents of an element should be excluded, add the 'exclude' class to the element.\n\nClick Generate to send a request and receive the auto component AI generated code.\n\nUser ID:\n" + user + "\n\nUser Request:\n" + currentRequest + "\n\nUser HTML:\n" + currentHtml : 'There was an error collecting your HTML. Ensure no top level elements are assigned the class "exclude"';
339
345
  var responseHtml = responseData ? responseData : 'No response has been generated';
346
+ var handleKeyDown = function handleKeyDown(e) {
347
+ if (e.key === 'Enter') {
348
+ e.preventDefault();
349
+ handleGenerate();
350
+ }
351
+ };
352
+
353
+ //**------------**/
354
+ // ** Return ** //
355
+ //**----------**/
356
+
340
357
  return /*#__PURE__*/_react["default"].createElement("div", {
341
358
  className: "auto-component exclude"
342
- }, /*#__PURE__*/_react["default"].createElement("div", null, responseData ?
343
- /*#__PURE__*/
344
- // Use {} to directly interpolate the JSX code
345
- _react["default"].createElement(_reactJsxParser["default"], {
359
+ }, /*#__PURE__*/_react["default"].createElement("div", null, responseData ? /*#__PURE__*/_react["default"].createElement(_reactJsxParser["default"], {
346
360
  jsx: responseData
347
361
  }) : '- auto component will be added here -'), /*#__PURE__*/_react["default"].createElement("div", {
348
362
  id: "auto-component-ui"
@@ -363,6 +377,7 @@ var AutoComponent = function AutoComponent() {
363
377
  type: "text",
364
378
  value: currentRequest,
365
379
  onChange: handleChange,
380
+ onKeyDown: handleKeyDown,
366
381
  placeholder: "Enter a request"
367
382
  }), /*#__PURE__*/_react["default"].createElement("button", {
368
383
  onClick: handleGenerate
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-component",
3
- "version": "0.0.44",
3
+ "version": "0.1.0",
4
4
  "main": "lib/index.js",
5
5
  "peerDependencies": {
6
6
  "react": "^18.2.0",