@blocklet/pages-kit 0.2.346 → 0.2.347

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.
@@ -51,6 +51,7 @@ const types_1 = require("@blocklet/ai-runtime/types");
51
51
  const react_1 = require("@iconify/react");
52
52
  const material_1 = require("@mui/material");
53
53
  const file_saver_1 = require("file-saver");
54
+ const lodash_1 = __importDefault(require("lodash"));
54
55
  const react_2 = require("react");
55
56
  const ufo_1 = require("ufo");
56
57
  const locale_1 = require("../../../../locale");
@@ -58,21 +59,31 @@ const CurrentAgent_1 = require("../../contexts/CurrentAgent");
58
59
  const CurrentMessage_1 = require("../../contexts/CurrentMessage");
59
60
  const use_appearances_1 = require("../../hooks/use-appearances");
60
61
  const runtime_1 = require("../../state/runtime");
62
+ const agent_inputs_1 = require("../../utils/agent-inputs");
61
63
  const download_image_1 = require("../../utils/download-image");
62
64
  const ActionButton_1 = __importDefault(require("../ActionButton"));
63
65
  function ShareActions(_a) {
64
66
  var _b;
65
67
  var props = __rest(_a, []);
66
68
  const { agent } = (0, CurrentAgent_1.useCurrentAgent)();
69
+ const { message } = (0, CurrentMessage_1.useCurrentMessage)();
67
70
  const sharing = (0, react_2.useMemo)(() => {
68
71
  var _a, _b;
69
72
  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;
70
73
  }, [agent]);
74
+ const params = (0, react_2.useMemo)(() => {
75
+ var _a;
76
+ 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
+ }, [agent.parameters, message.inputs]);
71
78
  const items = (_b = sharing === null || sharing === void 0 ? void 0 : sharing.items) === null || _b === void 0 ? void 0 : _b.map((item) => {
79
+ var _a, _b;
72
80
  const C = ShareActionsMap[item.to];
73
81
  if (!C)
74
82
  return null;
75
- return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(C, {}) }));
83
+ return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(C, { inputs: JSON.stringify(lodash_1.default.fromPairs(params), null, 2), shareAttach: {
84
+ shareAttachInputs: (_a = sharing === null || sharing === void 0 ? void 0 : sharing.shareAttachInputs) !== null && _a !== void 0 ? _a : false,
85
+ shareAttachUrl: (_b = sharing === null || sharing === void 0 ? void 0 : sharing.shareAttachUrl) !== null && _b !== void 0 ? _b : false,
86
+ } }) }));
76
87
  }).filter((i) => !!i);
77
88
  if (!(items === null || items === void 0 ? void 0 : items.length))
78
89
  return null;
@@ -83,30 +94,40 @@ const ShareActionsMap = {
83
94
  twitter: ShareTwitter,
84
95
  copy: ShareCopy,
85
96
  saveAs: ShareSave,
97
+ community: ShareCommunity,
86
98
  };
87
- function ShareTwitter() {
99
+ function ShareTwitter({ inputs, shareAttach, }) {
88
100
  var _a, _b, _c, _d, _e, _f, _g, _h;
89
101
  const { t } = (0, locale_1.useLocaleContext)();
90
102
  const { message } = (0, CurrentMessage_1.useCurrentMessage)();
91
- 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]) ||
103
+ 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[types_1.RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[types_1.RuntimeOutputVariable.text]) ||
92
104
  ((_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);
93
105
  if (!content)
94
106
  return null;
95
- return ((0, jsx_runtime_1.jsx)(StyledActionButton, { tip: t('socialShare.shareToX'), title: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:brand-x" }), href: (0, ufo_1.withQuery)('https://twitter.com/intent/tweet', {
107
+ if (shareAttach.shareAttachInputs) {
108
+ content += `\nInputs: ${inputs}`;
109
+ }
110
+ 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', {
96
111
  text: content,
97
- url: window.location.href,
98
- }), target: '_blank' }));
112
+ url: shareAttach.shareAttachUrl ? window.location.href : undefined,
113
+ }) }));
99
114
  }
100
- function ShareCopy() {
115
+ function ShareCopy({ inputs, shareAttach, }) {
101
116
  var _a, _b, _c, _d, _e, _f, _g, _h;
102
117
  const { t } = (0, locale_1.useLocaleContext)();
103
118
  const { message } = (0, CurrentMessage_1.useCurrentMessage)();
104
- 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];
119
+ 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[types_1.RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[types_1.RuntimeOutputVariable.text];
105
120
  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;
106
121
  if (!content && !image)
107
122
  return null;
108
123
  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* () {
109
124
  if (content) {
125
+ if (shareAttach.shareAttachInputs) {
126
+ content += `\nInputs: ${inputs}`;
127
+ }
128
+ if (shareAttach.shareAttachUrl) {
129
+ content += `\nURL: ${window.location.href}`;
130
+ }
110
131
  window.navigator.clipboard.writeText(content);
111
132
  }
112
133
  else if (image) {
@@ -115,7 +136,7 @@ function ShareCopy() {
115
136
  }
116
137
  }) }));
117
138
  }
118
- function ShareSave() {
139
+ function ShareSave({ inputs, shareAttach, }) {
119
140
  var _a, _b, _c, _d, _e, _f, _g, _h;
120
141
  const { t } = (0, locale_1.useLocaleContext)();
121
142
  const { message } = (0, CurrentMessage_1.useCurrentMessage)();
@@ -130,7 +151,13 @@ function ShareSave() {
130
151
  const { default: html2pdf } = yield Promise.resolve().then(() => __importStar(require('html2pdf.js')));
131
152
  if (content) {
132
153
  const element = document.createElement('div');
133
- element.innerText = content;
154
+ element.innerHTML = content;
155
+ if (shareAttach.shareAttachInputs) {
156
+ element.innerHTML += `<br/>Inputs: ${inputs}`;
157
+ }
158
+ if (shareAttach.shareAttachUrl) {
159
+ element.innerHTML += `<br/>URL: ${window.location.href}`;
160
+ }
134
161
  yield html2pdf()
135
162
  .set({
136
163
  margin: 1,
@@ -147,9 +174,30 @@ function ShareSave() {
147
174
  }
148
175
  }) }));
149
176
  }
177
+ function ShareCommunity({ inputs, shareAttach, }) {
178
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
179
+ const { t } = (0, locale_1.useLocaleContext)();
180
+ const { message } = (0, CurrentMessage_1.useCurrentMessage)();
181
+ 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[types_1.RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[types_1.RuntimeOutputVariable.text]) !== null && _d !== void 0 ? _d : '';
182
+ 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[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)) !== null && _k !== void 0 ? _k : []).join(',');
183
+ if (!content && !image)
184
+ return null;
185
+ if (shareAttach.shareAttachInputs) {
186
+ content += `\nInputs: ${inputs}`;
187
+ }
188
+ if (shareAttach.shareAttachUrl) {
189
+ content += `\nURL: ${window.location.href}`;
190
+ }
191
+ return ((0, jsx_runtime_1.jsx)(StyledActionButton, { tip: t('share to community'), title: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:share-2" }), target: "_blank", href: (0, ufo_1.withQuery)('https://community.arcblock.io/discussions/add?', {
192
+ boardId: 'aigne',
193
+ title: '[Share the generation from Aigne](Give your post a title...)',
194
+ content,
195
+ images: image,
196
+ }) }));
197
+ }
150
198
  const StyledActionButton = (0, material_1.styled)(ActionButton_1.default)(({ theme }) => theme.unstable_sx({
151
199
  fontSize: 'inherit',
152
200
  p: 0.5,
153
- minWidth: 0,
154
- minHeight: 0,
201
+ minWidth: '0 !important',
202
+ minHeight: '0 !important',
155
203
  }));