@vite-plugin-opencode-assistant/components 1.0.26 → 1.0.27

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.
Files changed (33) hide show
  1. package/es/index.d.ts +1 -1
  2. package/es/index.js +1 -1
  3. package/es/open-code-widget/composables/use-inspector.js +118 -79
  4. package/es/open-code-widget/composables/use-persist-state.d.ts +24 -0
  5. package/es/open-code-widget/composables/use-persist-state.js +59 -0
  6. package/es/open-code-widget/src/components/FloatingBubble/FloatingBubble-sfc.css +1 -1
  7. package/es/open-code-widget/src/components/FloatingBubble/FloatingBubble.vue.d.ts +2 -2
  8. package/es/open-code-widget/src/components/FloatingBubble/FloatingBubble.vue.js +37 -21
  9. package/es/open-code-widget/src/components/Trigger.vue.d.ts +0 -2
  10. package/es/open-code-widget/src/components/Trigger.vue.js +10 -27
  11. package/es/open-code-widget/src/context.d.ts +3 -0
  12. package/es/open-code-widget/src/index-sfc.css +1 -1
  13. package/es/open-code-widget/src/index.vue.d.ts +10 -10
  14. package/es/open-code-widget/src/index.vue.js +107 -29
  15. package/lib/@vite-plugin-opencode-assistant/components.cjs.js +304 -140
  16. package/lib/@vite-plugin-opencode-assistant/components.es.js +305 -141
  17. package/lib/components.css +2 -2
  18. package/lib/index.d.ts +1 -1
  19. package/lib/index.js +1 -1
  20. package/lib/open-code-widget/composables/use-inspector.js +118 -79
  21. package/lib/open-code-widget/composables/use-persist-state.d.ts +24 -0
  22. package/lib/open-code-widget/composables/use-persist-state.js +78 -0
  23. package/lib/open-code-widget/src/components/FloatingBubble/FloatingBubble-sfc.css +1 -1
  24. package/lib/open-code-widget/src/components/FloatingBubble/FloatingBubble.vue.d.ts +2 -2
  25. package/lib/open-code-widget/src/components/FloatingBubble/FloatingBubble.vue.js +37 -21
  26. package/lib/open-code-widget/src/components/Trigger.vue.d.ts +0 -2
  27. package/lib/open-code-widget/src/components/Trigger.vue.js +10 -27
  28. package/lib/open-code-widget/src/context.d.ts +3 -0
  29. package/lib/open-code-widget/src/index-sfc.css +1 -1
  30. package/lib/open-code-widget/src/index.vue.d.ts +10 -10
  31. package/lib/open-code-widget/src/index.vue.js +106 -28
  32. package/lib/web-types.json +1 -1
  33. package/package.json +2 -2
@@ -19,7 +19,7 @@ var __spreadValues = (a, b) => {
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import "./index-sfc.css";
21
21
  import { useCssVars as _useCssVars, defineComponent as _defineComponent } from "vue";
22
- import { useSlots, toRef, ref, watch, computed } from "vue";
22
+ import { useSlots, toRef, ref, watch, computed, nextTick, onMounted, onUnmounted } from "vue";
23
23
  import Frame from "./components/Frame.vue.js";
24
24
  import Header from "./components/Header.vue.js";
25
25
  import SelectHint from "./components/SelectHint.vue.js";
@@ -30,6 +30,7 @@ import { useSelection } from "../composables/use-selection";
30
30
  import { useSession } from "../composables/use-session";
31
31
  import { useWidget } from "../composables/use-widget";
32
32
  import { useInspector } from "../composables/use-inspector";
33
+ import { usePersistState } from "../composables/use-persist-state";
33
34
  import { provideOpenCodeWidgetContext } from "./context";
34
35
  const __vue_sfc__ = /* @__PURE__ */ _defineComponent(__spreadProps(__spreadValues({}, {
35
36
  name: "OpencodeWidget"
@@ -106,17 +107,26 @@ const __vue_sfc__ = /* @__PURE__ */ _defineComponent(__spreadProps(__spreadValue
106
107
  var _a;
107
108
  (_a = frameRef.value) == null ? void 0 : _a.sendMessageToIframe(type, data);
108
109
  };
110
+ const localSessionListCollapsed = ref(props.sessionListCollapsed);
111
+ const minimized = ref(false);
112
+ const promptDockVisible = ref(true);
113
+ const isRestoring = ref(true);
114
+ const iframeLoaded = ref(false);
115
+ const syncStateToIframe = () => {
116
+ if (!iframeLoaded.value) return;
117
+ sendMessageToIframe("prompt-dock-visibility-change", { visible: promptDockVisible.value });
118
+ sendMessageToIframe("minimize-state-change", { minimized: minimized.value });
119
+ };
109
120
  const handleFrameLoaded = () => {
110
121
  emit("frame-loaded");
122
+ iframeLoaded.value = true;
123
+ syncStateToIframe();
111
124
  };
112
125
  __expose({
113
126
  showNotification,
114
127
  showConfirmDialog,
115
128
  sendMessageToIframe
116
129
  });
117
- const localSessionListCollapsed = ref(props.sessionListCollapsed);
118
- const minimized = ref(false);
119
- const promptDockVisible = ref(true);
120
130
  watch(
121
131
  () => props.sessionListCollapsed,
122
132
  (val) => {
@@ -213,6 +223,53 @@ const __vue_sfc__ = /* @__PURE__ */ _defineComponent(__spreadProps(__spreadValue
213
223
  emit("toggle-select-mode", false);
214
224
  }
215
225
  });
226
+ const bubbleOffset = ref(void 0);
227
+ usePersistState({
228
+ open: toRef(props, "open"),
229
+ minimized,
230
+ promptDockVisible,
231
+ bubbleOffset,
232
+ theme: toRef(props, "theme"),
233
+ sessionListCollapsed: localSessionListCollapsed,
234
+ onRestore: (state) => {
235
+ if (state.open !== void 0 && state.open !== props.open) {
236
+ emit("update:open", state.open);
237
+ emit("toggle", state.open);
238
+ }
239
+ if (state.minimized !== void 0) {
240
+ minimized.value = state.minimized;
241
+ }
242
+ if (state.bubbleOffset !== void 0) {
243
+ const bubbleSize = 44;
244
+ const margin = 10;
245
+ const maxX = window.innerWidth - bubbleSize - margin;
246
+ const maxY = window.innerHeight - bubbleSize - margin;
247
+ bubbleOffset.value = {
248
+ x: Math.max(margin, Math.min(state.bubbleOffset.x, maxX)),
249
+ y: Math.max(margin, Math.min(state.bubbleOffset.y, maxY))
250
+ };
251
+ }
252
+ if (state.theme !== void 0 && state.theme !== props.theme) {
253
+ emit("update:theme", state.theme);
254
+ emit("toggle-theme", state.theme);
255
+ }
256
+ if (state.sessionListCollapsed !== void 0 && state.sessionListCollapsed !== props.sessionListCollapsed) {
257
+ localSessionListCollapsed.value = state.sessionListCollapsed;
258
+ emit("update:sessionListCollapsed", state.sessionListCollapsed);
259
+ }
260
+ if (state.promptDockVisible !== void 0) {
261
+ promptDockVisible.value = state.promptDockVisible;
262
+ } else if (minimized.value) {
263
+ promptDockVisible.value = false;
264
+ }
265
+ nextTick(() => {
266
+ syncStateToIframe();
267
+ setTimeout(() => {
268
+ isRestoring.value = false;
269
+ }, 50);
270
+ });
271
+ }
272
+ });
216
273
  const handleToggleMinimize = () => {
217
274
  minimized.value = !minimized.value;
218
275
  promptDockVisible.value = !minimized.value;
@@ -223,15 +280,33 @@ const __vue_sfc__ = /* @__PURE__ */ _defineComponent(__spreadProps(__spreadValue
223
280
  promptDockVisible.value = !promptDockVisible.value;
224
281
  sendMessageToIframe("prompt-dock-visibility-change", { visible: promptDockVisible.value });
225
282
  };
226
- const bubbleOffset = ref(void 0);
283
+ const windowWidth = ref(typeof window !== "undefined" ? window.innerWidth : 0);
284
+ const windowHeight = ref(typeof window !== "undefined" ? window.innerHeight : 0);
285
+ const handleWindowResize = () => {
286
+ if (typeof window !== "undefined") {
287
+ windowWidth.value = window.innerWidth;
288
+ windowHeight.value = window.innerHeight;
289
+ }
290
+ };
291
+ onMounted(() => {
292
+ if (typeof window !== "undefined") {
293
+ window.addEventListener("resize", handleWindowResize);
294
+ }
295
+ });
296
+ onUnmounted(() => {
297
+ if (typeof window !== "undefined") {
298
+ window.removeEventListener("resize", handleWindowResize);
299
+ }
300
+ });
227
301
  const bubbleQuadrant = computed(() => {
228
302
  var _a, _b, _c, _d;
229
303
  if (typeof window === "undefined") return "bottom-right";
230
- const centerX = window.innerWidth / 2;
231
- const centerY = window.innerHeight / 2;
304
+ const centerX = windowWidth.value / 2;
305
+ const centerY = windowHeight.value / 2;
232
306
  const bubbleSize = 44;
233
- const effectiveX = ((_b = (_a = bubbleOffset.value) == null ? void 0 : _a.x) != null ? _b : window.innerWidth - bubbleSize - 24) + bubbleSize / 2;
234
- const effectiveY = ((_d = (_c = bubbleOffset.value) == null ? void 0 : _c.y) != null ? _d : window.innerHeight - bubbleSize - 24) + bubbleSize / 2;
307
+ const currentOffset = (_b = (_a = triggerRef.value) == null ? void 0 : _a.offset) != null ? _b : bubbleOffset.value;
308
+ const effectiveX = ((_c = currentOffset == null ? void 0 : currentOffset.x) != null ? _c : windowWidth.value - bubbleSize - 24) + bubbleSize / 2;
309
+ const effectiveY = ((_d = currentOffset == null ? void 0 : currentOffset.y) != null ? _d : windowHeight.value - bubbleSize - 24) + bubbleSize / 2;
235
310
  if (effectiveX >= centerX && effectiveY >= centerY) {
236
311
  return "bottom-right";
237
312
  } else if (effectiveX < centerX && effectiveY >= centerY) {
@@ -247,36 +322,42 @@ const __vue_sfc__ = /* @__PURE__ */ _defineComponent(__spreadProps(__spreadValue
247
322
  return quadrant === "top-right" || quadrant === "bottom-right";
248
323
  });
249
324
  const chatPositionStyle = computed(() => {
250
- var _a;
325
+ var _a, _b, _c;
251
326
  if (typeof window === "undefined") return {};
252
- const windowWidth = window.innerWidth;
253
- const windowHeight = window.innerHeight;
254
327
  const chatWidth = minimized.value ? 300 : 700;
255
- const chatHeight = minimized.value ? 300 : Math.min(windowHeight * 0.86, windowHeight - 40);
328
+ const chatHeight = minimized.value ? 300 : Math.min(windowHeight.value * 0.86, windowHeight.value - 40);
256
329
  const gap = 24;
257
330
  const bubbleSize = 44;
258
331
  const screenMargin = 20;
259
- const effectiveOffset = (_a = bubbleOffset.value) != null ? _a : { x: windowWidth - bubbleSize - gap, y: windowHeight - bubbleSize - gap };
332
+ const effectiveOffset = (_c = (_b = (_a = triggerRef.value) == null ? void 0 : _a.offset) != null ? _b : bubbleOffset.value) != null ? _c : { x: windowWidth.value - bubbleSize - gap, y: windowHeight.value - bubbleSize - gap };
260
333
  const style = {};
261
334
  if (isBubbleOnRightSide.value) {
262
- let rightPos = windowWidth - effectiveOffset.x + gap;
263
- const maxRight = windowWidth - chatWidth - screenMargin;
335
+ let rightPos = windowWidth.value - effectiveOffset.x + gap;
336
+ const minRight = screenMargin;
337
+ const maxRight = windowWidth.value - chatWidth - screenMargin;
264
338
  if (rightPos > maxRight) {
265
339
  rightPos = maxRight;
266
340
  }
341
+ if (rightPos < minRight) {
342
+ rightPos = minRight;
343
+ }
267
344
  style.right = `${rightPos}px`;
268
345
  style.left = "auto";
269
346
  } else {
270
347
  let leftPos = effectiveOffset.x + bubbleSize + gap;
271
- const maxLeft = windowWidth - chatWidth - screenMargin;
348
+ const minLeft = screenMargin;
349
+ const maxLeft = windowWidth.value - chatWidth - screenMargin;
272
350
  if (leftPos > maxLeft) {
273
351
  leftPos = maxLeft;
274
352
  }
353
+ if (leftPos < minLeft) {
354
+ leftPos = minLeft;
355
+ }
275
356
  style.left = `${leftPos}px`;
276
357
  style.right = "auto";
277
358
  }
278
- let bottomPos = windowHeight - effectiveOffset.y - bubbleSize;
279
- const maxBottom = windowHeight - chatHeight - screenMargin;
359
+ let bottomPos = windowHeight.value - effectiveOffset.y - bubbleSize;
360
+ const maxBottom = windowHeight.value - chatHeight - screenMargin;
280
361
  if (bottomPos > maxBottom) {
281
362
  bottomPos = maxBottom;
282
363
  }
@@ -340,6 +421,7 @@ const __vue_sfc__ = /* @__PURE__ */ _defineComponent(__spreadProps(__spreadValue
340
421
  thinking: toRef(props, "thinking"),
341
422
  minimized,
342
423
  promptDockVisible,
424
+ bubbleOffset,
343
425
  iframeSource,
344
426
  buttonActive,
345
427
  sessionListTitle,
@@ -361,7 +443,8 @@ const __vue_sfc__ = /* @__PURE__ */ _defineComponent(__spreadProps(__spreadValue
361
443
  handleClickSelectedNode,
362
444
  handleRemoveSelectedNode: (payload) => handleRemoveSelectedNode(payload.item, payload.index, payload.source),
363
445
  handleClearSelectedNodes,
364
- handleFrameLoaded
446
+ handleFrameLoaded,
447
+ handleBubbleOffsetChange
365
448
  });
366
449
  const __returned__ = { props, emit, slots, notificationMessage, notificationVisible, notificationMode, get notificationTimer() {
367
450
  return notificationTimer;
@@ -371,7 +454,7 @@ const __vue_sfc__ = /* @__PURE__ */ _defineComponent(__spreadProps(__spreadValue
371
454
  return dialogResolve;
372
455
  }, set dialogResolve(v) {
373
456
  dialogResolve = v;
374
- }, showConfirmDialog, handleDialogConfirm, handleDialogCancel, frameRef, triggerRef, sendMessageToIframe, handleFrameLoaded, localSessionListCollapsed, minimized, promptDockVisible, buttonActive, containerClasses, iframeSource, sessionListTitle, resolvedTheme, handleClose, handleEmptyAction, handleToggle, handleToggleSessionList, handleToggleTheme, sessionItems, handleCreateSession, handleDeleteSession, handleSelectSession, bubbleVisible, hasSelectedElements, selectedElementItems, handleClearSelectedNodes, handleClickSelectedNode, handleRemoveSelectedNode, handleToggleSelectMode, highlightVisible, highlightStyle, tooltipVisible, tooltipStyle, tooltipContent, handleToggleMinimize, handleTogglePromptDock, bubbleOffset, bubbleQuadrant, isBubbleOnRightSide, chatPositionStyle, handleBubbleOffsetChange, chatAnimationOrigin, isDragging, get wasOpenBeforeDrag() {
457
+ }, showConfirmDialog, handleDialogConfirm, handleDialogCancel, frameRef, triggerRef, sendMessageToIframe, localSessionListCollapsed, minimized, promptDockVisible, isRestoring, iframeLoaded, syncStateToIframe, handleFrameLoaded, buttonActive, containerClasses, iframeSource, sessionListTitle, resolvedTheme, handleClose, handleEmptyAction, handleToggle, handleToggleSessionList, handleToggleTheme, sessionItems, handleCreateSession, handleDeleteSession, handleSelectSession, bubbleVisible, hasSelectedElements, selectedElementItems, handleClearSelectedNodes, handleClickSelectedNode, handleRemoveSelectedNode, handleToggleSelectMode, highlightVisible, highlightStyle, tooltipVisible, tooltipStyle, tooltipContent, bubbleOffset, handleToggleMinimize, handleTogglePromptDock, windowWidth, windowHeight, handleWindowResize, bubbleQuadrant, isBubbleOnRightSide, chatPositionStyle, handleBubbleOffsetChange, chatAnimationOrigin, isDragging, get wasOpenBeforeDrag() {
375
458
  return wasOpenBeforeDrag;
376
459
  }, set wasOpenBeforeDrag(v) {
377
460
  wasOpenBeforeDrag = v;
@@ -416,7 +499,6 @@ function __vue_render__(_ctx, _cache, $props, $setup, $data, $options) {
416
499
  $setup["Trigger"],
417
500
  {
418
501
  ref: "triggerRef",
419
- onOffsetChange: $setup.handleBubbleOffsetChange,
420
502
  onDragStart: $setup.handleDragStart,
421
503
  onDragEnd: $setup.handleDragEnd
422
504
  },
@@ -438,7 +520,7 @@ function __vue_render__(_ctx, _cache, $props, $setup, $data, $options) {
438
520
  _withDirectives(_createElementVNode(
439
521
  "div",
440
522
  {
441
- class: _normalizeClass(["opencode-chat", { open: $props.open, minimized: $setup.minimized, dragging: $setup.isDragging }]),
523
+ class: _normalizeClass(["opencode-chat", { open: $props.open, minimized: $setup.minimized, dragging: $setup.isDragging, "no-transition": $setup.isRestoring }]),
442
524
  style: _normalizeStyle($setup.chatPositionStyle)
443
525
  },
444
526
  [
@@ -549,9 +631,7 @@ function __vue_render__(_ctx, _cache, $props, $setup, $data, $options) {
549
631
  "div",
550
632
  {
551
633
  class: "opencode-element-highlight",
552
- style: _normalizeStyle(__spreadValues({
553
- display: $setup.highlightVisible ? "block" : "none"
554
- }, $setup.highlightStyle))
634
+ style: _normalizeStyle($setup.highlightStyle)
555
635
  },
556
636
  null,
557
637
  4
@@ -563,9 +643,7 @@ function __vue_render__(_ctx, _cache, $props, $setup, $data, $options) {
563
643
  "div",
564
644
  {
565
645
  class: "opencode-element-tooltip",
566
- style: _normalizeStyle(__spreadValues({
567
- display: $setup.tooltipVisible ? "block" : "none"
568
- }, $setup.tooltipStyle))
646
+ style: _normalizeStyle($setup.tooltipStyle)
569
647
  },
570
648
  [
571
649
  _createElementVNode(