@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.
- package/lib/cjs/builtin/async/ai-runtime/components/ShareActions/index.js +60 -47
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +60 -47
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -52,7 +52,6 @@ const types_1 = require("@blocklet/ai-runtime/types");
|
|
|
52
52
|
const react_1 = require("@iconify/react");
|
|
53
53
|
const material_1 = require("@mui/material");
|
|
54
54
|
const file_saver_1 = require("file-saver");
|
|
55
|
-
const lodash_1 = require("lodash");
|
|
56
55
|
const react_2 = require("react");
|
|
57
56
|
const ufo_1 = require("ufo");
|
|
58
57
|
const locale_1 = require("../../../../locale");
|
|
@@ -73,16 +72,16 @@ function ShareActions(_a) {
|
|
|
73
72
|
var _a, _b;
|
|
74
73
|
return (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.RuntimeOutputVariable.share)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
75
74
|
}, [agent]);
|
|
76
|
-
const
|
|
75
|
+
const inputs = (0, react_2.useMemo)(() => {
|
|
77
76
|
var _a;
|
|
78
|
-
return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(agent_inputs_1.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]);
|
|
77
|
+
return ((_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(agent_inputs_1.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')) || '';
|
|
79
78
|
}, [agent.parameters, message.inputs]);
|
|
80
79
|
const items = (_b = sharing === null || sharing === void 0 ? void 0 : sharing.items) === null || _b === void 0 ? void 0 : _b.map((item) => {
|
|
81
80
|
var _a, _b;
|
|
82
81
|
const C = ShareActionsMap[item.to];
|
|
83
82
|
if (!C)
|
|
84
83
|
return null;
|
|
85
|
-
return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(C, { inputs:
|
|
84
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(C, { inputs: inputs, shareAttach: {
|
|
86
85
|
shareAttachInputs: (_a = sharing === null || sharing === void 0 ? void 0 : sharing.shareAttachInputs) !== null && _a !== void 0 ? _a : false,
|
|
87
86
|
shareAttachUrl: (_b = sharing === null || sharing === void 0 ? void 0 : sharing.shareAttachUrl) !== null && _b !== void 0 ? _b : false,
|
|
88
87
|
} }) }));
|
|
@@ -99,25 +98,33 @@ const ShareActionsMap = {
|
|
|
99
98
|
link: ShareLink,
|
|
100
99
|
};
|
|
101
100
|
function ShareTwitter({ inputs, shareAttach, }) {
|
|
102
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
103
101
|
const { t } = (0, locale_1.useLocaleContext)();
|
|
104
102
|
const { message } = (0, CurrentMessage_1.useCurrentMessage)();
|
|
105
103
|
const { link } = useCurrentLink();
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
104
|
+
const query = (0, react_2.useMemo)(() => {
|
|
105
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
106
|
+
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[types_1.RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[types_1.RuntimeOutputVariable.text]) ||
|
|
107
|
+
((_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[types_1.RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _f === void 0 ? void 0 : _f[types_1.RuntimeOutputVariable.images]) === null || _g === void 0 ? void 0 : _g.at(0)) === null || _h === void 0 ? void 0 : _h.url);
|
|
108
|
+
if (!content)
|
|
109
|
+
return null;
|
|
110
|
+
const texts = [];
|
|
111
|
+
if (shareAttach.shareAttachInputs) {
|
|
112
|
+
texts.push(inputs);
|
|
113
|
+
}
|
|
114
|
+
texts.push(content);
|
|
115
|
+
let text = texts.join('\n\n');
|
|
116
|
+
// 如果 content 长度超过 100,截断
|
|
117
|
+
if (text.length > 250) {
|
|
118
|
+
text = `${text.slice(0, 250)}...`;
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
text,
|
|
119
122
|
url: link,
|
|
120
|
-
}
|
|
123
|
+
};
|
|
124
|
+
}, []);
|
|
125
|
+
if (!query)
|
|
126
|
+
return null;
|
|
127
|
+
return ((0, jsx_runtime_1.jsx)(StyledActionButton, { tip: t('socialShare.shareToX'), title: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:brand-x" }), target: "_blank", href: (0, ufo_1.withQuery)('https://twitter.com/intent/tweet', query) }));
|
|
121
128
|
}
|
|
122
129
|
function ShareLink() {
|
|
123
130
|
const { t } = (0, locale_1.useLocaleContext)();
|
|
@@ -133,19 +140,21 @@ function ShareCopy({ inputs, shareAttach, }) {
|
|
|
133
140
|
const { t } = (0, locale_1.useLocaleContext)();
|
|
134
141
|
const { message } = (0, CurrentMessage_1.useCurrentMessage)();
|
|
135
142
|
const { link } = useCurrentLink();
|
|
136
|
-
|
|
143
|
+
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[types_1.RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[types_1.RuntimeOutputVariable.text];
|
|
137
144
|
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[types_1.RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _f === void 0 ? void 0 : _f[types_1.RuntimeOutputVariable.images]) === null || _g === void 0 ? void 0 : _g.at(0)) === null || _h === void 0 ? void 0 : _h.url;
|
|
138
145
|
if (!content && !image)
|
|
139
146
|
return null;
|
|
140
147
|
return ((0, jsx_runtime_1.jsx)(StyledActionButton, { autoReset: true, tip: t('copy'), tipSucceed: t('copied'), title: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:copy" }), titleSucceed: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:copy-check" }), onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
141
148
|
if (content) {
|
|
142
|
-
|
|
143
|
-
content += `\nInputs: ${inputs}`;
|
|
144
|
-
}
|
|
149
|
+
const texts = [];
|
|
145
150
|
if (shareAttach.shareAttachUrl) {
|
|
146
|
-
|
|
151
|
+
texts.push(link);
|
|
152
|
+
}
|
|
153
|
+
if (shareAttach.shareAttachInputs) {
|
|
154
|
+
texts.push(inputs);
|
|
147
155
|
}
|
|
148
|
-
|
|
156
|
+
texts.push(content);
|
|
157
|
+
window.navigator.clipboard.writeText(texts.filter(Boolean).join('\n\n'));
|
|
149
158
|
}
|
|
150
159
|
else if (image) {
|
|
151
160
|
const imageBlob = yield (0, download_image_1.convertImageToBlob)(yield (0, download_image_1.downloadImage)({ url: image }));
|
|
@@ -169,13 +178,13 @@ function ShareSave({ inputs, shareAttach, }) {
|
|
|
169
178
|
const { default: html2pdf } = yield Promise.resolve().then(() => __importStar(require('html2pdf.js')));
|
|
170
179
|
if (content) {
|
|
171
180
|
const element = document.createElement('div');
|
|
172
|
-
element.innerHTML = content;
|
|
173
|
-
if (shareAttach.shareAttachInputs) {
|
|
174
|
-
element.innerHTML += `<br/>Inputs: ${inputs}`;
|
|
175
|
-
}
|
|
176
181
|
if (shareAttach.shareAttachUrl) {
|
|
177
|
-
element.innerHTML += `<
|
|
182
|
+
element.innerHTML += `<p><a href="{${link}}">${link}</a></p>`;
|
|
178
183
|
}
|
|
184
|
+
if (shareAttach.shareAttachInputs) {
|
|
185
|
+
element.innerHTML += `<p><blockquote>${inputs}</blockquote></p>`;
|
|
186
|
+
}
|
|
187
|
+
element.innerHTML += `<p>${content}</p>`;
|
|
179
188
|
yield html2pdf()
|
|
180
189
|
.set({
|
|
181
190
|
margin: 1,
|
|
@@ -193,28 +202,32 @@ function ShareSave({ inputs, shareAttach, }) {
|
|
|
193
202
|
}) }));
|
|
194
203
|
}
|
|
195
204
|
function ShareCommunity({ inputs, shareAttach, }) {
|
|
196
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
197
205
|
const { t } = (0, locale_1.useLocaleContext)();
|
|
198
206
|
const { message } = (0, CurrentMessage_1.useCurrentMessage)();
|
|
199
207
|
const { link } = useCurrentLink();
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
208
|
+
const query = (0, react_2.useMemo)(() => {
|
|
209
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
210
|
+
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[types_1.RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[types_1.RuntimeOutputVariable.text]) !== null && _d !== void 0 ? _d : '';
|
|
211
|
+
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[types_1.RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _h === void 0 ? void 0 : _h[types_1.RuntimeOutputVariable.images]) === null || _j === void 0 ? void 0 : _j.map((i) => i.url);
|
|
212
|
+
let content = '';
|
|
213
|
+
if (shareAttach.shareAttachUrl) {
|
|
214
|
+
content += `${link}\n\n`;
|
|
215
|
+
}
|
|
216
|
+
if (shareAttach.shareAttachInputs) {
|
|
217
|
+
content += `> ${inputs}\n\n`;
|
|
218
|
+
}
|
|
219
|
+
if (images) {
|
|
220
|
+
content += images.map((image) => ``).join('\n');
|
|
221
|
+
}
|
|
222
|
+
content += text;
|
|
223
|
+
return {
|
|
213
224
|
boardId: 'aigne',
|
|
214
|
-
|
|
225
|
+
format: 'markdown',
|
|
226
|
+
title: `${((_k = message.inputs) === null || _k === void 0 ? void 0 : _k.question) || inputs}`,
|
|
215
227
|
content,
|
|
216
|
-
|
|
217
|
-
|
|
228
|
+
};
|
|
229
|
+
}, [inputs, shareAttach]);
|
|
230
|
+
return ((0, jsx_runtime_1.jsx)(StyledActionButton, { tip: t('socialShare.shareToCommunity'), title: (0, jsx_runtime_1.jsx)(Community_1.default, {}), target: "_blank", href: (0, ufo_1.withQuery)('https://community.arcblock.io/discussions/add?', query) }));
|
|
218
231
|
}
|
|
219
232
|
const StyledActionButton = (0, material_1.styled)(ActionButton_1.default)(({ theme }) => theme.unstable_sx({
|
|
220
233
|
fontSize: 'inherit',
|