@blocklet/pages-kit 0.2.305 → 0.2.306
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/ActionButton.js +6 -6
- package/lib/cjs/builtin/async/ai-runtime/components/ShareActions/index.js +153 -0
- package/lib/cjs/builtin/async/ai-runtime/index.js +5 -1
- package/lib/cjs/builtin/async/ai-runtime/locales/index.js +2 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +11 -8
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGalleryItem/index.js +2 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +38 -2
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +4 -2
- package/lib/cjs/builtin/async/ai-runtime/state/agent.js +3 -1
- package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +1 -2
- package/lib/cjs/builtin/async/ai-runtime/utils/download-image.js +41 -0
- package/lib/cjs/components/CustomComponentRenderer/DevProvider.js +26 -0
- package/lib/cjs/components/CustomComponentRenderer/index.js +8 -5
- package/lib/cjs/utils/builtin.js +1 -0
- package/lib/cjs/utils/inject-global-components.js +5 -0
- package/lib/esm/builtin/async/ai-runtime/components/ActionButton.js +6 -6
- package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +124 -0
- package/lib/esm/builtin/async/ai-runtime/index.js +2 -0
- package/lib/esm/builtin/async/ai-runtime/locales/index.js +2 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +11 -8
- package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGalleryItem/index.js +2 -1
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +39 -3
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +4 -2
- package/lib/esm/builtin/async/ai-runtime/state/agent.js +3 -1
- package/lib/esm/builtin/async/ai-runtime/state/runtime.js +1 -2
- package/lib/esm/builtin/async/ai-runtime/utils/download-image.js +36 -0
- package/lib/esm/components/CustomComponentRenderer/DevProvider.js +21 -0
- package/lib/esm/components/CustomComponentRenderer/index.js +8 -5
- package/lib/esm/utils/builtin.js +1 -0
- package/lib/esm/utils/inject-global-components.js +2 -0
- package/lib/types/builtin/async/ai-runtime/components/ActionButton.d.ts +2 -1
- package/lib/types/builtin/async/ai-runtime/components/ShareActions/index.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/index.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/utils/download-image.d.ts +4 -0
- package/lib/types/components/CustomComponentRenderer/DevProvider.d.ts +9 -0
- package/lib/types/components/CustomComponentRenderer/index.d.ts +1 -1
- package/lib/types/utils/builtin.d.ts +1 -0
- package/package.json +9 -6
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageActions.js +0 -72
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageActions.js +0 -66
- package/lib/types/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageActions.d.ts +0 -4
|
@@ -30,29 +30,29 @@ const react_2 = require("react");
|
|
|
30
30
|
const LoadingButton_1 = __importDefault(require("./LoadingButton"));
|
|
31
31
|
function ActionButton(_a) {
|
|
32
32
|
var { tip, tipSucceed, title, titleSucceed, icon, iconSucceed, autoReset, placement = 'top' } = _a, props = __rest(_a, ["tip", "tipSucceed", "title", "titleSucceed", "icon", "iconSucceed", "autoReset", "placement"]);
|
|
33
|
-
const [
|
|
33
|
+
const [active, setActive] = (0, react_2.useState)(false);
|
|
34
34
|
const [error, setError] = (0, react_2.useState)();
|
|
35
35
|
const timer = (0, react_2.useRef)();
|
|
36
36
|
const onClose = () => {
|
|
37
37
|
setError(undefined);
|
|
38
38
|
if (autoReset) {
|
|
39
39
|
timer.current = window.setTimeout(() => {
|
|
40
|
-
|
|
40
|
+
setActive(false);
|
|
41
41
|
}, 3000);
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
const onOpen = () => {
|
|
45
45
|
clearTimeout(timer.current);
|
|
46
46
|
};
|
|
47
|
-
const realIcon =
|
|
48
|
-
const toolTipTitleText = error ? (0, jsx_runtime_1.jsx)(material_1.Box, { color: "error", children: error.message }) : (
|
|
49
|
-
const buttonText =
|
|
47
|
+
const realIcon = active ? iconSucceed : icon;
|
|
48
|
+
const toolTipTitleText = error ? (0, jsx_runtime_1.jsx)(material_1.Box, { color: "error", children: error.message }) : (active && tipSucceed) || tip;
|
|
49
|
+
const buttonText = active ? titleSucceed : title;
|
|
50
50
|
return ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: toolTipTitleText, disableInteractive: true, placement: placement, onClose: onClose, onOpen: onOpen, children: (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, Object.assign({ startIcon: realIcon && (typeof realIcon === 'string' ? (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: realIcon }) : realIcon), loadingPosition: realIcon ? 'start' : undefined }, props, { onClick: (e) => __awaiter(this, void 0, void 0, function* () {
|
|
51
51
|
if (!props.onClick)
|
|
52
52
|
return;
|
|
53
53
|
try {
|
|
54
54
|
yield props.onClick(e);
|
|
55
|
-
|
|
55
|
+
setActive(true);
|
|
56
56
|
}
|
|
57
57
|
catch (error) {
|
|
58
58
|
setError(error);
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
35
|
+
var t = {};
|
|
36
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
37
|
+
t[p] = s[p];
|
|
38
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
39
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
40
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
41
|
+
t[p[i]] = s[p[i]];
|
|
42
|
+
}
|
|
43
|
+
return t;
|
|
44
|
+
};
|
|
45
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
|
+
};
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
50
|
+
const types_1 = require("@blocklet/ai-runtime/types");
|
|
51
|
+
const react_1 = require("@iconify/react");
|
|
52
|
+
const material_1 = require("@mui/material");
|
|
53
|
+
const file_saver_1 = require("file-saver");
|
|
54
|
+
const react_2 = require("react");
|
|
55
|
+
const ufo_1 = require("ufo");
|
|
56
|
+
const locale_1 = require("../../../../locale");
|
|
57
|
+
const CurrentAgent_1 = require("../../contexts/CurrentAgent");
|
|
58
|
+
const CurrentMessage_1 = require("../../contexts/CurrentMessage");
|
|
59
|
+
const runtime_1 = require("../../state/runtime");
|
|
60
|
+
const download_image_1 = require("../../utils/download-image");
|
|
61
|
+
const ActionButton_1 = __importDefault(require("../ActionButton"));
|
|
62
|
+
function ShareActions(_a) {
|
|
63
|
+
var _b;
|
|
64
|
+
var props = __rest(_a, []);
|
|
65
|
+
const { agent } = (0, CurrentAgent_1.useCurrentAgent)();
|
|
66
|
+
const sharing = (0, react_2.useMemo)(() => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
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;
|
|
69
|
+
}, [agent]);
|
|
70
|
+
const items = (_b = sharing === null || sharing === void 0 ? void 0 : sharing.items) === null || _b === void 0 ? void 0 : _b.map((item) => {
|
|
71
|
+
const C = ShareActionsMap[item.to];
|
|
72
|
+
if (!C)
|
|
73
|
+
return null;
|
|
74
|
+
return (0, jsx_runtime_1.jsx)(C, {});
|
|
75
|
+
}).filter((i) => !!i);
|
|
76
|
+
if (!(items === null || items === void 0 ? void 0 : items.length))
|
|
77
|
+
return null;
|
|
78
|
+
return (0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({}, props, { children: items }));
|
|
79
|
+
}
|
|
80
|
+
exports.default = ShareActions;
|
|
81
|
+
const ShareActionsMap = {
|
|
82
|
+
twitter: ShareTwitter,
|
|
83
|
+
copy: ShareCopy,
|
|
84
|
+
saveAs: ShareSave,
|
|
85
|
+
};
|
|
86
|
+
function ShareTwitter() {
|
|
87
|
+
var _a, _b, _c, _d, _e, _f;
|
|
88
|
+
const { t } = (0, locale_1.useLocaleContext)();
|
|
89
|
+
const { message } = (0, CurrentMessage_1.useCurrentMessage)();
|
|
90
|
+
const content = ((_a = message.result) === null || _a === void 0 ? void 0 : _a.content) ||
|
|
91
|
+
((_f = (_e = (_d = (_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.objects) === null || _c === void 0 ? void 0 : _c.find((i) => { var _a; return (_a = i.data[types_1.RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _d === void 0 ? void 0 : _d.data[types_1.RuntimeOutputVariable.images]) === null || _e === void 0 ? void 0 : _e.at(0)) === null || _f === void 0 ? void 0 : _f.url);
|
|
92
|
+
if (!content)
|
|
93
|
+
return null;
|
|
94
|
+
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', {
|
|
95
|
+
text: content,
|
|
96
|
+
url: window.location.href,
|
|
97
|
+
}), target: '_blank' }));
|
|
98
|
+
}
|
|
99
|
+
function ShareCopy() {
|
|
100
|
+
var _a, _b, _c, _d, _e, _f;
|
|
101
|
+
const { t } = (0, locale_1.useLocaleContext)();
|
|
102
|
+
const { message } = (0, CurrentMessage_1.useCurrentMessage)();
|
|
103
|
+
const content = (_a = message.result) === null || _a === void 0 ? void 0 : _a.content;
|
|
104
|
+
const image = (_f = (_e = (_d = (_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.objects) === null || _c === void 0 ? void 0 : _c.find((i) => { var _a; return (_a = i.data[types_1.RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _d === void 0 ? void 0 : _d.data[types_1.RuntimeOutputVariable.images]) === null || _e === void 0 ? void 0 : _e.at(0)) === null || _f === void 0 ? void 0 : _f.url;
|
|
105
|
+
if (!content && !image)
|
|
106
|
+
return null;
|
|
107
|
+
return ((0, jsx_runtime_1.jsx)(StyledActionButton, { 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* () {
|
|
108
|
+
if (content) {
|
|
109
|
+
window.navigator.clipboard.writeText(content);
|
|
110
|
+
}
|
|
111
|
+
else if (image) {
|
|
112
|
+
const imageBlob = yield (0, download_image_1.convertImageToBlob)(yield (0, download_image_1.downloadImage)({ url: image }));
|
|
113
|
+
window.navigator.clipboard.write([new ClipboardItem({ 'image/png': imageBlob })]);
|
|
114
|
+
}
|
|
115
|
+
}) }));
|
|
116
|
+
}
|
|
117
|
+
function ShareSave() {
|
|
118
|
+
var _a, _b, _c, _d, _e, _f;
|
|
119
|
+
const { t } = (0, locale_1.useLocaleContext)();
|
|
120
|
+
const { message } = (0, CurrentMessage_1.useCurrentMessage)();
|
|
121
|
+
const { agent, appearancePage } = (0, runtime_1.useRuntimeState)();
|
|
122
|
+
const content = (_a = message.result) === null || _a === void 0 ? void 0 : _a.content;
|
|
123
|
+
const image = (_f = (_e = (_d = (_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.objects) === null || _c === void 0 ? void 0 : _c.find((i) => { var _a; return (_a = i.data[types_1.RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _d === void 0 ? void 0 : _d.data[types_1.RuntimeOutputVariable.images]) === null || _e === void 0 ? void 0 : _e.at(0)) === null || _f === void 0 ? void 0 : _f.url;
|
|
124
|
+
if (!content && !image)
|
|
125
|
+
return null;
|
|
126
|
+
return ((0, jsx_runtime_1.jsx)(StyledActionButton, { tip: t('save'), tipSucceed: t('saved'), title: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:file" }), titleSucceed: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:file-check" }), onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
const { default: html2pdf } = yield Promise.resolve().then(() => __importStar(require('html2pdf.js')));
|
|
129
|
+
if (content) {
|
|
130
|
+
const element = document.createElement('div');
|
|
131
|
+
element.innerText = content;
|
|
132
|
+
yield html2pdf()
|
|
133
|
+
.set({
|
|
134
|
+
margin: 1,
|
|
135
|
+
filename: `${(appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) || agent.name || agent.id} - ${message.taskId}.pdf`,
|
|
136
|
+
image: { type: 'jpeg', quality: 0.98 },
|
|
137
|
+
html2canvas: { scale: 2 },
|
|
138
|
+
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' },
|
|
139
|
+
})
|
|
140
|
+
.from(element)
|
|
141
|
+
.save();
|
|
142
|
+
}
|
|
143
|
+
else if (image) {
|
|
144
|
+
(0, file_saver_1.saveAs)(image, `${(appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) || agent.name || agent.id}.png`);
|
|
145
|
+
}
|
|
146
|
+
}) }));
|
|
147
|
+
}
|
|
148
|
+
const StyledActionButton = (0, material_1.styled)(ActionButton_1.default)(({ theme }) => theme.unstable_sx({
|
|
149
|
+
fontSize: 'inherit',
|
|
150
|
+
p: 0.5,
|
|
151
|
+
minWidth: 0,
|
|
152
|
+
minHeight: 0,
|
|
153
|
+
}));
|
|
@@ -17,9 +17,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.PhotoGalleryItem = exports.ChatOutput = exports.SimpleOutput = exports.AutoForm = exports.PhotoGallery = exports.SimpleChat = exports.SimplePage = exports.ChatBotButton = exports.Runtime = void 0;
|
|
20
|
+
exports.PhotoGalleryItem = exports.ChatOutput = exports.SimpleOutput = exports.AutoForm = exports.PhotoGallery = exports.SimpleChat = exports.SimplePage = exports.ChatBotButton = exports.Runtime = exports.CurrentMessageProvider = exports.CurrentAgentProvider = void 0;
|
|
21
21
|
__exportStar(require("./contexts/CurrentAgent"), exports);
|
|
22
|
+
var CurrentAgent_1 = require("./contexts/CurrentAgent");
|
|
23
|
+
Object.defineProperty(exports, "CurrentAgentProvider", { enumerable: true, get: function () { return __importDefault(CurrentAgent_1).default; } });
|
|
22
24
|
__exportStar(require("./contexts/CurrentMessage"), exports);
|
|
25
|
+
var CurrentMessage_1 = require("./contexts/CurrentMessage");
|
|
26
|
+
Object.defineProperty(exports, "CurrentMessageProvider", { enumerable: true, get: function () { return __importDefault(CurrentMessage_1).default; } });
|
|
23
27
|
__exportStar(require("./state/runtime"), exports);
|
|
24
28
|
__exportStar(require("./state/session"), exports);
|
|
25
29
|
var Runtime_1 = require("./runtime/Runtime");
|
|
@@ -45,6 +45,7 @@ exports.translations = {
|
|
|
45
45
|
contentPlaceholder: 'Write anything...',
|
|
46
46
|
cancel: 'Cancel',
|
|
47
47
|
save: 'Save',
|
|
48
|
+
saved: 'Saved',
|
|
48
49
|
edit: 'Edit',
|
|
49
50
|
chat: 'Chat',
|
|
50
51
|
subscribeNow: 'Subscribe Now',
|
|
@@ -138,6 +139,7 @@ exports.translations = {
|
|
|
138
139
|
contentPlaceholder: '写点什么吧...',
|
|
139
140
|
cancel: '取消',
|
|
140
141
|
save: '保存',
|
|
142
|
+
saved: '已保存',
|
|
141
143
|
edit: '编辑',
|
|
142
144
|
chat: '对话',
|
|
143
145
|
subscribeNow: '立即订阅',
|
|
@@ -48,8 +48,8 @@ const react_1 = __importStar(require("react"));
|
|
|
48
48
|
const ux_1 = require("../../../../arcblock/ux");
|
|
49
49
|
const session_1 = require("../../../../session");
|
|
50
50
|
const MarkdownRenderer_1 = __importDefault(require("../../components/MarkdownRenderer"));
|
|
51
|
+
const ShareActions_1 = __importDefault(require("../../components/ShareActions"));
|
|
51
52
|
const runtime_1 = require("../../state/runtime");
|
|
52
|
-
const MessageActions_1 = __importDefault(require("./MessageActions"));
|
|
53
53
|
const MessageErrorView_1 = __importDefault(require("./MessageErrorView"));
|
|
54
54
|
const MessageMetadataRenderer_1 = __importDefault(require("./MessageMetadataRenderer"));
|
|
55
55
|
const MessageItemView = (0, react_1.memo)((_a) => {
|
|
@@ -119,6 +119,7 @@ function AgentMessage({ message, hideAvatar }) {
|
|
|
119
119
|
const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('sm'));
|
|
120
120
|
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, did: (_d = globalThis.blocklet) === null || _d === void 0 ? void 0 : _d.appId, variant: "circle", shape: "circle", src: (_e = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.logo) === null || _e === void 0 ? void 0 : _e.url }) })), (0, jsx_runtime_1.jsxs)(material_1.Box, { flex: 1, width: 0, children: [!hideAvatar && ((0, jsx_runtime_1.jsxs)(MessageUserName, { children: [appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name, (0, jsx_runtime_1.jsx)(MessageTime, { time: message.createdAt })] })), (0, jsx_runtime_1.jsxs)(react_1.default.Suspense, { children: [showMainMessage ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { placement: "right-start", slotProps: {
|
|
121
121
|
popper: {
|
|
122
|
+
disablePortal: true,
|
|
122
123
|
modifiers: [
|
|
123
124
|
{
|
|
124
125
|
name: 'offset',
|
|
@@ -129,14 +130,16 @@ function AgentMessage({ message, hideAvatar }) {
|
|
|
129
130
|
],
|
|
130
131
|
},
|
|
131
132
|
tooltip: {
|
|
132
|
-
sx: {
|
|
133
|
-
bgcolor: 'white',
|
|
134
|
-
boxShadow: '0px 4px 8px 0px rgba(3, 7, 18, 0.08)',
|
|
135
|
-
border: '1px solid rgba(229, 231, 235, 1)',
|
|
136
|
-
p: 0.5,
|
|
137
|
-
},
|
|
133
|
+
sx: { p: 0, bgcolor: 'white' },
|
|
138
134
|
},
|
|
139
|
-
}, title: !isMessageLoading &&
|
|
135
|
+
}, title: !isMessageLoading &&
|
|
136
|
+
((_f = message.result) === null || _f === void 0 ? void 0 : _f.content) && ((0, jsx_runtime_1.jsx)(ShareActions_1.default, { sx: {
|
|
137
|
+
fontSize: '1rem',
|
|
138
|
+
boxShadow: '0px 4px 8px 0px rgba(3, 7, 18, 0.08)',
|
|
139
|
+
border: '1px solid rgba(229, 231, 235, 1)',
|
|
140
|
+
borderRadius: 1,
|
|
141
|
+
p: 0.25,
|
|
142
|
+
} })), children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 1, className: "message-response", children: [(_h = (_g = message.result) === null || _g === void 0 ? void 0 : _g.messages) === null || _h === void 0 ? void 0 : _h.map((childMsg, index) => {
|
|
140
143
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
141
144
|
return ((_a = childMsg.result) === null || _a === void 0 ? void 0 : _a.content) ? ((0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { className: isMessageLoading &&
|
|
142
145
|
!((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) &&
|
|
@@ -23,6 +23,7 @@ const ux_1 = require("../../../../arcblock/ux");
|
|
|
23
23
|
const locale_1 = require("../../../../locale");
|
|
24
24
|
const session_1 = require("../../../../session");
|
|
25
25
|
const ActionButton_1 = __importDefault(require("../../components/ActionButton"));
|
|
26
|
+
const ShareActions_1 = __importDefault(require("../../components/ShareActions"));
|
|
26
27
|
const UserInfo_1 = __importDefault(require("../../components/UserInfo"));
|
|
27
28
|
const CurrentAgent_1 = require("../../contexts/CurrentAgent");
|
|
28
29
|
const CurrentMessage_1 = require("../../contexts/CurrentMessage");
|
|
@@ -151,5 +152,5 @@ function PromptDialog(_a) {
|
|
|
151
152
|
window.navigator.clipboard.writeText(parameters === null || parameters === void 0 ? void 0 : parameters.question);
|
|
152
153
|
}, sx: {
|
|
153
154
|
borderRadius,
|
|
154
|
-
} }) })] })] }) })] })));
|
|
155
|
+
} }) }), (0, jsx_runtime_1.jsx)(ShareActions_1.default, { direction: "row", justifyContent: "flex-end", sx: { mt: 2 } })] })] }) })] })));
|
|
155
156
|
}
|
|
@@ -46,13 +46,14 @@ const CustomComponentRenderer_1 = __importDefault(require("../../../../../compon
|
|
|
46
46
|
const session_1 = require("../../../../session");
|
|
47
47
|
const SimpleHeader_1 = __importDefault(require("../../components/Header/SimpleHeader"));
|
|
48
48
|
const SimpleLayout_1 = __importDefault(require("../../components/Layout/SimpleLayout"));
|
|
49
|
+
const MarkdownRenderer_1 = __importDefault(require("../../components/MarkdownRenderer"));
|
|
49
50
|
const ScrollView_1 = __importDefault(require("../../components/ScrollView"));
|
|
50
51
|
const UserInfo_1 = __importDefault(require("../../components/UserInfo"));
|
|
51
52
|
const CurrentAgent_1 = __importStar(require("../../contexts/CurrentAgent"));
|
|
52
53
|
const CurrentMessage_1 = __importDefault(require("../../contexts/CurrentMessage"));
|
|
53
54
|
const runtime_1 = require("../../state/runtime");
|
|
54
55
|
const session_2 = require("../../state/session");
|
|
55
|
-
const MessageSuggestedQuestions_1 =
|
|
56
|
+
const MessageSuggestedQuestions_1 = __importStar(require("../ChatOutput/MessageSuggestedQuestions"));
|
|
56
57
|
function SimpleChat({ primaryColor, scrollViewProps = { scroll: 'window', initialScrollBehavior: 'auto' }, }) {
|
|
57
58
|
(0, session_2.useSessionState)({ autoLoad: true });
|
|
58
59
|
const inheritedTheme = (0, material_1.useTheme)();
|
|
@@ -97,8 +98,9 @@ function AgentInputRender(_a) {
|
|
|
97
98
|
function OutputView(_a) {
|
|
98
99
|
var props = __rest(_a, []);
|
|
99
100
|
const messages = (0, session_2.useSessionState)()((s) => s.messages);
|
|
101
|
+
const loading = (0, session_2.useSessionState)()((s) => s.loading);
|
|
100
102
|
const lastMessage = messages === null || messages === void 0 ? void 0 : messages.at(-1);
|
|
101
|
-
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2 }, props, { children: [messages === null || messages === void 0 ? void 0 : messages.map((message) => (0, jsx_runtime_1.jsx)(OutputItemView, { message: message }, message.taskId)), lastMessage && (0, jsx_runtime_1.jsx)(SuggestedQuestionsView, { message: lastMessage })] })));
|
|
103
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2 }, props, { children: [(0, jsx_runtime_1.jsx)(OpeningMessageView, {}), messages === null || messages === void 0 ? void 0 : messages.map((message) => (0, jsx_runtime_1.jsx)(OutputItemView, { message: message }, message.taskId)), lastMessage && (0, jsx_runtime_1.jsx)(SuggestedQuestionsView, { message: lastMessage }), !loading && !(messages === null || messages === void 0 ? void 0 : messages.length) && (0, jsx_runtime_1.jsx)(OpeningQuestionsView, {})] })));
|
|
102
104
|
}
|
|
103
105
|
const OutputItemView = (0, react_1.memo)(({ message }) => {
|
|
104
106
|
var _a, _b, _c, _d, _e;
|
|
@@ -124,3 +126,37 @@ function SuggestedQuestionsView({ message }) {
|
|
|
124
126
|
execute({ aid, parameters: Object.assign(Object.assign({}, message.parameters), { question: item.question }) });
|
|
125
127
|
} })) : null }));
|
|
126
128
|
}
|
|
129
|
+
const OpeningMessageView = (0, react_1.memo)(() => {
|
|
130
|
+
var _a, _b;
|
|
131
|
+
const { childAgentId, appearancePage } = (0, runtime_1.useRuntimeState)();
|
|
132
|
+
const { agent } = (0, CurrentAgent_1.useCurrentAgent)({ agentId: childAgentId });
|
|
133
|
+
const openingMessage = (0, react_1.useMemo)(() => {
|
|
134
|
+
var _a, _b;
|
|
135
|
+
return (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.RuntimeOutputVariable.openingMessage)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
136
|
+
}, [agent]);
|
|
137
|
+
if (!(openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.message))
|
|
138
|
+
return null;
|
|
139
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: (appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) || agent.name, did: (_a = globalThis.blocklet) === null || _a === void 0 ? void 0 : _a.appId, avatar: (_b = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.logo) === null || _b === void 0 ? void 0 : _b.url, alignItems: "flex-start", children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
140
|
+
bgcolor: 'rgba(229, 231, 235, 1)',
|
|
141
|
+
borderRadius: 1,
|
|
142
|
+
borderTopLeftRadius: 2,
|
|
143
|
+
px: 2,
|
|
144
|
+
py: 1,
|
|
145
|
+
mt: 0.5,
|
|
146
|
+
mr: 5,
|
|
147
|
+
}, children: (0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { children: openingMessage.message }) }) }) }));
|
|
148
|
+
});
|
|
149
|
+
function OpeningQuestionsView() {
|
|
150
|
+
const { childAgentId } = (0, runtime_1.useRuntimeState)();
|
|
151
|
+
const { execute } = (0, runtime_1.useRuntimeState)();
|
|
152
|
+
const { aid, agent } = (0, CurrentAgent_1.useCurrentAgent)({ agentId: childAgentId });
|
|
153
|
+
const openingQuestions = (0, react_1.useMemo)(() => {
|
|
154
|
+
var _a, _b, _c, _d;
|
|
155
|
+
return (_d = (_c = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.RuntimeOutputVariable.openingQuestions)) === null || _b === void 0 ? void 0 : _b.initialValue) === null || _c === void 0 ? void 0 : _c.items) === null || _d === void 0 ? void 0 : _d.filter((i) => !!i.title);
|
|
156
|
+
}, [agent]);
|
|
157
|
+
if (!(openingQuestions === null || openingQuestions === void 0 ? void 0 : openingQuestions.length))
|
|
158
|
+
return null;
|
|
159
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { ml: 6.5, mr: 2.5, children: (0, jsx_runtime_1.jsx)(material_1.Stack, { gap: 1, children: openingQuestions.map((item) => {
|
|
160
|
+
return ((0, jsx_runtime_1.jsx)(MessageSuggestedQuestions_1.MessageSuggestedQuestion, { onClick: () => execute({ aid, parameters: Object.assign(Object.assign({}, item.parameters), { question: item.parameters.question || item.title }) }), children: item.title }, item.id));
|
|
161
|
+
}) }) }));
|
|
162
|
+
}
|
|
@@ -6,14 +6,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
7
|
const material_1 = require("@mui/material");
|
|
8
8
|
const MarkdownRenderer_1 = __importDefault(require("../../components/MarkdownRenderer"));
|
|
9
|
+
const ShareActions_1 = __importDefault(require("../../components/ShareActions"));
|
|
9
10
|
const CurrentMessage_1 = require("../../contexts/CurrentMessage");
|
|
10
11
|
const MessageErrorView_1 = __importDefault(require("../ChatOutput/MessageErrorView"));
|
|
11
12
|
const MessageMetadataRenderer_1 = __importDefault(require("../ChatOutput/MessageMetadataRenderer"));
|
|
12
13
|
function SimpleOutput() {
|
|
13
|
-
var _a, _b;
|
|
14
|
+
var _a, _b, _c;
|
|
14
15
|
const { message } = (0, CurrentMessage_1.useCurrentMessage)();
|
|
15
16
|
const objects = (_a = message.result) === null || _a === void 0 ? void 0 : _a.objects;
|
|
16
17
|
const { error } = message;
|
|
17
|
-
|
|
18
|
+
const isMessageLoading = (message.loading || !message.result) && !message.error;
|
|
19
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 2, boxShadow: 1, borderRadius: 1, p: 2, children: [(0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { children: (_b = message.result) === null || _b === void 0 ? void 0 : _b.content }), error && (0, jsx_runtime_1.jsx)(MessageErrorView_1.default, { error: error }), objects === null || objects === void 0 ? void 0 : objects.map((item) => (0, jsx_runtime_1.jsx)(MessageMetadataRenderer_1.default, { object: item.data })), !isMessageLoading && ((_c = message.result) === null || _c === void 0 ? void 0 : _c.content) && ((0, jsx_runtime_1.jsx)(ShareActions_1.default, { direction: "row", justifyContent: "flex-end", sx: { mt: 2 } }))] }));
|
|
18
20
|
}
|
|
19
21
|
exports.default = SimpleOutput;
|
|
@@ -13,6 +13,7 @@ exports.useAgentState = exports.createAgentState = void 0;
|
|
|
13
13
|
const zustand_1 = require("zustand");
|
|
14
14
|
const immer_1 = require("zustand/middleware/immer");
|
|
15
15
|
const agent_1 = require("../api/agent");
|
|
16
|
+
const Runtime_1 = require("../contexts/Runtime");
|
|
16
17
|
const zustand_2 = require("../utils/zustand");
|
|
17
18
|
const createAgentState = ({ aid, working, agent }) => {
|
|
18
19
|
const key = working ? `${aid}-working` : aid;
|
|
@@ -46,7 +47,8 @@ exports.createAgentState = createAgentState;
|
|
|
46
47
|
const LOADING_TASKS = {};
|
|
47
48
|
function useAgentState({ aid, working }) {
|
|
48
49
|
var _a;
|
|
49
|
-
const
|
|
50
|
+
const runtimeState = (0, Runtime_1.useRuntimeContext)();
|
|
51
|
+
const state = (0, exports.createAgentState)({ aid, working: working !== null && working !== void 0 ? working : runtimeState.working })();
|
|
50
52
|
if (!state.agent) {
|
|
51
53
|
if (state.error)
|
|
52
54
|
throw state.error;
|
|
@@ -44,8 +44,7 @@ function useRuntimeState() {
|
|
|
44
44
|
}), [authSession.user, exec, working, login]);
|
|
45
45
|
const appearancePage = (0, react_1.useMemo)(() => {
|
|
46
46
|
var _a, _b;
|
|
47
|
-
|
|
48
|
-
return initialValue;
|
|
47
|
+
return (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.RuntimeOutputVariable.appearancePage)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
49
48
|
}, [agent]);
|
|
50
49
|
const childAgentId = (0, react_1.useMemo)(() => {
|
|
51
50
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.convertImageToBlob = exports.downloadImage = void 0;
|
|
13
|
+
function downloadImage(_a) {
|
|
14
|
+
return __awaiter(this, arguments, void 0, function* ({ url }) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const image = new Image();
|
|
17
|
+
image.src = url;
|
|
18
|
+
image.onload = () => resolve(image);
|
|
19
|
+
image.onerror = (e) => reject(e);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.downloadImage = downloadImage;
|
|
24
|
+
function convertImageToBlob(image) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
const c = document.createElement('canvas');
|
|
28
|
+
const ctx = c.getContext('2d');
|
|
29
|
+
c.width = image.naturalWidth;
|
|
30
|
+
c.height = image.naturalHeight;
|
|
31
|
+
ctx.drawImage(image, 0, 0);
|
|
32
|
+
c.toBlob((blob) => {
|
|
33
|
+
if (blob)
|
|
34
|
+
resolve(blob);
|
|
35
|
+
else
|
|
36
|
+
reject(new Error('Failed to get image'));
|
|
37
|
+
}, 'image/png', 1);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.convertImageToBlob = convertImageToBlob;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.useDev = exports.DevProvider = void 0;
|
|
15
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
|
+
const react_1 = require("react");
|
|
17
|
+
const devContext = (0, react_1.createContext)(undefined);
|
|
18
|
+
function DevProvider(_a) {
|
|
19
|
+
var { dev } = _a, props = __rest(_a, ["dev"]);
|
|
20
|
+
return (0, jsx_runtime_1.jsx)(devContext.Provider, Object.assign({ value: dev }, props));
|
|
21
|
+
}
|
|
22
|
+
exports.DevProvider = DevProvider;
|
|
23
|
+
function useDev() {
|
|
24
|
+
return (0, react_1.useContext)(devContext);
|
|
25
|
+
}
|
|
26
|
+
exports.useDev = useDev;
|
|
@@ -29,13 +29,15 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
29
29
|
const material_1 = require("@mui/material");
|
|
30
30
|
const react_error_boundary_1 = require("react-error-boundary");
|
|
31
31
|
const property_1 = require("../../utils/property");
|
|
32
|
+
const DevProvider_1 = require("./DevProvider");
|
|
32
33
|
const state_1 = require("./state");
|
|
33
34
|
__exportStar(require("./state"), exports);
|
|
34
35
|
const MAXIMUM_RENDER_STACK_SIZE = 20;
|
|
35
36
|
function CustomComponentRenderer(_a) {
|
|
36
37
|
var _b;
|
|
37
|
-
var props = __rest(_a, []);
|
|
38
|
-
|
|
38
|
+
var { dev } = _a, props = __rest(_a, ["dev"]);
|
|
39
|
+
const inheritedDev = (0, DevProvider_1.useDev)();
|
|
40
|
+
return ((0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { fallbackRender: ErrorView, resetKeys: [Date.now()], children: (0, jsx_runtime_1.jsx)(DevProvider_1.DevProvider, { dev: dev !== null && dev !== void 0 ? dev : inheritedDev, children: (0, jsx_runtime_1.jsx)(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId })) }) }));
|
|
39
41
|
}
|
|
40
42
|
exports.default = CustomComponentRenderer;
|
|
41
43
|
function ErrorView({ error }) {
|
|
@@ -43,10 +45,11 @@ function ErrorView({ error }) {
|
|
|
43
45
|
}
|
|
44
46
|
function ComponentRenderer(_a) {
|
|
45
47
|
var { renderCount = 0 } = _a, props = __rest(_a, ["renderCount"]);
|
|
48
|
+
const dev = (0, DevProvider_1.useDev)();
|
|
46
49
|
if (renderCount > MAXIMUM_RENDER_STACK_SIZE) {
|
|
47
50
|
throw new Error('Maximum render stack size exceeded');
|
|
48
51
|
}
|
|
49
|
-
const component = (0, state_1.useComponent)(props);
|
|
52
|
+
const component = (0, state_1.useComponent)(Object.assign(Object.assign({}, props), { dev }));
|
|
50
53
|
if (component === null || component === void 0 ? void 0 : component.error) {
|
|
51
54
|
return (0, jsx_runtime_1.jsx)(ErrorView, { error: component.error });
|
|
52
55
|
}
|
|
@@ -55,11 +58,11 @@ function ComponentRenderer(_a) {
|
|
|
55
58
|
}
|
|
56
59
|
return null;
|
|
57
60
|
}
|
|
58
|
-
function Renderer({ renderCount, Component, locale, props,
|
|
61
|
+
function Renderer({ renderCount, Component, locale, props, }) {
|
|
59
62
|
const componentProps = Object.fromEntries(Object.entries(props).map(([key, val]) => {
|
|
60
63
|
return [
|
|
61
64
|
key,
|
|
62
|
-
(val === null || val === void 0 ? void 0 : val.type) === property_1.RenderNestedComponent ? ((0, jsx_runtime_1.jsx)(ComponentRenderer, { locale: locale, renderCount: renderCount, componentId: val.componentId, properties: val.properties, props: val.props
|
|
65
|
+
(val === null || val === void 0 ? void 0 : val.type) === property_1.RenderNestedComponent ? ((0, jsx_runtime_1.jsx)(ComponentRenderer, { locale: locale, renderCount: renderCount, componentId: val.componentId, properties: val.properties, props: val.props })) : (val),
|
|
63
66
|
];
|
|
64
67
|
}));
|
|
65
68
|
return (0, jsx_runtime_1.jsx)(Component, Object.assign({ locale: locale }, componentProps));
|
package/lib/cjs/utils/builtin.js
CHANGED
|
@@ -40,6 +40,7 @@ const stream = __importStar(require("../builtin/stream"));
|
|
|
40
40
|
const utils = __importStar(require("../builtin/utils"));
|
|
41
41
|
const zustandMiddlewareImmer = __importStar(require("../builtin/zustand/middleware/immer"));
|
|
42
42
|
exports.BuiltinModules = {
|
|
43
|
+
'@blocklet/pages-kit/builtin/pages-kit': {},
|
|
43
44
|
'@blocklet/pages-kit/builtin/dayjs': dayjs,
|
|
44
45
|
'@blocklet/pages-kit/builtin/utils': utils,
|
|
45
46
|
'@blocklet/pages-kit/builtin/call': call,
|
|
@@ -22,6 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
29
|
const arcblockUx = __importStar(require("../builtin/arcblock/ux"));
|
|
27
30
|
const aiRuntime = __importStar(require("../builtin/async/ai-runtime"));
|
|
@@ -47,11 +50,13 @@ const stream = __importStar(require("../builtin/stream"));
|
|
|
47
50
|
const utils = __importStar(require("../builtin/utils"));
|
|
48
51
|
const zustand = __importStar(require("../builtin/zustand"));
|
|
49
52
|
const zustandMiddlewareImmer = __importStar(require("../builtin/zustand/middleware/immer"));
|
|
53
|
+
const CustomComponentRenderer_1 = __importDefault(require("../components/CustomComponentRenderer"));
|
|
50
54
|
const builtin_1 = require("../types/builtin");
|
|
51
55
|
function injectGlobalComponents() {
|
|
52
56
|
const win = window;
|
|
53
57
|
win[builtin_1.BuiltinModulesGlobalVariableName] = {
|
|
54
58
|
modules: {
|
|
59
|
+
'@blocklet/pages-kit/builtin/pages-kit': { CustomComponentRenderer: CustomComponentRenderer_1.default },
|
|
55
60
|
'@blocklet/pages-kit/builtin/dayjs': dayjs,
|
|
56
61
|
'@blocklet/pages-kit/builtin/utils': utils,
|
|
57
62
|
'@blocklet/pages-kit/builtin/react': react,
|
|
@@ -25,29 +25,29 @@ import { useRef, useState } from 'react';
|
|
|
25
25
|
import LoadingButton from './LoadingButton';
|
|
26
26
|
export default function ActionButton(_a) {
|
|
27
27
|
var { tip, tipSucceed, title, titleSucceed, icon, iconSucceed, autoReset, placement = 'top' } = _a, props = __rest(_a, ["tip", "tipSucceed", "title", "titleSucceed", "icon", "iconSucceed", "autoReset", "placement"]);
|
|
28
|
-
const [
|
|
28
|
+
const [active, setActive] = useState(false);
|
|
29
29
|
const [error, setError] = useState();
|
|
30
30
|
const timer = useRef();
|
|
31
31
|
const onClose = () => {
|
|
32
32
|
setError(undefined);
|
|
33
33
|
if (autoReset) {
|
|
34
34
|
timer.current = window.setTimeout(() => {
|
|
35
|
-
|
|
35
|
+
setActive(false);
|
|
36
36
|
}, 3000);
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
const onOpen = () => {
|
|
40
40
|
clearTimeout(timer.current);
|
|
41
41
|
};
|
|
42
|
-
const realIcon =
|
|
43
|
-
const toolTipTitleText = error ? _jsx(Box, { color: "error", children: error.message }) : (
|
|
44
|
-
const buttonText =
|
|
42
|
+
const realIcon = active ? iconSucceed : icon;
|
|
43
|
+
const toolTipTitleText = error ? _jsx(Box, { color: "error", children: error.message }) : (active && tipSucceed) || tip;
|
|
44
|
+
const buttonText = active ? titleSucceed : title;
|
|
45
45
|
return (_jsx(Tooltip, { title: toolTipTitleText, disableInteractive: true, placement: placement, onClose: onClose, onOpen: onOpen, children: _jsx("span", { children: _jsx(LoadingButton, Object.assign({ startIcon: realIcon && (typeof realIcon === 'string' ? _jsx(Icon, { icon: realIcon }) : realIcon), loadingPosition: realIcon ? 'start' : undefined }, props, { onClick: (e) => __awaiter(this, void 0, void 0, function* () {
|
|
46
46
|
if (!props.onClick)
|
|
47
47
|
return;
|
|
48
48
|
try {
|
|
49
49
|
yield props.onClick(e);
|
|
50
|
-
|
|
50
|
+
setActive(true);
|
|
51
51
|
}
|
|
52
52
|
catch (error) {
|
|
53
53
|
setError(error);
|