auto-component 0.1.3 → 1.0.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.
- package/README.md +58 -7
- package/lib/index.js +117 -44
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/auto-component)
|
|
4
4
|
|
|
5
|
-
> A tool to streamline UI element creation in React projects
|
|
5
|
+
> A tool to streamline UI element creation in React projects through AI prompted generation
|
|
6
|
+
|
|
7
|
+
## Technologies Used
|
|
8
|
+
|
|
9
|
+
| Category | Technologies |
|
|
10
|
+
|---------------------|----------------------------------------------------------------------------------------|
|
|
11
|
+
| **Frontend** | [React](https://reactjs.org/) - [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript) |
|
|
12
|
+
| **Backend** | [Mongoose](https://mongoosejs.com/) - [Express](https://expressjs.com/) - [Node.js](https://nodejs.org/) |
|
|
13
|
+
| **Dependencies** | [Babel](https://babeljs.io/) - [JSXParser](https://www.npmjs.com/package/jsx-parser) - [js-beautify](https://www.npmjs.com/package/js-beautify) |
|
|
14
|
+
|
|
15
|
+
#### Dependency Uses
|
|
16
|
+
> Babel - Transpile JSX to JS for publishing<br/>
|
|
17
|
+
JSXParser - Dynamically render generated code<br/>
|
|
18
|
+
js-beautify - Format JSX/HTML for UI display
|
|
6
19
|
|
|
7
20
|
## Installation
|
|
8
21
|
|
|
@@ -20,7 +33,7 @@ npm install -D auto-component
|
|
|
20
33
|
import AutoComponent from 'auto-component';
|
|
21
34
|
```
|
|
22
35
|
|
|
23
|
-
<div style="
|
|
36
|
+
<div style="display: flex; justify-content: center; align-items: center;">
|
|
24
37
|
<img src="https://i.imgur.com/v18uMyR.png" alt="Step 2" style="max-width: 100%; height: auto;">
|
|
25
38
|
</div>
|
|
26
39
|
|
|
@@ -30,7 +43,7 @@ import AutoComponent from 'auto-component';
|
|
|
30
43
|
<AutoComponent />
|
|
31
44
|
```
|
|
32
45
|
|
|
33
|
-
<div style="
|
|
46
|
+
<div style="display: flex; justify-content: center; align-items: center;">
|
|
34
47
|
<img src="https://i.imgur.com/Hh4MV4W.png" alt="Step 3" style="max-width: 100%; height: auto;">
|
|
35
48
|
</div>
|
|
36
49
|
|
|
@@ -38,13 +51,13 @@ import AutoComponent from 'auto-component';
|
|
|
38
51
|
|
|
39
52
|
3. View your page to see the auto-component tool at the bottom, indicating where it will render your code:
|
|
40
53
|
|
|
41
|
-
<div style="
|
|
54
|
+
<div style="display: flex; justify-content: center; align-items: center;">
|
|
42
55
|
<img src="https://i.imgur.com/ItXg9Bd.png" alt="Step 4" style="max-width: 100%; height: auto;">
|
|
43
56
|
</div>
|
|
44
57
|
|
|
45
58
|
4. Start building by telling `auto-component` what you want and clicking "Generate." The result will be rendered on the page. You can view the "Request" or "Response" tabs to inspect what is being sent to the AI and what was returned:
|
|
46
59
|
|
|
47
|
-
<div style="
|
|
60
|
+
<div style="display: flex; justify-content: center; align-items: center;">
|
|
48
61
|
<img src="https://i.imgur.com/DmXWPdC.gif" alt="Step 5" style="max-width: 100%; height: auto;">
|
|
49
62
|
</div>
|
|
50
63
|
|
|
@@ -52,7 +65,7 @@ import AutoComponent from 'auto-component';
|
|
|
52
65
|
|
|
53
66
|
5. Ask `auto-component` to make changes to the code it provided, and see the changes rendered on the page:
|
|
54
67
|
|
|
55
|
-
<div style="
|
|
68
|
+
<div style="display: flex; justify-content: center; align-items: center;">
|
|
56
69
|
<img src="https://i.imgur.com/zSqx9iP.gif" alt="Step 6" style="max-width: 100%; height: auto;">
|
|
57
70
|
</div>
|
|
58
71
|
|
|
@@ -60,7 +73,7 @@ import AutoComponent from 'auto-component';
|
|
|
60
73
|
|
|
61
74
|
6. When satisfied with the response, click on the "Response" tab underneath the input. Copy the code from the AI to use it in your codebase:
|
|
62
75
|
|
|
63
|
-
<div style="
|
|
76
|
+
<div style="display: flex; justify-content: center; align-items: center;">
|
|
64
77
|
<img src="https://i.imgur.com/m9KpCHL.gif" alt="Step 7" style="max-width: 100%; height: auto;">
|
|
65
78
|
</div>
|
|
66
79
|
|
|
@@ -68,6 +81,44 @@ import AutoComponent from 'auto-component';
|
|
|
68
81
|
|
|
69
82
|
7. Click the red X button to start a new session.
|
|
70
83
|
|
|
84
|
+
|
|
85
|
+
# Planned Features
|
|
86
|
+
|
|
87
|
+
## User Features
|
|
88
|
+
|
|
89
|
+
1. **Personal Page:**
|
|
90
|
+
- Allow users to create a personal page to store and manage their created components.
|
|
91
|
+
- Efficiently reuse and keep track of components.
|
|
92
|
+
|
|
93
|
+
2. **Save and Manage Code:**
|
|
94
|
+
- Provide a "Save" button to store the returned code from the AI.
|
|
95
|
+
- Users can easily manage their components within their user page.
|
|
96
|
+
|
|
97
|
+
3. **Position Customization:**
|
|
98
|
+
- Allow users to shift the position of the request/code box around the screen.
|
|
99
|
+
- Ensure it doesn't obscure anything in their project.
|
|
100
|
+
|
|
101
|
+
## Developer Features
|
|
102
|
+
|
|
103
|
+
1. **Code Integration Walkthrough:**
|
|
104
|
+
- Include an optional walkthrough of code integration.
|
|
105
|
+
- Help developers understand how to implement generated components into their projects.
|
|
106
|
+
|
|
107
|
+
2. **Code Editing in the Browser:**
|
|
108
|
+
- Enable developers to edit displayed code directly in the browser.
|
|
109
|
+
- Allow quick adjustments without leaving the platform.
|
|
110
|
+
|
|
111
|
+
3. **Access Saved Components:**
|
|
112
|
+
- Provide developers with the ability to access their saved components directly from the AutoComponent component.
|
|
113
|
+
|
|
114
|
+
4. **Multiple AutoComponent Instances:**
|
|
115
|
+
- Notify developers if there is more than one `<AutoComponent />` creation component added to the project.
|
|
116
|
+
- Prevent potential functionality issues that may arise from multiple instances.
|
|
117
|
+
|
|
118
|
+
5. **Multiple Components with Single Request Box:**
|
|
119
|
+
- Allow developers to add multiple components to the page.
|
|
120
|
+
- Provide an easy way to switch between them using a single request box.
|
|
121
|
+
|
|
71
122
|
## License
|
|
72
123
|
|
|
73
124
|
This project is licensed under the AGPL 3.0 License - see the [LICENSE](LICENSE) file for details.
|
package/lib/index.js
CHANGED
|
@@ -61,24 +61,28 @@ var AutoComponent = function AutoComponent() {
|
|
|
61
61
|
setUser = _useState8[1];
|
|
62
62
|
var _useState9 = (0, _react.useState)(''),
|
|
63
63
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var _useState11 = (0, _react.useState)(
|
|
64
|
+
userID = _useState10[0],
|
|
65
|
+
setUserID = _useState10[1];
|
|
66
|
+
var _useState11 = (0, _react.useState)(''),
|
|
67
67
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
var _useState13 = (0, _react.useState)(
|
|
68
|
+
responseData = _useState12[0],
|
|
69
|
+
setResponseData = _useState12[1];
|
|
70
|
+
var _useState13 = (0, _react.useState)(null),
|
|
71
71
|
_useState14 = _slicedToArray(_useState13, 2),
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
var _useState15 = (0, _react.useState)(
|
|
72
|
+
requestData = _useState14[0],
|
|
73
|
+
setRequestData = _useState14[1];
|
|
74
|
+
var _useState15 = (0, _react.useState)(''),
|
|
75
75
|
_useState16 = _slicedToArray(_useState15, 2),
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
var _useState17 = (0, _react.useState)(
|
|
76
|
+
activeTab = _useState16[0],
|
|
77
|
+
setActiveTab = _useState16[1];
|
|
78
|
+
var _useState17 = (0, _react.useState)(["No History"]),
|
|
79
79
|
_useState18 = _slicedToArray(_useState17, 2),
|
|
80
|
-
|
|
81
|
-
|
|
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];
|
|
82
86
|
|
|
83
87
|
//**-------------------------**/
|
|
84
88
|
// ** HTML/CSS Formatting ** //
|
|
@@ -257,21 +261,90 @@ var AutoComponent = function AutoComponent() {
|
|
|
257
261
|
return _ref2.apply(this, arguments);
|
|
258
262
|
};
|
|
259
263
|
}();
|
|
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
|
+
}();
|
|
260
302
|
|
|
261
303
|
//**------------------------**/
|
|
262
304
|
// ** UI/Button Handling ** //
|
|
263
305
|
//**----------------------**/
|
|
264
306
|
|
|
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
|
+
}();
|
|
265
338
|
var handleChange = function handleChange(e) {
|
|
266
339
|
e.preventDefault();
|
|
267
340
|
setRequest(e.target.value);
|
|
268
341
|
};
|
|
269
342
|
var handleGenerate = /*#__PURE__*/function () {
|
|
270
|
-
var
|
|
271
|
-
return _regeneratorRuntime().wrap(function
|
|
272
|
-
while (1) switch (
|
|
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) {
|
|
273
346
|
case 0:
|
|
274
|
-
|
|
347
|
+
_context5.next = 2;
|
|
275
348
|
return setRequestData({
|
|
276
349
|
"userId": user,
|
|
277
350
|
"request": currentRequest
|
|
@@ -280,12 +353,12 @@ var AutoComponent = function AutoComponent() {
|
|
|
280
353
|
setRequest('');
|
|
281
354
|
case 3:
|
|
282
355
|
case "end":
|
|
283
|
-
return
|
|
356
|
+
return _context5.stop();
|
|
284
357
|
}
|
|
285
|
-
},
|
|
358
|
+
}, _callee5);
|
|
286
359
|
}));
|
|
287
|
-
return function handleGenerate(
|
|
288
|
-
return
|
|
360
|
+
return function handleGenerate(_x2) {
|
|
361
|
+
return _ref5.apply(this, arguments);
|
|
289
362
|
};
|
|
290
363
|
}();
|
|
291
364
|
(0, _react.useEffect)(function () {
|
|
@@ -301,56 +374,56 @@ var AutoComponent = function AutoComponent() {
|
|
|
301
374
|
setIsRequesting(false);
|
|
302
375
|
};
|
|
303
376
|
var handleRequestTab = /*#__PURE__*/function () {
|
|
304
|
-
var
|
|
305
|
-
return _regeneratorRuntime().wrap(function
|
|
306
|
-
while (1) switch (
|
|
377
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
378
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
379
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
307
380
|
case 0:
|
|
308
|
-
|
|
381
|
+
_context6.next = 2;
|
|
309
382
|
return setActiveTab(activeTab === 'response' || activeTab === '' ? 'request' : '');
|
|
310
383
|
case 2:
|
|
311
384
|
case "end":
|
|
312
|
-
return
|
|
385
|
+
return _context6.stop();
|
|
313
386
|
}
|
|
314
|
-
},
|
|
387
|
+
}, _callee6);
|
|
315
388
|
}));
|
|
316
389
|
return function handleRequestTab() {
|
|
317
|
-
return
|
|
390
|
+
return _ref6.apply(this, arguments);
|
|
318
391
|
};
|
|
319
392
|
}();
|
|
320
393
|
var handleResponseTab = /*#__PURE__*/function () {
|
|
321
|
-
var
|
|
322
|
-
return _regeneratorRuntime().wrap(function
|
|
323
|
-
while (1) switch (
|
|
394
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
395
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
396
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
324
397
|
case 0:
|
|
325
|
-
|
|
398
|
+
_context7.next = 2;
|
|
326
399
|
return setActiveTab(activeTab === 'request' || activeTab === '' ? 'response' : '');
|
|
327
400
|
case 2:
|
|
328
401
|
case "end":
|
|
329
|
-
return
|
|
402
|
+
return _context7.stop();
|
|
330
403
|
}
|
|
331
|
-
},
|
|
404
|
+
}, _callee7);
|
|
332
405
|
}));
|
|
333
406
|
return function handleResponseTab() {
|
|
334
|
-
return
|
|
407
|
+
return _ref7.apply(this, arguments);
|
|
335
408
|
};
|
|
336
409
|
}();
|
|
337
410
|
var copyToClipboard = /*#__PURE__*/function () {
|
|
338
|
-
var
|
|
411
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
339
412
|
var text;
|
|
340
|
-
return _regeneratorRuntime().wrap(function
|
|
341
|
-
while (1) switch (
|
|
413
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
414
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
342
415
|
case 0:
|
|
343
416
|
text = activeTab === 'response' ? responseData : requestData;
|
|
344
|
-
|
|
417
|
+
_context8.next = 3;
|
|
345
418
|
return navigator.clipboard.writeText(text);
|
|
346
419
|
case 3:
|
|
347
420
|
case "end":
|
|
348
|
-
return
|
|
421
|
+
return _context8.stop();
|
|
349
422
|
}
|
|
350
|
-
},
|
|
423
|
+
}, _callee8);
|
|
351
424
|
}));
|
|
352
425
|
return function copyToClipboard() {
|
|
353
|
-
return
|
|
426
|
+
return _ref8.apply(this, arguments);
|
|
354
427
|
};
|
|
355
428
|
}();
|
|
356
429
|
|
|
@@ -366,7 +439,7 @@ var AutoComponent = function AutoComponent() {
|
|
|
366
439
|
};
|
|
367
440
|
|
|
368
441
|
// build request tab content
|
|
369
|
-
var requestHTML = currentHtml ? getLog() && getLog().join('') + "Click Generate to send a request and receive the auto component AI generated code.\n\nUser ID:\n" + user + "\n\nUser Request:\n" + currentRequest
|
|
442
|
+
var requestHTML = currentHtml ? getLog() && getLog().join('') + "Click Generate to send a request and receive the auto component AI generated code.\n\nUser ID:\n" + user + "\n\nUser Request:\n" + currentRequest : 'There was an error collecting your HTML. Ensure no top level elements are assigned the class "exclude"';
|
|
370
443
|
var responseHtml = responseData ? responseData : 'No response has been generated';
|
|
371
444
|
var handleKeyDown = function handleKeyDown(e) {
|
|
372
445
|
if (e.key === 'Enter') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
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://
|
|
46
|
+
"homepage": "https://auto-component.netlify.app/"
|
|
47
47
|
}
|