@ripperts/poco-agent-embed 0.1.2 → 0.1.3
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/README.md +1 -1
- package/index.js +65 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,4 +120,4 @@ export function AgentChat({ getAccessToken }: AgentChatProps) {
|
|
|
120
120
|
|
|
121
121
|
支持现代 Chrome、Edge、Firefox 和 Safari。Vue 2 项目可以正常接入,但不支持 Internet Explorer 11。
|
|
122
122
|
|
|
123
|
-
完整参数和安全配置请参阅 [Agent 外部嵌入文档](https://ai-agent.fsxgt.cn/docs/
|
|
123
|
+
完整参数和安全配置请参阅 [Agent 外部嵌入文档](https://ai-agent.fsxgt.cn/docs/getting-started/agent-embed)。
|
package/index.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
var MESSAGE_REQUEST_AUTH = "poco-agent-embed:request-auth";
|
|
19
19
|
var MESSAGE_AUTHENTICATE = "poco-agent-embed:authenticate";
|
|
20
20
|
var MESSAGE_ERROR = "poco-agent-embed:error";
|
|
21
|
+
var MESSAGE_DRAG = "poco-agent-embed:drag";
|
|
21
22
|
|
|
22
23
|
function trimTrailingSlash(value) {
|
|
23
24
|
return String(value || "").replace(/\/+$/, "");
|
|
@@ -114,6 +115,7 @@
|
|
|
114
115
|
? options.theme
|
|
115
116
|
: "system";
|
|
116
117
|
var query = new URLSearchParams({ channel: channel, theme: theme });
|
|
118
|
+
if (!target && options.draggable !== false) query.set("draggable", "1");
|
|
117
119
|
var iframe = document.createElement("iframe");
|
|
118
120
|
iframe.src =
|
|
119
121
|
baseUrl +
|
|
@@ -137,6 +139,7 @@
|
|
|
137
139
|
var container = document.createElement("div");
|
|
138
140
|
var button = null;
|
|
139
141
|
var updateViewportPosition = null;
|
|
142
|
+
var handleFrameDrag = null;
|
|
140
143
|
var openIcon = createIcon(options.openIcon, false);
|
|
141
144
|
var closeIcon = createIcon(options.closeIcon, true);
|
|
142
145
|
|
|
@@ -165,8 +168,6 @@
|
|
|
165
168
|
container.style.cssText = [
|
|
166
169
|
"position:fixed",
|
|
167
170
|
"width:min(420px,calc(100vw - 24px))",
|
|
168
|
-
"height:min(720px,calc(100dvh - 96px))",
|
|
169
|
-
"min-height:min(360px,calc(100dvh - 96px))",
|
|
170
171
|
"overflow:hidden",
|
|
171
172
|
"border:1px solid color-mix(in srgb,CanvasText 25%,transparent)",
|
|
172
173
|
"border-radius:16px",
|
|
@@ -201,10 +202,15 @@
|
|
|
201
202
|
var position = options.position || "bottom-right";
|
|
202
203
|
var vertical = position.indexOf("top") === 0 ? "top" : "bottom";
|
|
203
204
|
var horizontal = position.indexOf("left") > -1 ? "left" : "right";
|
|
204
|
-
|
|
205
|
+
var verticalOffset = vertical === "bottom" ? 100 : 20;
|
|
206
|
+
var popupAvailableHeight =
|
|
207
|
+
"calc(100dvh - " + (verticalOffset + 76) + "px)";
|
|
208
|
+
button.style[vertical] = verticalOffset + "px";
|
|
205
209
|
button.style[horizontal] = "20px";
|
|
206
|
-
container.style[vertical] = "
|
|
210
|
+
container.style[vertical] = verticalOffset + 64 + "px";
|
|
207
211
|
container.style[horizontal] = "20px";
|
|
212
|
+
container.style.height = "min(720px," + popupAvailableHeight + ")";
|
|
213
|
+
container.style.minHeight = "min(360px," + popupAvailableHeight + ")";
|
|
208
214
|
container.style.transformOrigin = vertical + " " + horizontal;
|
|
209
215
|
|
|
210
216
|
function anchorContainerToButton() {
|
|
@@ -255,6 +261,52 @@
|
|
|
255
261
|
anchorContainerToButton();
|
|
256
262
|
};
|
|
257
263
|
|
|
264
|
+
var frameDrag = null;
|
|
265
|
+
handleFrameDrag = function (data) {
|
|
266
|
+
if (data.phase === "start") {
|
|
267
|
+
var buttonRect = button.getBoundingClientRect();
|
|
268
|
+
var containerRect = container.getBoundingClientRect();
|
|
269
|
+
frameDrag = {
|
|
270
|
+
buttonLeft: buttonRect.left,
|
|
271
|
+
buttonTop: buttonRect.top,
|
|
272
|
+
containerLeft: containerRect.left,
|
|
273
|
+
containerTop: containerRect.top,
|
|
274
|
+
minX: 8 - Math.min(buttonRect.left, containerRect.left),
|
|
275
|
+
maxX:
|
|
276
|
+
window.innerWidth -
|
|
277
|
+
8 -
|
|
278
|
+
Math.max(buttonRect.right, containerRect.right),
|
|
279
|
+
minY: 8 - Math.min(buttonRect.top, containerRect.top),
|
|
280
|
+
maxY:
|
|
281
|
+
window.innerHeight -
|
|
282
|
+
8 -
|
|
283
|
+
Math.max(buttonRect.bottom, containerRect.bottom),
|
|
284
|
+
};
|
|
285
|
+
container.style.height = containerRect.height + "px";
|
|
286
|
+
container.style.minHeight = containerRect.height + "px";
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (!frameDrag) return;
|
|
290
|
+
if (data.phase === "move") {
|
|
291
|
+
var offsetX = Math.max(
|
|
292
|
+
frameDrag.minX,
|
|
293
|
+
Math.min(frameDrag.maxX, data.dx),
|
|
294
|
+
);
|
|
295
|
+
var offsetY = Math.max(
|
|
296
|
+
frameDrag.minY,
|
|
297
|
+
Math.min(frameDrag.maxY, data.dy),
|
|
298
|
+
);
|
|
299
|
+
button.style.left = frameDrag.buttonLeft + offsetX + "px";
|
|
300
|
+
button.style.top = frameDrag.buttonTop + offsetY + "px";
|
|
301
|
+
container.style.left = frameDrag.containerLeft + offsetX + "px";
|
|
302
|
+
container.style.top = frameDrag.containerTop + offsetY + "px";
|
|
303
|
+
container.style.bottom = "auto";
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
frameDrag = null;
|
|
307
|
+
anchorContainerToButton();
|
|
308
|
+
};
|
|
309
|
+
|
|
258
310
|
var dragState = null;
|
|
259
311
|
var suppressClickUntil = 0;
|
|
260
312
|
button.addEventListener("pointerdown", function (event) {
|
|
@@ -358,6 +410,15 @@
|
|
|
358
410
|
event.data.type === MESSAGE_REQUEST_AUTH
|
|
359
411
|
) {
|
|
360
412
|
authenticate();
|
|
413
|
+
} else if (
|
|
414
|
+
event.data.type === MESSAGE_DRAG &&
|
|
415
|
+
handleFrameDrag &&
|
|
416
|
+
options.draggable !== false &&
|
|
417
|
+
["start", "move", "end"].includes(event.data.phase) &&
|
|
418
|
+
Number.isFinite(event.data.dx) &&
|
|
419
|
+
Number.isFinite(event.data.dy)
|
|
420
|
+
) {
|
|
421
|
+
handleFrameDrag(event.data);
|
|
361
422
|
} else if (
|
|
362
423
|
event.data.type === MESSAGE_ERROR &&
|
|
363
424
|
typeof options.onError === "function"
|