@blocklet/pages-kit 0.2.346 → 0.2.348

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.
@@ -23,6 +23,7 @@ import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
23
23
  import { Icon } from '@iconify/react';
24
24
  import { Box, Stack, styled } from '@mui/material';
25
25
  import { saveAs } from 'file-saver';
26
+ import _ from 'lodash';
26
27
  import { useMemo } from 'react';
27
28
  import { withQuery } from 'ufo';
28
29
  import { useLocaleContext } from '../../../../locale';
@@ -30,21 +31,31 @@ import { useCurrentAgent } from '../../contexts/CurrentAgent';
30
31
  import { useCurrentMessage } from '../../contexts/CurrentMessage';
31
32
  import { useProfile } from '../../hooks/use-appearances';
32
33
  import { useRuntimeState } from '../../state/runtime';
34
+ import { isValidInput } from '../../utils/agent-inputs';
33
35
  import { convertImageToBlob, downloadImage } from '../../utils/download-image';
34
36
  import ActionButton from '../ActionButton';
35
37
  export default function ShareActions(_a) {
36
38
  var _b;
37
39
  var props = __rest(_a, []);
38
40
  const { agent } = useCurrentAgent();
41
+ const { message } = useCurrentMessage();
39
42
  const sharing = useMemo(() => {
40
43
  var _a, _b;
41
44
  return (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.share)) === null || _b === void 0 ? void 0 : _b.initialValue;
42
45
  }, [agent]);
46
+ const params = useMemo(() => {
47
+ var _a;
48
+ return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(isValidInput).map((i) => { var _a, _b; return [((_a = i.label) === null || _a === void 0 ? void 0 : _a.trim()) || i.key, (_b = message.inputs) === null || _b === void 0 ? void 0 : _b[i.key]]; }).filter((i) => i[1]);
49
+ }, [agent.parameters, message.inputs]);
43
50
  const items = (_b = sharing === null || sharing === void 0 ? void 0 : sharing.items) === null || _b === void 0 ? void 0 : _b.map((item) => {
51
+ var _a, _b;
44
52
  const C = ShareActionsMap[item.to];
45
53
  if (!C)
46
54
  return null;
47
- return (_jsx(Box, { children: _jsx(C, {}) }));
55
+ return (_jsx(Box, { children: _jsx(C, { inputs: JSON.stringify(_.fromPairs(params), null, 2), shareAttach: {
56
+ shareAttachInputs: (_a = sharing === null || sharing === void 0 ? void 0 : sharing.shareAttachInputs) !== null && _a !== void 0 ? _a : false,
57
+ shareAttachUrl: (_b = sharing === null || sharing === void 0 ? void 0 : sharing.shareAttachUrl) !== null && _b !== void 0 ? _b : false,
58
+ } }) }));
48
59
  }).filter((i) => !!i);
49
60
  if (!(items === null || items === void 0 ? void 0 : items.length))
50
61
  return null;
@@ -54,30 +65,40 @@ const ShareActionsMap = {
54
65
  twitter: ShareTwitter,
55
66
  copy: ShareCopy,
56
67
  saveAs: ShareSave,
68
+ community: ShareCommunity,
57
69
  };
58
- function ShareTwitter() {
70
+ function ShareTwitter({ inputs, shareAttach, }) {
59
71
  var _a, _b, _c, _d, _e, _f, _g, _h;
60
72
  const { t } = useLocaleContext();
61
73
  const { message } = useCurrentMessage();
62
- const content = ((_c = (_b = (_a = message.outputs) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b.find((i) => i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[RuntimeOutputVariable.text]) ||
74
+ let content = ((_c = (_b = (_a = message.outputs) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b.find((i) => i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[RuntimeOutputVariable.text]) ||
63
75
  ((_h = (_g = (_f = (_e = (_d = message.outputs) === null || _d === void 0 ? void 0 : _d.objects) === null || _e === void 0 ? void 0 : _e.find((i) => { var _a; return (_a = i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _f === void 0 ? void 0 : _f[RuntimeOutputVariable.images]) === null || _g === void 0 ? void 0 : _g.at(0)) === null || _h === void 0 ? void 0 : _h.url);
64
76
  if (!content)
65
77
  return null;
66
- return (_jsx(StyledActionButton, { tip: t('socialShare.shareToX'), title: _jsx(Icon, { icon: "tabler:brand-x" }), href: withQuery('https://twitter.com/intent/tweet', {
78
+ if (shareAttach.shareAttachInputs) {
79
+ content += `\nInputs: ${inputs}`;
80
+ }
81
+ return (_jsx(StyledActionButton, { tip: t('socialShare.shareToX'), title: _jsx(Icon, { icon: "tabler:brand-x" }), target: "_blank", href: withQuery('https://twitter.com/intent/tweet', {
67
82
  text: content,
68
- url: window.location.href,
69
- }), target: '_blank' }));
83
+ url: shareAttach.shareAttachUrl ? window.location.href : undefined,
84
+ }) }));
70
85
  }
71
- function ShareCopy() {
86
+ function ShareCopy({ inputs, shareAttach, }) {
72
87
  var _a, _b, _c, _d, _e, _f, _g, _h;
73
88
  const { t } = useLocaleContext();
74
89
  const { message } = useCurrentMessage();
75
- const content = (_c = (_b = (_a = message.outputs) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b.find((i) => i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[RuntimeOutputVariable.text];
90
+ let content = (_c = (_b = (_a = message.outputs) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b.find((i) => i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[RuntimeOutputVariable.text];
76
91
  const image = (_h = (_g = (_f = (_e = (_d = message.outputs) === null || _d === void 0 ? void 0 : _d.objects) === null || _e === void 0 ? void 0 : _e.find((i) => { var _a; return (_a = i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _f === void 0 ? void 0 : _f[RuntimeOutputVariable.images]) === null || _g === void 0 ? void 0 : _g.at(0)) === null || _h === void 0 ? void 0 : _h.url;
77
92
  if (!content && !image)
78
93
  return null;
79
94
  return (_jsx(StyledActionButton, { autoReset: true, tip: t('copy'), tipSucceed: t('copied'), title: _jsx(Icon, { icon: "tabler:copy" }), titleSucceed: _jsx(Icon, { icon: "tabler:copy-check" }), onClick: () => __awaiter(this, void 0, void 0, function* () {
80
95
  if (content) {
96
+ if (shareAttach.shareAttachInputs) {
97
+ content += `\nInputs: ${inputs}`;
98
+ }
99
+ if (shareAttach.shareAttachUrl) {
100
+ content += `\nURL: ${window.location.href}`;
101
+ }
81
102
  window.navigator.clipboard.writeText(content);
82
103
  }
83
104
  else if (image) {
@@ -86,7 +107,7 @@ function ShareCopy() {
86
107
  }
87
108
  }) }));
88
109
  }
89
- function ShareSave() {
110
+ function ShareSave({ inputs, shareAttach, }) {
90
111
  var _a, _b, _c, _d, _e, _f, _g, _h;
91
112
  const { t } = useLocaleContext();
92
113
  const { message } = useCurrentMessage();
@@ -101,7 +122,13 @@ function ShareSave() {
101
122
  const { default: html2pdf } = yield import('html2pdf.js');
102
123
  if (content) {
103
124
  const element = document.createElement('div');
104
- element.innerText = content;
125
+ element.innerHTML = content;
126
+ if (shareAttach.shareAttachInputs) {
127
+ element.innerHTML += `<br/>Inputs: ${inputs}`;
128
+ }
129
+ if (shareAttach.shareAttachUrl) {
130
+ element.innerHTML += `<br/>URL: ${window.location.href}`;
131
+ }
105
132
  yield html2pdf()
106
133
  .set({
107
134
  margin: 1,
@@ -118,9 +145,30 @@ function ShareSave() {
118
145
  }
119
146
  }) }));
120
147
  }
148
+ function ShareCommunity({ inputs, shareAttach, }) {
149
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
150
+ const { t } = useLocaleContext();
151
+ const { message } = useCurrentMessage();
152
+ let content = (_d = (_c = (_b = (_a = message.outputs) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b.find((i) => i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[RuntimeOutputVariable.text]) !== null && _d !== void 0 ? _d : '';
153
+ const image = ((_k = (_j = (_h = (_g = (_f = (_e = message.outputs) === null || _e === void 0 ? void 0 : _e.objects) === null || _f === void 0 ? void 0 : _f.find) === null || _g === void 0 ? void 0 : _g.call(_f, (i) => { var _a; return (_a = i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _h === void 0 ? void 0 : _h[RuntimeOutputVariable.images]) === null || _j === void 0 ? void 0 : _j.map((i) => i.url)) !== null && _k !== void 0 ? _k : []).join(',');
154
+ if (!content && !image)
155
+ return null;
156
+ if (shareAttach.shareAttachInputs) {
157
+ content += `\nInputs: ${inputs}`;
158
+ }
159
+ if (shareAttach.shareAttachUrl) {
160
+ content += `\nURL: ${window.location.href}`;
161
+ }
162
+ return (_jsx(StyledActionButton, { tip: t('share to community'), title: _jsx(Icon, { icon: "tabler:share-2" }), target: "_blank", href: withQuery('https://community.arcblock.io/discussions/add?', {
163
+ boardId: 'aigne',
164
+ title: '[Share the generation from Aigne](Give your post a title...)',
165
+ content,
166
+ images: image,
167
+ }) }));
168
+ }
121
169
  const StyledActionButton = styled(ActionButton)(({ theme }) => theme.unstable_sx({
122
170
  fontSize: 'inherit',
123
171
  p: 0.5,
124
- minWidth: 0,
125
- minHeight: 0,
172
+ minWidth: '0 !important',
173
+ minHeight: '0 !important',
126
174
  }));