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.
- package/README.md +5 -0
- package/lib/index.js +47 -159
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/auto-component)
|
|
4
4
|
|
|
5
|
+
[](https://github.com/TimHuitt/client-auto-component)
|
|
6
|
+
|
|
7
|
+
[](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)
|
|
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
|
-
|
|
53
|
-
|
|
52
|
+
currentRequest = _useState4[0],
|
|
53
|
+
setRequest = _useState4[1];
|
|
54
54
|
var _useState5 = (0, _react.useState)(''),
|
|
55
55
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
user = _useState6[0],
|
|
57
|
+
setUser = _useState6[1];
|
|
58
58
|
var _useState7 = (0, _react.useState)(''),
|
|
59
59
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
65
|
-
|
|
64
|
+
requestData = _useState10[0],
|
|
65
|
+
setRequestData = _useState10[1];
|
|
66
66
|
var _useState11 = (0, _react.useState)(''),
|
|
67
67
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
var _useState13 = (0, _react.useState)(
|
|
68
|
+
activeTab = _useState12[0],
|
|
69
|
+
setActiveTab = _useState12[1];
|
|
70
|
+
var _useState13 = (0, _react.useState)(["No History"]),
|
|
71
71
|
_useState14 = _slicedToArray(_useState13, 2),
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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
|
|
344
|
-
return _regeneratorRuntime().wrap(function
|
|
345
|
-
while (1) switch (
|
|
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
|
-
|
|
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
|
|
244
|
+
return _context3.stop();
|
|
357
245
|
}
|
|
358
|
-
},
|
|
246
|
+
}, _callee3);
|
|
359
247
|
}));
|
|
360
|
-
return function handleGenerate(
|
|
361
|
-
return
|
|
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
|
|
378
|
-
return _regeneratorRuntime().wrap(function
|
|
379
|
-
while (1) switch (
|
|
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
|
-
|
|
269
|
+
_context4.next = 2;
|
|
382
270
|
return setActiveTab(activeTab === 'response' || activeTab === '' ? 'request' : '');
|
|
383
271
|
case 2:
|
|
384
272
|
case "end":
|
|
385
|
-
return
|
|
273
|
+
return _context4.stop();
|
|
386
274
|
}
|
|
387
|
-
},
|
|
275
|
+
}, _callee4);
|
|
388
276
|
}));
|
|
389
277
|
return function handleRequestTab() {
|
|
390
|
-
return
|
|
278
|
+
return _ref4.apply(this, arguments);
|
|
391
279
|
};
|
|
392
280
|
}();
|
|
393
281
|
var handleResponseTab = /*#__PURE__*/function () {
|
|
394
|
-
var
|
|
395
|
-
return _regeneratorRuntime().wrap(function
|
|
396
|
-
while (1) switch (
|
|
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
|
-
|
|
286
|
+
_context5.next = 2;
|
|
399
287
|
return setActiveTab(activeTab === 'request' || activeTab === '' ? 'response' : '');
|
|
400
288
|
case 2:
|
|
401
289
|
case "end":
|
|
402
|
-
return
|
|
290
|
+
return _context5.stop();
|
|
403
291
|
}
|
|
404
|
-
},
|
|
292
|
+
}, _callee5);
|
|
405
293
|
}));
|
|
406
294
|
return function handleResponseTab() {
|
|
407
|
-
return
|
|
295
|
+
return _ref5.apply(this, arguments);
|
|
408
296
|
};
|
|
409
297
|
}();
|
|
410
298
|
var copyToClipboard = /*#__PURE__*/function () {
|
|
411
|
-
var
|
|
299
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
412
300
|
var text;
|
|
413
|
-
return _regeneratorRuntime().wrap(function
|
|
414
|
-
while (1) switch (
|
|
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
|
-
|
|
305
|
+
_context6.next = 3;
|
|
418
306
|
return navigator.clipboard.writeText(text);
|
|
419
307
|
case 3:
|
|
420
308
|
case "end":
|
|
421
|
-
return
|
|
309
|
+
return _context6.stop();
|
|
422
310
|
}
|
|
423
|
-
},
|
|
311
|
+
}, _callee6);
|
|
424
312
|
}));
|
|
425
313
|
return function copyToClipboard() {
|
|
426
|
-
return
|
|
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.
|
|
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.
|
|
46
|
+
"homepage": "https://auto-component.com/"
|
|
47
47
|
}
|