@fonixtree/magic-design 0.1.74 → 0.1.76

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.
@@ -17,17 +17,13 @@ var _GenerateArtist = _interopRequireDefault(require("./GenerateArtist"));
17
17
 
18
18
  var _UploadReference = _interopRequireDefault(require("./UploadReference"));
19
19
 
20
- var _History = _interopRequireDefault(require("./History"));
21
-
22
20
  var _nodata = _interopRequireDefault(require("./images/nodata.png"));
23
21
 
24
22
  var _common = require("../../../common");
25
23
 
26
- var _commonUtil = require("../../../utils/commonUtil");
27
-
28
- var _storeUtil = require("../../../utils/storeUtil");
24
+ var _mobx = require("../../../mobx");
29
25
 
30
- var _constants = require("../../../constants");
26
+ var _commonUtil = require("../../../utils/commonUtil");
31
27
 
32
28
  require("./index.less");
33
29
 
@@ -63,22 +59,6 @@ var __extends = void 0 && (void 0).__extends || function () {
63
59
  };
64
60
  }();
65
61
 
66
- var __assign = void 0 && (void 0).__assign || function () {
67
- __assign = Object.assign || function (t) {
68
- for (var s, i = 1, n = arguments.length; i < n; i++) {
69
- s = arguments[i];
70
-
71
- for (var p in s) {
72
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
73
- }
74
- }
75
-
76
- return t;
77
- };
78
-
79
- return __assign.apply(this, arguments);
80
- };
81
-
82
62
  var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
83
63
  function adopt(value) {
84
64
  return value instanceof P ? value : new P(function (resolve) {
@@ -234,25 +214,13 @@ function (_super) {
234
214
 
235
215
  _this.state = {
236
216
  loading: false,
237
- selected: [],
238
- prompt: '',
239
- history: [],
240
- hisCursor: 0
217
+ visible: false,
218
+ images: []
241
219
  };
242
220
  _this.formRef = /*#__PURE__*/_react["default"].createRef();
243
221
 
244
- _this.onHisConfigClick = function () {};
245
-
246
- _this.historyChange = function (newHis) {
247
- (0, _storeUtil.setSessionStore)(_constants.STORAGE_KEY.FONIXTREE_AI_IMG_HIS, newHis);
248
-
249
- _this.setState({
250
- history: newHis
251
- });
252
- };
253
-
254
222
  _this.getColumnNum = function (num) {
255
- if (num <= 1) {
223
+ if (num === 1) {
256
224
  return 1;
257
225
  } else if (num > 1 && num <= 4) {
258
226
  return 2;
@@ -262,89 +230,42 @@ function (_super) {
262
230
  };
263
231
 
264
232
  _this.onCloseDrawer = function () {
265
- _this.props.onClose();
266
- };
267
-
268
- _this.onConfirm = function () {
269
- return __awaiter(_this, void 0, void 0, function () {
270
- var _a, history, hisCursor, selected, images, imageList, result;
271
-
272
- return __generator(this, function (_b) {
273
- switch (_b.label) {
274
- case 0:
275
- _a = this.state, history = _a.history, hisCursor = _a.hisCursor, selected = _a.selected;
276
-
277
- if (!selected.length) {
278
- return [2
279
- /*return*/
280
- ];
281
- }
282
-
283
- images = history[hisCursor].images;
284
- imageList = selected.map(function (sel) {
285
- return images[sel];
286
- });
287
- return [4
288
- /*yield*/
289
- , (0, _commonUtil.commonFetch)('/designer/v1/uploadImage', {
290
- base64Images: imageList
291
- }, 'POST')];
292
-
293
- case 1:
294
- result = _b.sent();
295
- this.props.onConfirm(result[0]);
296
- return [2
297
- /*return*/
298
- ];
299
- }
300
- });
233
+ _mobx.store.setState({
234
+ imgGenVisible: false
301
235
  });
302
236
  };
303
237
 
238
+ _this.onHisConfigClick = function () {};
239
+
304
240
  _this.onGenarate = function (prompt) {
305
241
  return __awaiter(_this, void 0, void 0, function () {
306
- var history, formVal, params, result, e_1;
242
+ var formVal, result, e_1;
307
243
  return __generator(this, function (_a) {
308
244
  switch (_a.label) {
309
245
  case 0:
310
- history = this.state.history;
311
-
312
- if (!prompt) {
313
- return [2
314
- /*return*/
315
- ];
316
- }
317
-
318
246
  formVal = this.formRef.current.getFieldsValue(true);
319
- params = {
320
- prompt: prompt,
321
- n: formVal.number || 1,
322
- height: 256,
323
- width: 256
324
- };
247
+ this.setState({
248
+ loading: true
249
+ });
325
250
  _a.label = 1;
326
251
 
327
252
  case 1:
328
253
  _a.trys.push([1, 3,, 4]);
329
254
 
330
- this.setState({
331
- prompt: prompt,
332
- loading: true
333
- });
334
255
  return [4
335
256
  /*yield*/
336
- , (0, _commonUtil.commonFetch)('/designer/v1/ai/create-image', params, 'POST')];
257
+ , (0, _commonUtil.commonFetch)('/designer/v1/ai/create-image', {
258
+ prompt: prompt,
259
+ n: formVal.number || 4,
260
+ height: 256,
261
+ width: 256
262
+ }, 'POST')];
337
263
 
338
264
  case 2:
339
265
  result = _a.sent();
340
- history.push({
341
- images: result.imageList,
342
- params: params
343
- });
344
- this.historyChange(history);
345
266
  this.setState({
346
267
  loading: false,
347
- hisCursor: history.length - 1
268
+ images: result.imageList
348
269
  });
349
270
  return [3
350
271
  /*break*/
@@ -368,197 +289,16 @@ function (_super) {
368
289
  });
369
290
  };
370
291
 
371
- _this.onRegenerate = function () {
372
- return __awaiter(_this, void 0, void 0, function () {
373
- var _a, history, hisCursor, params, result, e_2;
374
-
375
- return __generator(this, function (_b) {
376
- switch (_b.label) {
377
- case 0:
378
- _a = this.state, history = _a.history, hisCursor = _a.hisCursor;
379
- params = history[hisCursor].params;
380
- _b.label = 1;
381
-
382
- case 1:
383
- _b.trys.push([1, 3,, 4]);
384
-
385
- this.setState({
386
- loading: true
387
- });
388
- return [4
389
- /*yield*/
390
- , (0, _commonUtil.commonFetch)('/designer/v1/ai/create-image', params, 'POST')];
391
-
392
- case 2:
393
- result = _b.sent();
394
- history[hisCursor] = {
395
- images: result.imageList,
396
- params: params
397
- };
398
- this.historyChange(history);
399
- this.setState({
400
- loading: false
401
- });
402
- return [3
403
- /*break*/
404
- , 4];
405
-
406
- case 3:
407
- e_2 = _b.sent();
408
- this.setState({
409
- loading: false
410
- });
411
- return [3
412
- /*break*/
413
- , 4];
414
-
415
- case 4:
416
- return [2
417
- /*return*/
418
- ];
419
- }
420
- });
421
- });
422
- };
423
-
424
292
  _this.getImageList = function (images) {
425
- var selected = _this.state.selected;
426
- return images.map(function (img, index) {
293
+ var columnNum = _this.getColumnNum(images.length);
294
+
295
+ return images.map(function (img) {
427
296
  return /*#__PURE__*/_react["default"].createElement("div", {
428
- className: "aiImageItem"
297
+ className: "aiImageWrap" + columnNum
429
298
  }, /*#__PURE__*/_react["default"].createElement("img", {
430
299
  alt: "",
431
300
  src: img
432
- }), /*#__PURE__*/_react["default"].createElement("div", {
433
- className: "imgHandleBtnWrap"
434
- }, /*#__PURE__*/_react["default"].createElement("div", {
435
- className: "refreshBtnWrap"
436
- }, /*#__PURE__*/_react["default"].createElement(_common.Iconfont, {
437
- color: "#232F46",
438
- onClick: function onClick() {
439
- return _this.onRefresh(index);
440
- },
441
- size: 16,
442
- type: "icon-refresh"
443
- })), /*#__PURE__*/_react["default"].createElement("div", {
444
- className: "downloadBtnWrap"
445
- }, /*#__PURE__*/_react["default"].createElement(_common.Iconfont, {
446
- color: "#232F46",
447
- onClick: function onClick() {
448
- return _this.onDownload(index);
449
- },
450
- size: 16,
451
- type: "icon-download1"
452
- }))), /*#__PURE__*/_react["default"].createElement("div", {
453
- className: "imgSelectBtnWrap"
454
- }, /*#__PURE__*/_react["default"].createElement(_common.Iconfont, {
455
- color: "#2F54EB",
456
- onClick: function onClick() {
457
- return _this.onSelectClick(index);
458
- },
459
- size: 22,
460
- style: {
461
- cursor: 'pointer'
462
- },
463
- type: selected.includes(index) ? 'icon-select1' : 'icon-uncheck'
464
- })));
465
- });
466
- };
467
-
468
- _this.onRefresh = function (index) {
469
- return __awaiter(_this, void 0, void 0, function () {
470
- var _a, history, hisCursor, _b, images, params, result, e_3;
471
-
472
- return __generator(this, function (_c) {
473
- switch (_c.label) {
474
- case 0:
475
- _a = this.state, history = _a.history, hisCursor = _a.hisCursor;
476
- _b = history[hisCursor], images = _b.images, params = _b.params;
477
- _c.label = 1;
478
-
479
- case 1:
480
- _c.trys.push([1, 3,, 4]);
481
-
482
- this.setState({
483
- loading: true
484
- });
485
- return [4
486
- /*yield*/
487
- , (0, _commonUtil.commonFetch)('/designer/v1/ai/create-image', __assign(__assign({}, params), {
488
- n: 1
489
- }), 'POST')];
490
-
491
- case 2:
492
- result = _c.sent();
493
- images[index] = result.imageList[0];
494
- this.historyChange(history);
495
- this.setState({
496
- loading: false
497
- });
498
- return [3
499
- /*break*/
500
- , 4];
501
-
502
- case 3:
503
- e_3 = _c.sent();
504
- this.setState({
505
- loading: false
506
- });
507
- return [3
508
- /*break*/
509
- , 4];
510
-
511
- case 4:
512
- return [2
513
- /*return*/
514
- ];
515
- }
516
- });
517
- });
518
- };
519
-
520
- _this.onDownload = function (index) {
521
- var _a = _this.state,
522
- prompt = _a.prompt,
523
- history = _a.history,
524
- hisCursor = _a.hisCursor;
525
- var images = history[hisCursor].images;
526
- (0, _commonUtil.downloadBase64Image)(images[index], prompt + ".png");
527
- };
528
-
529
- _this.onSelectClick = function (index) {
530
- var selected = _this.state.selected;
531
- var single = _this.props.single; // 单选模式下,智能选中一个
532
-
533
- if (single) {
534
- _this.setState({
535
- selected: [index]
536
- });
537
-
538
- return;
539
- } // 多选模式,可以选择多个
540
-
541
-
542
- if (selected.includes(index)) {
543
- var newSelected = selected.filter(function (sel) {
544
- return sel !== index;
545
- });
546
-
547
- _this.setState({
548
- selected: newSelected
549
- });
550
- } else {
551
- selected.push(index);
552
-
553
- _this.setState({
554
- selected: selected
555
- });
556
- }
557
- };
558
-
559
- _this.onHistoryClick = function (index) {
560
- _this.setState({
561
- hisCursor: index
301
+ }));
562
302
  });
563
303
  };
564
304
 
@@ -566,9 +306,12 @@ function (_super) {
566
306
  }
567
307
 
568
308
  AiImageGenerator.prototype.componentDidMount = function () {
569
- var history = (0, _storeUtil.getSessionStore)(_constants.STORAGE_KEY.FONIXTREE_AI_IMG_HIS) || [];
570
- this.setState({
571
- history: history
309
+ var _this = this;
310
+
311
+ this.destory = (0, _mobx.autorun)(function () {
312
+ _this.setState({
313
+ visible: _mobx.store.imgGenVisible
314
+ });
572
315
  });
573
316
  };
574
317
 
@@ -577,15 +320,10 @@ function (_super) {
577
320
  };
578
321
 
579
322
  AiImageGenerator.prototype.render = function () {
580
- var _a;
581
-
582
- var _b = this.state,
583
- loading = _b.loading,
584
- history = _b.history,
585
- hisCursor = _b.hisCursor;
586
- var visible = this.props.visible;
587
- var images = ((_a = history[hisCursor]) === null || _a === void 0 ? void 0 : _a.images) || [];
588
- var columnNum = this.getColumnNum(images.length || []);
323
+ var _a = this.state,
324
+ visible = _a.visible,
325
+ images = _a.images,
326
+ loading = _a.loading;
589
327
  return /*#__PURE__*/_react["default"].createElement(_antd.Drawer, {
590
328
  bodyStyle: {
591
329
  padding: 16,
@@ -611,7 +349,6 @@ function (_super) {
611
349
  type: "light"
612
350
  }, "Cancel"), /*#__PURE__*/_react["default"].createElement(_common.Button, {
613
351
  className: "ml8",
614
- onClick: this.onConfirm,
615
352
  size: "small",
616
353
  type: "primary"
617
354
  }, "Confirm"))),
@@ -667,24 +404,19 @@ function (_super) {
667
404
  })))), /*#__PURE__*/_react["default"].createElement("div", {
668
405
  className: "middle_wrap"
669
406
  }, /*#__PURE__*/_react["default"].createElement("div", {
670
- className: "img_wrap",
671
- style: {
672
- gridTemplateColumns: "repeat(" + columnNum + ", 1fr)",
673
- gridTemplateRows: "repeat(" + columnNum + ", 1fr)"
674
- }
675
- }, images.length > 0 ? this.getImageList(images) : /*#__PURE__*/_react["default"].createElement("div", {
676
- className: "noDataWrap"
677
- }, /*#__PURE__*/_react["default"].createElement("img", {
407
+ className: "img_wrap"
408
+ }, images.length > 0 ? this.getImageList(images) : /*#__PURE__*/_react["default"].createElement("img", {
678
409
  alt: "",
679
410
  className: "no_data",
680
411
  src: _nodata["default"]
681
- })), /*#__PURE__*/_react["default"].createElement("div", null)), /*#__PURE__*/_react["default"].createElement("div", {
412
+ }), /*#__PURE__*/_react["default"].createElement("div", null)), /*#__PURE__*/_react["default"].createElement("div", {
682
413
  className: "btn_wrap"
683
414
  }, /*#__PURE__*/_react["default"].createElement("div", {
684
415
  className: "regenerate_btn",
685
- onClick: this.onRegenerate
416
+ onClick: this.onRegenarate
686
417
  }, /*#__PURE__*/_react["default"].createElement(_common.Iconfont, {
687
418
  color: "#232F46",
419
+ onClick: this.onCloseDrawer,
688
420
  size: 16,
689
421
  style: {
690
422
  marginRight: 5
@@ -696,12 +428,20 @@ function (_super) {
696
428
  enterButton: "Generate",
697
429
  onSearch: this.onGenarate,
698
430
  size: "large"
699
- }))), /*#__PURE__*/_react["default"].createElement(_History["default"], {
700
- onChange: this.historyChange,
701
- onClick: this.onHistoryClick,
702
- selectIndex: hisCursor,
703
- source: history
704
- }))));
431
+ }))), /*#__PURE__*/_react["default"].createElement("div", {
432
+ className: "right_wrap"
433
+ }, /*#__PURE__*/_react["default"].createElement("div", {
434
+ className: "right_header"
435
+ }, /*#__PURE__*/_react["default"].createElement("div", {
436
+ className: "title"
437
+ }, "History"), /*#__PURE__*/_react["default"].createElement(_common.Iconfont, {
438
+ onClick: this.onHisConfigClick,
439
+ size: 20,
440
+ style: {
441
+ cursor: 'pointer'
442
+ },
443
+ type: "icon-setting1"
444
+ }))))));
705
445
  };
706
446
 
707
447
  return AiImageGenerator;
@@ -27,74 +27,46 @@
27
27
  position: relative;
28
28
  .img_wrap {
29
29
  width: 492px;
30
- height: 492px;
31
- display: grid;
32
- grid-template-columns: repeat(2, 1fr);
33
- grid-template-rows: repeat(2, 1fr);
34
- grid-gap: 12px;
35
- margin: 0 auto;
36
-
37
- .aiImageItem {
38
- position: relative;
39
- background-color: #ccc;
40
- display: flex;
41
- align-items: center;
42
- justify-content: center;
43
- font-size: 24px;
44
- img {
45
- width: 100%;
46
- }
47
- .imgHandleBtnWrap {
48
- display: flex;
49
- position: absolute;
50
- bottom: 12px;
51
- right: 12px;
52
- .refreshBtnWrap {
53
- background-color: #FFF;
54
- cursor: pointer;
55
- height: 28px;
56
- width: 28px;
57
- display: flex;
58
- align-items: center;
59
- justify-content: center;
60
- border-radius: 50%;
61
- border: 1px solid #D2D9E5;
62
- }
63
- .downloadBtnWrap {
64
- background-color: #FFF;
65
- cursor: pointer;
66
- height: 28px;
67
- width: 28px;
68
- display: flex;
69
- align-items: center;
70
- justify-content: center;
71
- margin-left: 12px;
72
- border-radius: 50%;
73
- border: 1px solid #D2D9E5;
74
- }
30
+ height: 100%;
31
+ display: flex;
32
+ flex-wrap: wrap;
33
+ align-items: center;
34
+ justify-content: center;
35
+ .aiImageWrap1 {
36
+ height: 492px;
37
+ width: 492px;
38
+ }
39
+ .aiImageWrap2 {
40
+ height: 240px;
41
+ width: 240px;
42
+ margin-bottom: 12px;
43
+ margin-left: 12px;
44
+ &:nth-child(2n - 1) {
45
+ margin-left: 0;
75
46
  }
76
- .imgSelectBtnWrap {
77
- position: absolute;
78
- top: 12px;
79
- right: 12px;
80
- border-radius: 50%;
81
- height: 22px;
82
- display: flex;
83
- background: #FFF;
47
+ img {
48
+ max-width: 100%;
84
49
  }
85
50
  }
86
- .noDataWrap {
87
- width: 100%;
88
- height: 100%;
89
- display: flex;
90
- align-items: center;
91
- justify-content: center;
92
- .no_data {
93
- height: 183px;
94
- width: 212px;
51
+
52
+ .aiImageWrap3 {
53
+ height: 156px;
54
+ width: 156px;
55
+ margin-bottom: 12px;
56
+ margin-bottom: 12px;
57
+ margin-left: 12px;
58
+ &:nth-child(3n + 1) {
59
+ margin-left: 0;
60
+ }
61
+ img {
62
+ max-width: 100%;
95
63
  }
96
64
  }
97
65
 
66
+ .no_data {
67
+ height: 183px;
68
+ width: 212px;
69
+ }
98
70
  }
99
71
  .btn_wrap {
100
72
  margin-top: 40px;
@@ -19,9 +19,9 @@ var _CopyBtn = _interopRequireDefault(require("./components/CopyBtn"));
19
19
 
20
20
  var _common = require("../../../common");
21
21
 
22
- var _FonixtreeGpt = _interopRequireDefault(require("../FonixtreeGpt"));
22
+ var _mobx = require("../../../mobx");
23
23
 
24
- var _AiImageGenerator = _interopRequireDefault(require("../AiImageGenerator"));
24
+ var _FonixtreeGpt = _interopRequireDefault(require("../FonixtreeGpt"));
25
25
 
26
26
  require("./index.less");
27
27
 
@@ -71,13 +71,12 @@ function (_super) {
71
71
  open: false,
72
72
  message: '',
73
73
  context: [],
74
- isGenerating: false,
75
- aiImageVisible: false
74
+ isGenerating: false
76
75
  };
77
76
 
78
77
  _this.scrollBottom = function () {
79
78
  var container = document.getElementById('content_wrap');
80
- container.scrollTop = container.scrollHeight + 50;
79
+ container.scrollTop = container.scrollHeight;
81
80
  };
82
81
 
83
82
  _this.onMessageChage = function (e) {
@@ -106,8 +105,6 @@ function (_super) {
106
105
  isGenerating: true,
107
106
  context: context,
108
107
  message: ''
109
- }, function () {
110
- _this.scrollBottom();
111
108
  });
112
109
  };
113
110
 
@@ -142,8 +139,8 @@ function (_super) {
142
139
  open: false
143
140
  });
144
141
 
145
- _this.setState({
146
- aiImageVisible: true
142
+ _mobx.store.setState({
143
+ imgGenVisible: true
147
144
  });
148
145
  };
149
146
 
@@ -172,6 +169,7 @@ function (_super) {
172
169
  }
173
170
 
174
171
  ChatRobot.prototype.componentDidMount = function () {
172
+ this.chatGpt.initChatGpt();
175
173
  var context = this.chatGpt.getContext();
176
174
  this.setState({
177
175
  context: context
@@ -185,8 +183,7 @@ function (_super) {
185
183
  context = _a.context,
186
184
  message = _a.message,
187
185
  open = _a.open,
188
- isGenerating = _a.isGenerating,
189
- aiImageVisible = _a.aiImageVisible;
186
+ isGenerating = _a.isGenerating;
190
187
  return /*#__PURE__*/_react["default"].createElement("div", {
191
188
  className: "chat_wrap"
192
189
  }, /*#__PURE__*/_react["default"].createElement("div", {
@@ -299,19 +296,7 @@ function (_super) {
299
296
  marginRight: 5
300
297
  },
301
298
  type: "icon-refresh"
302
- }), "Regenerate Response"))), /*#__PURE__*/_react["default"].createElement(_AiImageGenerator["default"], {
303
- onClose: function onClose() {
304
- return _this.setState({
305
- aiImageVisible: false
306
- });
307
- },
308
- onConfirm: function onConfirm() {
309
- return _this.setState({
310
- aiImageVisible: false
311
- });
312
- },
313
- visible: aiImageVisible
314
- }));
299
+ }), "Regenerate Response"))));
315
300
  };
316
301
 
317
302
  return ChatRobot;
@@ -89,9 +89,6 @@
89
89
  padding: 7px 14px;
90
90
  background: #F5F6F7;
91
91
  color: #232F46;
92
- p {
93
- margin-bottom: 0;
94
- }
95
92
  }
96
93
  }
97
94
  .regenerate_btn {