auto-component 1.0.0 → 1.0.2

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.
Files changed (3) hide show
  1. package/README.md +5 -0
  2. package/lib/index.js +47 -159
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/auto-component.svg)](https://www.npmjs.com/package/auto-component)
4
4
 
5
+ [![github repo](https://img.shields.io/badge/Repo%20-%20GitHub?style=flat&logo=github&link=https%3A%2F%2Fgithub.com%2FTimHuitt%2Fclient-auto-component)](https://github.com/TimHuitt/client-auto-component)
6
+
7
+ [![official website](https://img.shields.io/badge/demo-37c637?style=flat&logo=react&logoColor=white&label=docs
8
+ )](https://auto-component.com)
9
+
5
10
  > A tool to streamline UI element creation in React projects through AI prompted generation
6
11
 
7
12
  ## Technologies Used
package/lib/index.js CHANGED
@@ -24,7 +24,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // AutoCom
24
24
  // Built By:
25
25
  // https://github.com/SamPatt
26
26
  // https://github.com/TimHuitt
27
- // Copyright (C) <year> <name of author>
27
+ // Copyright (C) 2023 Tim Huitt, Sam Patterson
28
28
  //
29
29
  // This program is free software: you can redistribute it and/or modify
30
30
  // it under the terms of the GNU Affero General Public License as
@@ -49,54 +49,36 @@ var AutoComponent = function AutoComponent() {
49
49
  setHtml = _useState2[1];
50
50
  var _useState3 = (0, _react.useState)(''),
51
51
  _useState4 = _slicedToArray(_useState3, 2),
52
- currentStyle = _useState4[0],
53
- setStyles = _useState4[1];
52
+ currentRequest = _useState4[0],
53
+ setRequest = _useState4[1];
54
54
  var _useState5 = (0, _react.useState)(''),
55
55
  _useState6 = _slicedToArray(_useState5, 2),
56
- currentRequest = _useState6[0],
57
- setRequest = _useState6[1];
56
+ user = _useState6[0],
57
+ setUser = _useState6[1];
58
58
  var _useState7 = (0, _react.useState)(''),
59
59
  _useState8 = _slicedToArray(_useState7, 2),
60
- user = _useState8[0],
61
- setUser = _useState8[1];
62
- var _useState9 = (0, _react.useState)(''),
60
+ responseData = _useState8[0],
61
+ setResponseData = _useState8[1];
62
+ var _useState9 = (0, _react.useState)(null),
63
63
  _useState10 = _slicedToArray(_useState9, 2),
64
- userID = _useState10[0],
65
- setUserID = _useState10[1];
64
+ requestData = _useState10[0],
65
+ setRequestData = _useState10[1];
66
66
  var _useState11 = (0, _react.useState)(''),
67
67
  _useState12 = _slicedToArray(_useState11, 2),
68
- responseData = _useState12[0],
69
- setResponseData = _useState12[1];
70
- var _useState13 = (0, _react.useState)(null),
68
+ activeTab = _useState12[0],
69
+ setActiveTab = _useState12[1];
70
+ var _useState13 = (0, _react.useState)(["No History"]),
71
71
  _useState14 = _slicedToArray(_useState13, 2),
72
- requestData = _useState14[0],
73
- setRequestData = _useState14[1];
74
- var _useState15 = (0, _react.useState)(''),
72
+ history = _useState14[0],
73
+ setHistory = _useState14[1];
74
+ var _useState15 = (0, _react.useState)(false),
75
75
  _useState16 = _slicedToArray(_useState15, 2),
76
- activeTab = _useState16[0],
77
- setActiveTab = _useState16[1];
78
- var _useState17 = (0, _react.useState)(["No History"]),
79
- _useState18 = _slicedToArray(_useState17, 2),
80
- history = _useState18[0],
81
- setHistory = _useState18[1];
82
- var _useState19 = (0, _react.useState)(false),
83
- _useState20 = _slicedToArray(_useState19, 2),
84
- isRequesting = _useState20[0],
85
- setIsRequesting = _useState20[1];
76
+ isRequesting = _useState16[0],
77
+ setIsRequesting = _useState16[1];
86
78
 
87
79
  //**-------------------------**/
88
80
  // ** HTML/CSS Formatting ** //
89
81
  //**-----------------------**/
90
- // get the html/style for the current page and set state
91
- var htmlContent = function htmlContent() {
92
- var body = document.querySelector('body');
93
- var htmlContent = body ? body.innerHTML : '';
94
- var cssStyles = document.documentElement.innerHTML;
95
- var cleanedHtml = cleanExclusions(htmlContent);
96
- var cleanedStyles = cleanStyles(cssStyles);
97
- setHtml(formatHtml(cleanedHtml));
98
- setStyles(cleanedStyles);
99
- };
100
82
 
101
83
  // format html for display (breaks/indentation)
102
84
  var formatHtml = function formatHtml(html) {
@@ -133,30 +115,6 @@ var AutoComponent = function AutoComponent() {
133
115
  return doc.documentElement.outerHTML;
134
116
  };
135
117
 
136
- // full exclusion
137
- var cleanExclusionsFull = function cleanExclusionsFull(html) {
138
- var parser = new DOMParser();
139
- var doc = parser.parseFromString(html, 'text/html');
140
- var elementsToExclude = doc.querySelectorAll('.exclude');
141
- elementsToExclude.forEach(function (element) {
142
- element.parentNode.removeChild(element);
143
- });
144
- return doc.documentElement.outerHTML;
145
- };
146
-
147
- // exclude non <style> data and remove comments
148
- var cleanStyles = function cleanStyles(css) {
149
- var styleRegex = /<style\b[^>]*>([\s\S]*?)<\/style>/g;
150
- var matches = css.match(styleRegex);
151
- if (matches) {
152
- var cleanedMatches = matches.map(function (match) {
153
- return match.replace(/\/\*[\s\S]*?\*\//g, '');
154
- });
155
- return cleanedMatches;
156
- }
157
- return null;
158
- };
159
-
160
118
  // generate a random 5 digit user id
161
119
  var randomUser = function randomUser() {
162
120
  setUser(Math.floor(Math.random() * 100000));
@@ -164,7 +122,6 @@ var AutoComponent = function AutoComponent() {
164
122
 
165
123
  // set initial load data
166
124
  (0, _react.useEffect)(function () {
167
- htmlContent();
168
125
  randomUser();
169
126
  }, []);
170
127
 
@@ -261,90 +218,21 @@ var AutoComponent = function AutoComponent() {
261
218
  return _ref2.apply(this, arguments);
262
219
  };
263
220
  }();
264
- var saveComponent = /*#__PURE__*/function () {
265
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(data) {
266
- var url, response, responseData;
267
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
268
- while (1) switch (_context3.prev = _context3.next) {
269
- case 0:
270
- url = "https://server-auto-component-46830ff262f8.herokuapp.com/user";
271
- _context3.next = 3;
272
- return fetch(url, {
273
- method: 'POST',
274
- headers: {
275
- 'Content-Type': 'application/json'
276
- },
277
- body: JSON.stringify(data)
278
- });
279
- case 3:
280
- response = _context3.sent;
281
- if (response.ok) {
282
- _context3.next = 6;
283
- break;
284
- }
285
- throw new Error('Failed to save component');
286
- case 6:
287
- _context3.next = 8;
288
- return response.json();
289
- case 8:
290
- responseData = _context3.sent;
291
- console.log('Save successful:', responseData);
292
- case 10:
293
- case "end":
294
- return _context3.stop();
295
- }
296
- }, _callee3);
297
- }));
298
- return function saveComponent(_x) {
299
- return _ref3.apply(this, arguments);
300
- };
301
- }();
302
221
 
303
222
  //**------------------------**/
304
223
  // ** UI/Button Handling ** //
305
224
  //**----------------------**/
306
225
 
307
- var handleSave = /*#__PURE__*/function () {
308
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
309
- var saveData;
310
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
311
- while (1) switch (_context4.prev = _context4.next) {
312
- case 0:
313
- saveData = {
314
- userId: user,
315
- content: responseData
316
- // Add other relevant data you might want to save
317
- };
318
- _context4.prev = 1;
319
- _context4.next = 4;
320
- return saveComponent(saveData);
321
- case 4:
322
- _context4.next = 9;
323
- break;
324
- case 6:
325
- _context4.prev = 6;
326
- _context4.t0 = _context4["catch"](1);
327
- console.error("Error saving component:", _context4.t0);
328
- case 9:
329
- case "end":
330
- return _context4.stop();
331
- }
332
- }, _callee4, null, [[1, 6]]);
333
- }));
334
- return function handleSave() {
335
- return _ref4.apply(this, arguments);
336
- };
337
- }();
338
226
  var handleChange = function handleChange(e) {
339
227
  e.preventDefault();
340
228
  setRequest(e.target.value);
341
229
  };
342
230
  var handleGenerate = /*#__PURE__*/function () {
343
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(e) {
344
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
345
- while (1) switch (_context5.prev = _context5.next) {
231
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(e) {
232
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
233
+ while (1) switch (_context3.prev = _context3.next) {
346
234
  case 0:
347
- _context5.next = 2;
235
+ _context3.next = 2;
348
236
  return setRequestData({
349
237
  "userId": user,
350
238
  "request": currentRequest
@@ -353,12 +241,12 @@ var AutoComponent = function AutoComponent() {
353
241
  setRequest('');
354
242
  case 3:
355
243
  case "end":
356
- return _context5.stop();
244
+ return _context3.stop();
357
245
  }
358
- }, _callee5);
246
+ }, _callee3);
359
247
  }));
360
- return function handleGenerate(_x2) {
361
- return _ref5.apply(this, arguments);
248
+ return function handleGenerate(_x) {
249
+ return _ref3.apply(this, arguments);
362
250
  };
363
251
  }();
364
252
  (0, _react.useEffect)(function () {
@@ -374,56 +262,56 @@ var AutoComponent = function AutoComponent() {
374
262
  setIsRequesting(false);
375
263
  };
376
264
  var handleRequestTab = /*#__PURE__*/function () {
377
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
378
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
379
- while (1) switch (_context6.prev = _context6.next) {
265
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
266
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
267
+ while (1) switch (_context4.prev = _context4.next) {
380
268
  case 0:
381
- _context6.next = 2;
269
+ _context4.next = 2;
382
270
  return setActiveTab(activeTab === 'response' || activeTab === '' ? 'request' : '');
383
271
  case 2:
384
272
  case "end":
385
- return _context6.stop();
273
+ return _context4.stop();
386
274
  }
387
- }, _callee6);
275
+ }, _callee4);
388
276
  }));
389
277
  return function handleRequestTab() {
390
- return _ref6.apply(this, arguments);
278
+ return _ref4.apply(this, arguments);
391
279
  };
392
280
  }();
393
281
  var handleResponseTab = /*#__PURE__*/function () {
394
- var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
395
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
396
- while (1) switch (_context7.prev = _context7.next) {
282
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
283
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
284
+ while (1) switch (_context5.prev = _context5.next) {
397
285
  case 0:
398
- _context7.next = 2;
286
+ _context5.next = 2;
399
287
  return setActiveTab(activeTab === 'request' || activeTab === '' ? 'response' : '');
400
288
  case 2:
401
289
  case "end":
402
- return _context7.stop();
290
+ return _context5.stop();
403
291
  }
404
- }, _callee7);
292
+ }, _callee5);
405
293
  }));
406
294
  return function handleResponseTab() {
407
- return _ref7.apply(this, arguments);
295
+ return _ref5.apply(this, arguments);
408
296
  };
409
297
  }();
410
298
  var copyToClipboard = /*#__PURE__*/function () {
411
- var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
299
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
412
300
  var text;
413
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
414
- while (1) switch (_context8.prev = _context8.next) {
301
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
302
+ while (1) switch (_context6.prev = _context6.next) {
415
303
  case 0:
416
304
  text = activeTab === 'response' ? responseData : requestData;
417
- _context8.next = 3;
305
+ _context6.next = 3;
418
306
  return navigator.clipboard.writeText(text);
419
307
  case 3:
420
308
  case "end":
421
- return _context8.stop();
309
+ return _context6.stop();
422
310
  }
423
- }, _callee8);
311
+ }, _callee6);
424
312
  }));
425
313
  return function copyToClipboard() {
426
- return _ref8.apply(this, arguments);
314
+ return _ref6.apply(this, arguments);
427
315
  };
428
316
  }();
429
317
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-component",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "lib/index.js",
5
5
  "peerDependencies": {
6
6
  "react": "^18.2.0",
@@ -43,5 +43,5 @@
43
43
  "bugs": {
44
44
  "url": "https://github.com/TimHuitt/auto-component/issues"
45
45
  },
46
- "homepage": "https://auto-component.netlify.app/"
46
+ "homepage": "https://auto-component.com/"
47
47
  }