@blocklet/pages-kit 0.2.374 → 0.2.375

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,7 +23,6 @@ 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 { fromPairs, identity, pickBy } from 'lodash';
27
26
  import { useMemo } from 'react';
28
27
  import { joinURL, withQuery } from 'ufo';
29
28
  import { useLocaleContext } from '../../../../locale';
@@ -44,16 +43,16 @@ export default function ShareActions(_a) {
44
43
  var _a, _b;
45
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;
46
45
  }, [agent]);
47
- const params = useMemo(() => {
46
+ const inputs = useMemo(() => {
48
47
  var _a;
49
- 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]);
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]).map(([k, v]) => `${k}: ${v}`).join('\n')) || '';
50
49
  }, [agent.parameters, message.inputs]);
51
50
  const items = (_b = sharing === null || sharing === void 0 ? void 0 : sharing.items) === null || _b === void 0 ? void 0 : _b.map((item) => {
52
51
  var _a, _b;
53
52
  const C = ShareActionsMap[item.to];
54
53
  if (!C)
55
54
  return null;
56
- return (_jsx(Box, { children: _jsx(C, { inputs: JSON.stringify(fromPairs(params), null, 2), shareAttach: {
55
+ return (_jsx(Box, { children: _jsx(C, { inputs: inputs, shareAttach: {
57
56
  shareAttachInputs: (_a = sharing === null || sharing === void 0 ? void 0 : sharing.shareAttachInputs) !== null && _a !== void 0 ? _a : false,
58
57
  shareAttachUrl: (_b = sharing === null || sharing === void 0 ? void 0 : sharing.shareAttachUrl) !== null && _b !== void 0 ? _b : false,
59
58
  } }) }));
@@ -70,25 +69,33 @@ const ShareActionsMap = {
70
69
  link: ShareLink,
71
70
  };
72
71
  function ShareTwitter({ inputs, shareAttach, }) {
73
- var _a, _b, _c, _d, _e, _f, _g, _h;
74
72
  const { t } = useLocaleContext();
75
73
  const { message } = useCurrentMessage();
76
74
  const { link } = useCurrentLink();
77
- 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]) ||
78
- ((_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);
79
- if (!content)
80
- return null;
81
- if (shareAttach.shareAttachInputs) {
82
- content += `\nInputs: ${inputs}`;
83
- }
84
- // 如果 content 长度超过 100,截断
85
- if (content.length > 100) {
86
- content = `${content.slice(0, 100)}...`;
87
- }
88
- return (_jsx(StyledActionButton, { tip: t('socialShare.shareToX'), title: _jsx(Icon, { icon: "tabler:brand-x" }), target: "_blank", href: withQuery('https://twitter.com/intent/tweet', {
89
- text: content,
75
+ const query = useMemo(() => {
76
+ var _a, _b, _c, _d, _e, _f, _g, _h;
77
+ 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]) ||
78
+ ((_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);
79
+ if (!content)
80
+ return null;
81
+ const texts = [];
82
+ if (shareAttach.shareAttachInputs) {
83
+ texts.push(inputs);
84
+ }
85
+ texts.push(content);
86
+ let text = texts.join('\n\n');
87
+ // 如果 content 长度超过 100,截断
88
+ if (text.length > 250) {
89
+ text = `${text.slice(0, 250)}...`;
90
+ }
91
+ return {
92
+ text,
90
93
  url: link,
91
- }) }));
94
+ };
95
+ }, []);
96
+ if (!query)
97
+ return null;
98
+ return (_jsx(StyledActionButton, { tip: t('socialShare.shareToX'), title: _jsx(Icon, { icon: "tabler:brand-x" }), target: "_blank", href: withQuery('https://twitter.com/intent/tweet', query) }));
92
99
  }
93
100
  function ShareLink() {
94
101
  const { t } = useLocaleContext();
@@ -104,19 +111,21 @@ function ShareCopy({ inputs, shareAttach, }) {
104
111
  const { t } = useLocaleContext();
105
112
  const { message } = useCurrentMessage();
106
113
  const { link } = useCurrentLink();
107
- 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];
114
+ 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];
108
115
  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;
109
116
  if (!content && !image)
110
117
  return null;
111
118
  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* () {
112
119
  if (content) {
113
- if (shareAttach.shareAttachInputs) {
114
- content += `\nInputs: ${inputs}`;
115
- }
120
+ const texts = [];
116
121
  if (shareAttach.shareAttachUrl) {
117
- content += `\nURL: ${link}`;
122
+ texts.push(link);
123
+ }
124
+ if (shareAttach.shareAttachInputs) {
125
+ texts.push(inputs);
118
126
  }
119
- window.navigator.clipboard.writeText(content);
127
+ texts.push(content);
128
+ window.navigator.clipboard.writeText(texts.filter(Boolean).join('\n\n'));
120
129
  }
121
130
  else if (image) {
122
131
  const imageBlob = yield convertImageToBlob(yield downloadImage({ url: image }));
@@ -140,13 +149,13 @@ function ShareSave({ inputs, shareAttach, }) {
140
149
  const { default: html2pdf } = yield import('html2pdf.js');
141
150
  if (content) {
142
151
  const element = document.createElement('div');
143
- element.innerHTML = content;
144
- if (shareAttach.shareAttachInputs) {
145
- element.innerHTML += `<br/>Inputs: ${inputs}`;
146
- }
147
152
  if (shareAttach.shareAttachUrl) {
148
- element.innerHTML += `<br/>URL: ${link}`;
153
+ element.innerHTML += `<p><a href="{${link}}">${link}</a></p>`;
149
154
  }
155
+ if (shareAttach.shareAttachInputs) {
156
+ element.innerHTML += `<p><blockquote>${inputs}</blockquote></p>`;
157
+ }
158
+ element.innerHTML += `<p>${content}</p>`;
150
159
  yield html2pdf()
151
160
  .set({
152
161
  margin: 1,
@@ -164,28 +173,32 @@ function ShareSave({ inputs, shareAttach, }) {
164
173
  }) }));
165
174
  }
166
175
  function ShareCommunity({ inputs, shareAttach, }) {
167
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
168
176
  const { t } = useLocaleContext();
169
177
  const { message } = useCurrentMessage();
170
178
  const { link } = useCurrentLink();
171
- const { agent } = useCurrentAgent();
172
- 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 : '';
173
- 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(',');
174
- content = `[Sharing from ${(_l = agent === null || agent === void 0 ? void 0 : agent.project) === null || _l === void 0 ? void 0 : _l.name}]: ${window.location.href}\n ${content}`;
175
- if (!content && !image)
176
- return null;
177
- if (shareAttach.shareAttachInputs) {
178
- content += `\nInputs: ${inputs}`;
179
- }
180
- if (shareAttach.shareAttachUrl) {
181
- content += `\nURL: ${link}`;
182
- }
183
- return (_jsx(StyledActionButton, { tip: t('socialShare.shareToCommunity'), title: _jsx(CommunityIcon, {}), target: "_blank", href: withQuery('https://community.arcblock.io/discussions/add?', pickBy({
179
+ const query = useMemo(() => {
180
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
181
+ const text = (_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 : '';
182
+ const images = (_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);
183
+ let content = '';
184
+ if (shareAttach.shareAttachUrl) {
185
+ content += `${link}\n\n`;
186
+ }
187
+ if (shareAttach.shareAttachInputs) {
188
+ content += `> ${inputs}\n\n`;
189
+ }
190
+ if (images) {
191
+ content += images.map((image) => `![image](${image})`).join('\n');
192
+ }
193
+ content += text;
194
+ return {
184
195
  boardId: 'aigne',
185
- title: `${((_m = message.inputs) === null || _m === void 0 ? void 0 : _m.question) || ''}`,
196
+ format: 'markdown',
197
+ title: `${((_k = message.inputs) === null || _k === void 0 ? void 0 : _k.question) || inputs}`,
186
198
  content,
187
- images: image,
188
- }, identity)) }));
199
+ };
200
+ }, [inputs, shareAttach]);
201
+ return (_jsx(StyledActionButton, { tip: t('socialShare.shareToCommunity'), title: _jsx(CommunityIcon, {}), target: "_blank", href: withQuery('https://community.arcblock.io/discussions/add?', query) }));
189
202
  }
190
203
  const StyledActionButton = styled(ActionButton)(({ theme }) => theme.unstable_sx({
191
204
  fontSize: 'inherit',