vue-agent-input 0.1.0 → 0.2.0

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 CHANGED
@@ -10,6 +10,8 @@
10
10
 
11
11
  需要 Vue 3.5 或更新的 Vue 3 版本。包以 ESM 发布,附带 TypeScript 声明和编译好的 CSS。
12
12
 
13
+ 浏览器最低支持 Chrome 90。
14
+
13
15
  ```sh
14
16
  npm install vue-agent-input
15
17
  ```
@@ -48,10 +50,11 @@ function handleSend({ text }: AgentInputSendPayload) {
48
50
  <script setup lang="ts">
49
51
  import { ref } from 'vue'
50
52
  import { AgentInput } from 'vue-agent-input'
51
- import type { AgentInputContent, AgentInputItem, AgentInputTag } from 'vue-agent-input'
53
+ import type { AgentInputContent, AgentInputExpose, AgentInputItem, AgentInputTag } from 'vue-agent-input'
52
54
  import 'vue-agent-input/style.css'
53
55
 
54
56
  const draft = ref<AgentInputContent>([])
57
+ const composer = ref<AgentInputExpose | null>(null)
55
58
  const agent = ref<AgentInputItem | null>(null)
56
59
  const agents: AgentInputItem[] = [{ label: '研究助手', value: 'research' }]
57
60
  const tags: AgentInputTag[] = [{ label: '季度报告', value: 'report.pdf' }]
@@ -69,7 +72,9 @@ function handleTagClick(item: AgentInputTag) {
69
72
  </script>
70
73
 
71
74
  <template>
72
- <AgentInput v-model="draft" v-model:agent="agent" @tag-click="handleTagClick">
75
+ <button type="button" @click="composer?.openSuggestion('@')">选择智能体</button>
76
+ <button type="button" @click="composer?.openSuggestion('/')">插入标签</button>
77
+ <AgentInput ref="composer" v-model="draft" v-model:agent="agent" @tag-click="handleTagClick">
73
78
  <template #suggestion="{ trigger, query, setAgent, insertTag }">
74
79
  <button
75
80
  v-for="item in filterCandidates(trigger === '@' ? agents : tags, query)"
@@ -84,7 +89,9 @@ function handleTagClick(item: AgentInputTag) {
84
89
  </template>
85
90
  ```
86
91
 
87
- `setAgent(item)` 和 `insertTag(item)` 都会移除当前触发符及查询词,并恢复正文焦点。`close()` 收起面板并保留已输入的文字。`close({ clearTrigger: true })` 适用于连接器等自定义候选,会移除触发符及查询词并恢复焦点。
92
+ 组件外部的按钮或快捷键可以通过 ref 调用 `openSuggestion('@')` 或 `openSuggestion('/')`。面板以空查询打开,光标回到最近的编辑位置。有选区时从选区末尾开始,首次编辑时从正文末尾开始。此时正文保持原样,可以直接输入查询词。
93
+
94
+ `setAgent(item)` 和 `insertTag(item)` 都会清除当前查询词及正文中的触发符,并恢复正文焦点。`close()` 收起面板并保留已输入的文字。`close({ clearTrigger: true })` 适用于连接器等自定义候选,会清除查询词及正文中的触发符并恢复焦点。
88
95
 
89
96
  按 Escape 关闭候选面板。需要自定义方向键或 Enter 选择时,监听 `suggestion-keydown`,并对接管的按键调用 `event.preventDefault()`。面板打开时,未接管的 Enter 会收起面板。
90
97
 
@@ -138,7 +145,7 @@ const draft: AgentInputContent = [
138
145
  | --- | --- |
139
146
  | `header` | 位于正文上方,可放工具栏或已选连接器。 |
140
147
  | `footer` | 填满发送按钮左侧的可用宽度,两者相隔 `0.5rem`。 |
141
- | `suggestion` | 位于组件内部的 `header` 上方。接收 `{ trigger, query, setAgent, insertTag, close }`,类型为 `AgentInputSuggestion`。最大高度为 `min(16rem, 50dvh)`,超出时在面板内滚动。 |
148
+ | `suggestion` | 位于组件内部的 `header` 上方。接收 `{ trigger, query, setAgent, insertTag, close }`,类型为 `AgentInputSuggestion`。最大高度为 `16rem` 和半个视口高度中的较小值,超出时在面板内滚动。 |
142
149
 
143
150
  ### 实例方法
144
151
 
@@ -147,6 +154,7 @@ const draft: AgentInputContent = [
147
154
  | 方法 | 用途 |
148
155
  | --- | --- |
149
156
  | `focus()` | 将焦点移回正文。 |
157
+ | `openSuggestion(trigger)` | 为 `@` 或 `/` 打开 `#suggestion`,并聚焦正文。 |
150
158
  | `setAgent(item)` | 设置首行智能体,传 `null` 清除。 |
151
159
  | `insertTag(item)` | 用标签替换当前或最近的正文选区,未建立选区时追加到末尾。 |
152
160
 
package/dist/index.js CHANGED
@@ -1,172 +1,173 @@
1
- import { defineComponent as Ot, useSlots as Pt, ref as F, useId as $t, shallowRef as j, computed as H, watch as Vt, onMounted as Kt, onBeforeUnmount as Ft, openBlock as T, createElementBlock as S, withKeys as qt, normalizeStyle as Wt, renderSlot as Q, createCommentVNode as B, createElementVNode as _, toDisplayString as lt, withModifiers as zt } from "vue";
2
- const gt = (r) => typeof r == "string" ? r.length : 1;
3
- function ut(r) {
4
- return r.reduce((n, a) => n + gt(a), 0);
1
+ import { defineComponent as Vt, useSlots as Kt, ref as q, useId as Ft, shallowRef as Q, computed as Y, watch as qt, onMounted as Wt, onBeforeUnmount as zt, openBlock as C, createElementBlock as S, withKeys as Gt, normalizeStyle as Jt, renderSlot as Z, createCommentVNode as L, createElementVNode as _, toDisplayString as ct, withModifiers as Ut } from "vue";
2
+ const pt = (s) => typeof s == "string" ? s.length : 1;
3
+ function ft(s) {
4
+ return s.reduce((n, a) => n + pt(a), 0);
5
5
  }
6
- function N(r) {
6
+ function M(s) {
7
7
  const n = [];
8
- for (const a of r) {
8
+ for (const a of s) {
9
9
  if (typeof a != "string") {
10
10
  n.push({ ...a });
11
11
  continue;
12
12
  }
13
13
  if (a === "") continue;
14
- const l = n[n.length - 1], o = a.replace(/\r\n?/g, `
14
+ const u = n[n.length - 1], o = a.replace(/\r\n?/g, `
15
15
  `);
16
- typeof l == "string" ? n[n.length - 1] = l + o : n.push(o);
16
+ typeof u == "string" ? n[n.length - 1] = u + o : n.push(o);
17
17
  }
18
18
  return n;
19
19
  }
20
- function Y(r, n) {
21
- return r.length === n.length && r.every((a, l) => {
22
- const o = n[l];
20
+ function tt(s, n) {
21
+ return s.length === n.length && s.every((a, u) => {
22
+ const o = n[u];
23
23
  return typeof a == "string" || typeof o == "string" ? a === o : a.label === o.label && a.value === o.value && a.img === o.img && a.color === o.color;
24
24
  });
25
25
  }
26
- function R(r, n, a = 1 / 0) {
27
- const l = [];
26
+ function $(s, n, a = 1 / 0) {
27
+ const u = [];
28
28
  let o = 0;
29
- for (const d of r) {
30
- const g = o + gt(d);
29
+ for (const p of s) {
30
+ const h = o + pt(p);
31
31
  if (o >= a) break;
32
- g > n && n < a && l.push(typeof d == "string" ? d.slice(Math.max(0, n - o), a - o) : d), o = g;
32
+ h > n && n < a && u.push(typeof p == "string" ? p.slice(Math.max(0, n - o), a - o) : p), o = h;
33
33
  }
34
- return l;
34
+ return u;
35
35
  }
36
- function ct(r) {
36
+ function dt(s) {
37
37
  let n = "", a = !1;
38
- for (const l of r) {
39
- const o = typeof l != "string", d = o ? l.value : l;
40
- d !== "" && ((o || a) && n && !/\s$/.test(n) && !/^\s/.test(d) && (n += " "), n += d, a = o);
38
+ for (const u of s) {
39
+ const o = typeof u != "string", p = o ? u.value : u;
40
+ p !== "" && ((o || a) && n && !/\s$/.test(n) && !/^\s/.test(p) && (n += " "), n += p, a = o);
41
41
  }
42
42
  return n;
43
43
  }
44
- const pt = "\uFEFF", Z = "data-agent-input-tag", ht = "data-agent-input-guard";
45
- function mt(r) {
46
- const n = r.getAttribute(Z);
44
+ const ht = "\uFEFF", nt = "data-agent-input-tag", mt = "data-agent-input-guard";
45
+ function vt(s) {
46
+ const n = s.getAttribute(nt);
47
47
  return n === null ? void 0 : JSON.parse(n);
48
48
  }
49
- function ft(r, n) {
49
+ function gt(s, n) {
50
50
  if (!(n instanceof Element)) return;
51
- const a = n.closest(`[${Z}]`);
52
- if (a && r.contains(a)) return mt(a);
51
+ const a = n.closest(`[${nt}]`);
52
+ if (a && s.contains(a)) return vt(a);
53
53
  }
54
- function Gt(r, n) {
55
- const a = r.ownerDocument, l = a.createDocumentFragment();
54
+ function Xt(s, n) {
55
+ const a = s.ownerDocument, u = a.createDocumentFragment();
56
56
  function o() {
57
- const g = a.createElement("span");
58
- g.setAttribute(ht, ""), g.textContent = pt, l.append(g);
57
+ const h = a.createElement("span");
58
+ h.setAttribute(mt, ""), h.textContent = ht, u.append(h);
59
59
  }
60
- for (const [g, s] of n.entries()) {
61
- if (typeof s == "string") {
62
- l.append(a.createTextNode(s));
60
+ for (const [h, l] of n.entries()) {
61
+ if (typeof l == "string") {
62
+ u.append(a.createTextNode(l));
63
63
  continue;
64
64
  }
65
- typeof n[g - 1] != "string" && o();
65
+ typeof n[h - 1] != "string" && o();
66
66
  const i = a.createElement("button");
67
- if (i.type = "button", i.className = "agent-input__tag", i.contentEditable = "false", i.setAttribute(Z, JSON.stringify(s)), s.img) {
68
- const u = a.createElement("img");
69
- u.src = s.img, u.alt = "", u.draggable = !1, i.append(u);
67
+ if (i.type = "button", i.className = "agent-input__tag", i.contentEditable = "false", i.setAttribute(nt, JSON.stringify(l)), l.img) {
68
+ const d = a.createElement("img");
69
+ d.src = l.img, d.alt = "", d.draggable = !1, i.append(d);
70
70
  }
71
- const h = a.createElement("span");
72
- h.className = "agent-input__tag-label", h.textContent = s.label, s.color && (h.style.color = s.color), i.append(h), l.append(i);
71
+ const m = a.createElement("span");
72
+ m.className = "agent-input__tag-label", m.textContent = l.label, l.color && (m.style.color = l.color), i.append(m), u.append(i);
73
73
  }
74
- const d = n[n.length - 1];
75
- return (typeof d != "string" || d.endsWith(`
76
- `)) && o(), r.replaceChildren(l), vt(r);
74
+ const p = n[n.length - 1];
75
+ return (typeof p != "string" || p.endsWith(`
76
+ `)) && o(), s.replaceChildren(u), yt(s);
77
77
  }
78
- function vt(r) {
79
- const n = [], a = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
78
+ function yt(s) {
79
+ const n = [], a = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
80
80
  let o = 0;
81
- function d(s) {
82
- if (!s) return;
81
+ function p(l) {
82
+ if (!l) return;
83
83
  const i = n[n.length - 1];
84
- typeof i == "string" ? n[n.length - 1] = i + s : n.push(s), o += s.length;
84
+ typeof i == "string" ? n[n.length - 1] = i + l : n.push(l), o += l.length;
85
85
  }
86
- function g(s, i) {
87
- if (s.nodeType === Node.TEXT_NODE) {
88
- const y = s, c = y.data, x = i?.pending ? c.indexOf(pt) : -1;
86
+ function h(l, i) {
87
+ if (l.nodeType === Node.TEXT_NODE) {
88
+ const y = l, g = y.data, x = i != null && i.pending ? g.indexOf(ht) : -1;
89
89
  x !== -1 && i && (i.pending = !1);
90
- const M = o;
91
- d(x === -1 ? c : c.slice(0, x) + c.slice(x + 1)), l.set(s, { node: y, start: M, end: o, guardIndex: x });
90
+ const B = o;
91
+ p(x === -1 ? g : g.slice(0, x) + g.slice(x + 1)), u.set(l, { node: y, start: B, end: o, guardIndex: x });
92
92
  return;
93
93
  }
94
- if (s.nodeType !== Node.ELEMENT_NODE) return;
95
- const h = s, u = mt(h);
96
- if (u) {
97
- a.set(s, [o, o + 1]), n.push(u), o++;
94
+ if (l.nodeType !== Node.ELEMENT_NODE) return;
95
+ const m = l, d = vt(m);
96
+ if (d) {
97
+ a.set(l, [o, o + 1]), n.push(d), o++;
98
98
  return;
99
99
  }
100
- if (h.tagName === "BR") {
101
- a.set(s, [o]), h.nextSibling && d(`
100
+ if (m.tagName === "BR") {
101
+ a.set(l, [o]), m.nextSibling && p(`
102
102
  `);
103
103
  return;
104
104
  }
105
- const b = [o], w = h.hasAttribute(ht) ? { pending: !0 } : i;
106
- let v = !1;
107
- for (const [y, c] of [...s.childNodes].entries()) {
108
- const x = /^(DIV|P)$/.test(c.nodeName);
109
- y > 0 && (x || v) && d(`
110
- `), b[y] = o, g(c, w), b.push(o), v = x;
105
+ const E = [o], D = m.hasAttribute(mt) ? { pending: !0 } : i;
106
+ let b = !1;
107
+ for (const [y, g] of [...l.childNodes].entries()) {
108
+ const x = /^(DIV|P)$/.test(g.nodeName);
109
+ y > 0 && (x || b) && p(`
110
+ `), E[y] = o, h(g, D), E.push(o), b = x;
111
111
  }
112
- a.set(s, b);
112
+ a.set(l, E);
113
113
  }
114
- return g(r), {
114
+ return h(s), {
115
115
  content: n,
116
116
  length: o,
117
- offsetAt(s, i) {
118
- const h = l.get(s);
119
- if (h) return h.start + i - +(h.guardIndex !== -1 && i > h.guardIndex);
120
- const u = a.get(s);
121
- if (u) return u[Math.min(i, u.length - 1)];
117
+ offsetAt(l, i) {
118
+ const m = u.get(l);
119
+ if (m) return m.start + i - +(m.guardIndex !== -1 && i > m.guardIndex);
120
+ const d = a.get(l);
121
+ if (d) return d[Math.min(i, d.length - 1)];
122
122
  },
123
- pointAt(s) {
124
- const i = Math.max(0, Math.min(s, o));
125
- for (const b of l.values()) {
126
- if (i < b.start || i > b.end) continue;
127
- const w = i - b.start;
128
- return { node: b.node, offset: w + +(b.guardIndex !== -1 && w >= b.guardIndex) };
123
+ pointAt(l) {
124
+ const i = Math.max(0, Math.min(l, o));
125
+ for (const E of u.values()) {
126
+ if (i < E.start || i > E.end) continue;
127
+ const D = i - E.start;
128
+ return { node: E.node, offset: D + +(E.guardIndex !== -1 && D >= E.guardIndex) };
129
129
  }
130
- const u = (a.get(r) ?? [0]).findIndex((b) => b >= i);
131
- return { node: r, offset: u === -1 ? r.childNodes.length : u };
130
+ const d = (a.get(s) ?? [0]).findIndex((E) => E >= i);
131
+ return { node: s, offset: d === -1 ? s.childNodes.length : d };
132
132
  }
133
133
  };
134
134
  }
135
- function Jt(r, n) {
136
- const a = r.ownerDocument.getSelection();
137
- if (!a?.rangeCount) return null;
138
- const l = a.getRangeAt(0), o = n.offsetAt(l.startContainer, l.startOffset), d = n.offsetAt(l.endContainer, l.endOffset);
139
- return o === void 0 || d === void 0 ? null : { start: o, end: d };
135
+ function jt(s, n) {
136
+ const a = s.ownerDocument.getSelection();
137
+ if (!(a != null && a.rangeCount)) return null;
138
+ const u = a.getRangeAt(0), o = n.offsetAt(u.startContainer, u.startOffset), p = n.offsetAt(u.endContainer, u.endOffset);
139
+ return o === void 0 || p === void 0 ? null : { start: o, end: p };
140
140
  }
141
- function dt(r, n, a) {
142
- const l = r.ownerDocument, o = n.pointAt(a.start), d = n.pointAt(a.end), g = l.createRange();
143
- g.setStart(o.node, o.offset), g.setEnd(d.node, d.offset), l.getSelection()?.removeAllRanges(), l.getSelection()?.addRange(g);
144
- const s = g.getBoundingClientRect(), i = r.getBoundingClientRect();
145
- s.height && s.bottom > i.bottom && (r.scrollTop += s.bottom - i.bottom), s.height && s.top < i.top && (r.scrollTop -= i.top - s.top);
141
+ function et(s, n, a) {
142
+ var m, d;
143
+ const u = s.ownerDocument, o = n.pointAt(a.start), p = n.pointAt(a.end), h = u.createRange();
144
+ h.setStart(o.node, o.offset), h.setEnd(p.node, p.offset), (m = u.getSelection()) == null || m.removeAllRanges(), (d = u.getSelection()) == null || d.addRange(h);
145
+ const l = h.getBoundingClientRect(), i = s.getBoundingClientRect();
146
+ l.height && l.bottom > i.bottom && (s.scrollTop += l.bottom - i.bottom), l.height && l.top < i.top && (s.scrollTop -= i.top - l.top);
146
147
  }
147
- const Ut = ["data-theme"], Xt = {
148
+ const Ht = ["data-theme"], Qt = {
148
149
  key: 1,
149
150
  class: "agent-input__header"
150
- }, jt = {
151
+ }, Yt = {
151
152
  key: 0,
152
153
  class: "agent-input__agent"
153
- }, Ht = ["src"], Qt = { class: "agent-input__agent-label" }, Yt = ["aria-label"], Zt = {
154
+ }, Zt = ["src"], te = { class: "agent-input__agent-label" }, ee = ["aria-label"], ne = {
154
155
  key: 1,
155
156
  class: "agent-input__placeholder",
156
157
  "aria-hidden": "true"
157
- }, te = ["aria-label", "aria-placeholder", "aria-controls"], ee = { class: "agent-input__footer" }, ne = {
158
+ }, oe = ["aria-label", "aria-placeholder", "aria-controls"], ae = { class: "agent-input__footer" }, ie = {
158
159
  key: 0,
159
160
  class: "agent-input__footer-content"
160
- }, oe = ["aria-label"], ae = {
161
+ }, re = ["aria-label"], se = {
161
162
  key: 0,
162
163
  viewBox: "0 0 24 24",
163
164
  "aria-hidden": "true"
164
- }, ie = {
165
+ }, le = {
165
166
  key: 1,
166
167
  viewBox: "0 0 24 24",
167
168
  fill: "none",
168
169
  "aria-hidden": "true"
169
- }, se = /* @__PURE__ */ Ot({
170
+ }, ce = /* @__PURE__ */ Vt({
170
171
  __name: "AgentInput",
171
172
  props: {
172
173
  modelValue: {},
@@ -179,257 +180,277 @@ const Ut = ["data-theme"], Xt = {
179
180
  loading: { type: Boolean, default: !1 }
180
181
  },
181
182
  emits: ["update:modelValue", "update:agent", "suggestion-keydown", "tag-click", "send", "stop"],
182
- setup(r, { expose: n, emit: a }) {
183
- const l = r, o = a, d = Pt(), g = F(null), s = F(null), i = F(null), h = `agent-input-suggestion-${$t()}`, u = j(N(l.modelValue ?? [])), b = j(null), w = H(() => l.agent === void 0 ? b.value : l.agent), v = j(null), y = F(!1);
184
- let c = null, x = null, M = null, E, O = !1;
185
- const tt = H(() => et(l.minRows, 2)), yt = H(() => Math.max(tt.value, et(l.maxRows, 6)));
186
- function et(t, e) {
183
+ setup(s, { expose: n, emit: a }) {
184
+ const u = s, o = a, p = Kt(), h = q(null), l = q(null), i = q(null), m = `agent-input-suggestion-${Ft()}`, d = Q(M(u.modelValue ?? [])), E = Q(null), D = Y(() => u.agent === void 0 ? E.value : u.agent), b = Q(null), y = q(!1);
185
+ let g = null, x = null, B = null, c, V = !1;
186
+ const ot = Y(() => at(u.minRows, 2)), bt = Y(() => Math.max(ot.value, at(u.maxRows, 6)));
187
+ function at(t, e) {
187
188
  return Number.isFinite(t) ? Math.max(1, Math.floor(t)) : e;
188
189
  }
189
- function I() {
190
- return !i.value || !c || E?.activeElement !== i.value ? null : Jt(i.value, c);
190
+ function R() {
191
+ return !i.value || !g || (c == null ? void 0 : c.activeElement) !== i.value ? null : jt(i.value, g);
192
+ }
193
+ function k() {
194
+ const t = (g == null ? void 0 : g.length) ?? ft(d.value);
195
+ return R() ?? x ?? { start: t, end: t };
191
196
  }
192
- function C() {
193
- const t = c?.length ?? ut(u.value);
194
- return I() ?? x ?? { start: t, end: t };
197
+ function W() {
198
+ const t = i.value, e = l.value;
199
+ if (!t || !e || !g || (c == null ? void 0 : c.activeElement) === t) return;
200
+ const f = k();
201
+ t.focus({ preventScroll: !0 }), et(e, g, f);
195
202
  }
196
- function q() {
197
- const t = i.value, e = s.value;
198
- if (!t || !e || !c || E?.activeElement === t) return;
199
- const f = C();
200
- t.focus({ preventScroll: !0 }), dt(e, c, f);
203
+ function w() {
204
+ b.value = null;
201
205
  }
202
- function D() {
203
- v.value = null;
206
+ function xt(t) {
207
+ const e = i.value, f = l.value;
208
+ if (!p.suggestion || !e || !f || !g || y.value) return;
209
+ const r = k().end, v = { start: r, end: r };
210
+ e.focus({ preventScroll: !0 }), et(f, g, v), x = v, b.value = { ...v, trigger: t, query: "", hasTriggerText: !1 };
204
211
  }
205
- function W(t, e = "") {
206
- if (!d.suggestion || !t || t.start !== t.end) {
207
- D();
212
+ function z(t, e) {
213
+ if (!p.suggestion || !t || t.start !== t.end) {
214
+ w();
215
+ return;
216
+ }
217
+ const f = t.end, r = b.value, v = e ?? "", T = Math.max(v.lastIndexOf("@"), v.lastIndexOf("/")), N = T === -1 ? r == null ? void 0 : r.start : f - v.length + T, I = T === -1 ? r == null ? void 0 : r.trigger : v[T];
218
+ if (N === void 0 || I === void 0) return;
219
+ const P = T !== -1 || (r == null ? void 0 : r.hasTriggerText) === !0;
220
+ if (!P && e === void 0 && f !== (r == null ? void 0 : r.end)) {
221
+ w();
208
222
  return;
209
223
  }
210
- const f = t.end, p = Math.max(e.lastIndexOf("@"), e.lastIndexOf("/")), m = p === -1 ? v.value?.start : f - e.length + p;
211
- if (m === void 0) return;
212
- const [k, ...$] = R(u.value, m, f);
213
- if (typeof k != "string" || $.length || !/^[@/][^\s@/]*$/u.test(k)) {
214
- D();
224
+ const [F = "", ...$t] = $(d.value, N, f);
225
+ if (f < N || typeof F != "string" || $t.length || P && F[0] !== I) {
226
+ w();
215
227
  return;
216
228
  }
217
- const V = k[0], st = k.slice(1), K = v.value;
218
- (K?.start !== m || K.end !== f || K.trigger !== V || K.query !== st) && (v.value = { start: m, end: f, trigger: V, query: st });
229
+ const H = P ? F.slice(1) : F;
230
+ if (/[\s@/]/u.test(H)) {
231
+ w();
232
+ return;
233
+ }
234
+ ((r == null ? void 0 : r.start) !== N || r.end !== f || r.trigger !== I || r.query !== H || r.hasTriggerText !== P) && (b.value = { start: N, end: f, trigger: I, query: H, hasTriggerText: P });
219
235
  }
220
- function nt() {
236
+ function it() {
221
237
  if (y.value) return;
222
- const t = I();
223
- t && (x = t, W(t));
224
- }
225
- function L(t, e, f = !1) {
226
- const p = i.value;
227
- if (!p || (c = Gt(p, t), !e)) return;
228
- const m = {
229
- start: Math.min(e.start, c.length),
230
- end: Math.min(e.end, c.length)
238
+ const t = R();
239
+ t && (x = t, z(t));
240
+ }
241
+ function O(t, e, f = !1) {
242
+ const r = i.value;
243
+ if (!r || (g = Xt(r, t), !e)) return;
244
+ const v = {
245
+ start: Math.min(e.start, g.length),
246
+ end: Math.min(e.end, g.length)
231
247
  };
232
- x = m, f && p.focus({ preventScroll: !0 }), s.value && E?.activeElement === p && dt(s.value, c, m);
248
+ x = v, f && r.focus({ preventScroll: !0 }), l.value && (c == null ? void 0 : c.activeElement) === r && et(l.value, g, v);
233
249
  }
234
- function ot(t) {
235
- return Y(u.value, t) ? !1 : (u.value = t, !0);
250
+ function rt(t) {
251
+ return tt(d.value, t) ? !1 : (d.value = t, !0);
236
252
  }
237
253
  function A(t, e, f = {}) {
238
- const p = N(e), m = N([
239
- ...R(u.value, 0, t.start),
240
- ...p,
241
- ...R(u.value, t.end)
242
- ]), k = t.start + ut(p), $ = { start: k, end: k }, V = ot(m);
243
- L(m, $, f.focus), W($, f.typed), V && o("update:modelValue", N(m));
244
- }
245
- function at(t = "") {
254
+ const r = M(e), v = M([
255
+ ...$(d.value, 0, t.start),
256
+ ...r,
257
+ ...$(d.value, t.end)
258
+ ]), T = t.start + ft(r), N = { start: T, end: T }, I = rt(v);
259
+ O(v, N, f.focus), z(N, f.typed ?? ""), I && o("update:modelValue", M(v));
260
+ }
261
+ function st(t = "") {
246
262
  const e = i.value;
247
263
  if (!e) return;
248
- c = vt(e);
249
- const f = I();
264
+ g = yt(e);
265
+ const f = R();
250
266
  f && (x = f);
251
- const p = ot(c.content);
252
- !c.length && c.pointAt(0).node === e && L([], { start: 0, end: 0 }), W(f, t), p && o("update:modelValue", N(u.value));
267
+ const r = rt(g.content);
268
+ !g.length && g.pointAt(0).node === e && O([], { start: 0, end: 0 }), z(f, t), r && o("update:modelValue", M(d.value));
253
269
  }
254
- function it(t) {
255
- if (Y(u.value, t)) return;
256
- const e = I() ?? x;
257
- u.value = t, D(), L(t, e);
270
+ function lt(t) {
271
+ if (tt(d.value, t)) return;
272
+ const e = R() ?? x;
273
+ d.value = t, w(), O(t, e);
258
274
  }
259
- Vt(() => l.modelValue, (t) => {
275
+ qt(() => u.modelValue, (t) => {
260
276
  if (t === void 0) return;
261
- const e = N(t);
262
- y.value ? M = e : it(e);
277
+ const e = M(t);
278
+ y.value ? B = e : lt(e);
263
279
  }, { deep: !0 });
264
- function bt(t) {
265
- y.value || t.isComposing || at(t.inputType === "insertText" ? t.data ?? "" : "");
280
+ function Et(t) {
281
+ y.value || t.isComposing || st(t.inputType === "insertText" ? t.data ?? "" : "");
266
282
  }
267
- function xt() {
283
+ function Tt() {
268
284
  y.value = !0;
269
285
  }
270
- function Et(t) {
271
- if (y.value = !1, M !== null) {
272
- const e = M;
273
- M = null, Y(u.value, e) ? L(e, x) : it(e);
286
+ function wt(t) {
287
+ if (y.value = !1, B !== null) {
288
+ const e = B;
289
+ B = null, tt(d.value, e) ? O(e, x) : lt(e);
274
290
  return;
275
291
  }
276
- at(t.data);
277
- }
278
- function z(t) {
279
- b.value = t, o("update:agent", t);
280
- }
281
- function wt() {
282
- z(null), q();
283
- }
284
- function Dt(t) {
285
- const e = C();
286
- D(), A(e, [t], { focus: !0 });
292
+ st(t.data);
287
293
  }
288
294
  function G(t) {
289
- const e = v.value;
290
- return e ? (D(), A(e, t, { focus: !0 }), !0) : !1;
295
+ E.value = t, o("update:agent", t);
296
+ }
297
+ function Dt() {
298
+ G(null), W();
291
299
  }
292
300
  function kt(t) {
293
- G([t]);
301
+ const e = k();
302
+ w(), A(e, [t], { focus: !0 });
303
+ }
304
+ function J(t) {
305
+ const e = b.value;
306
+ return e ? (w(), A(e, t, { focus: !0 }), !0) : !1;
294
307
  }
295
308
  function _t(t) {
296
- G([]) && z(t);
309
+ J([t]);
297
310
  }
298
311
  function Ct(t) {
299
- t?.clearTrigger ? G([]) : D();
312
+ J([]) && G(t);
300
313
  }
301
- function J() {
302
- if (l.loading || y.value) return;
303
- const t = N(u.value);
304
- o("send", { text: ct(t), content: t, agent: w.value && { ...w.value } });
314
+ function St(t) {
315
+ t != null && t.clearTrigger ? J([]) : w();
305
316
  }
306
- function Tt() {
307
- l.loading ? o("stop") : J();
317
+ function U() {
318
+ if (u.loading || y.value) return;
319
+ const t = M(d.value);
320
+ o("send", { text: dt(t), content: t, agent: D.value && { ...D.value } });
321
+ }
322
+ function At() {
323
+ u.loading ? o("stop") : U();
308
324
  }
309
- function U(t) {
310
- return R(u.value, t.start, t.end).some((e) => typeof e != "string");
325
+ function X(t) {
326
+ return $(d.value, t.start, t.end).some((e) => typeof e != "string");
311
327
  }
312
- function X(t, e, f) {
313
- const { start: p, end: m } = f, k = p !== m ? f : {
314
- start: e === -1 ? Math.max(0, p - 1) : p,
315
- end: e === 1 ? p + 1 : p
328
+ function j(t, e, f) {
329
+ const { start: r, end: v } = f, T = r !== v ? f : {
330
+ start: e === -1 ? Math.max(0, r - 1) : r,
331
+ end: e === 1 ? r + 1 : r
316
332
  };
317
- U(k) && (t.preventDefault(), A(k, []));
333
+ X(T) && (t.preventDefault(), A(T, []));
318
334
  }
319
- function St(t) {
320
- t.button === 0 && i.value && ft(i.value, t.target) && t.preventDefault();
335
+ function Nt(t) {
336
+ t.button === 0 && i.value && gt(i.value, t.target) && t.preventDefault();
321
337
  }
322
- function At(t) {
338
+ function Mt(t) {
323
339
  if (!i.value) return;
324
- const e = ft(i.value, t.target);
340
+ const e = gt(i.value, t.target);
325
341
  e && o("tag-click", e);
326
342
  }
327
- function Nt(t) {
343
+ function Bt(t) {
328
344
  if (!(t.target !== i.value || y.value || t.isComposing || t.keyCode === 229)) {
329
- if (v.value && t.key !== "Escape") {
345
+ if (b.value && t.key !== "Escape") {
330
346
  if (o("suggestion-keydown", t), t.defaultPrevented) return;
331
347
  if (t.key === "Enter" && !t.shiftKey) {
332
- t.preventDefault(), D();
348
+ t.preventDefault(), w();
333
349
  return;
334
350
  }
335
351
  }
336
- t.key === "Enter" ? (t.preventDefault(), t.shiftKey ? A(C(), [`
337
- `]) : J()) : !t.metaKey && !t.ctrlKey && !t.altKey && (t.key === "Backspace" && X(t, -1, C()), t.key === "Delete" && X(t, 1, C()));
352
+ t.key === "Enter" ? (t.preventDefault(), t.shiftKey ? A(k(), [`
353
+ `]) : U()) : !t.metaKey && !t.ctrlKey && !t.altKey && (t.key === "Backspace" && j(t, -1, k()), t.key === "Delete" && j(t, 1, k()));
338
354
  }
339
355
  }
340
- function Mt(t) {
356
+ function It(t) {
357
+ var e;
341
358
  if (!(y.value || t.isComposing || !t.cancelable)) {
342
359
  if (t.inputType === "insertParagraph" || t.inputType === "insertLineBreak") {
343
- t.preventDefault(), t.inputType === "insertLineBreak" ? A(C(), [`
344
- `]) : v.value ? D() : J();
360
+ t.preventDefault(), t.inputType === "insertLineBreak" ? A(k(), [`
361
+ `]) : b.value ? w() : U();
345
362
  return;
346
363
  }
347
364
  if (t.inputType.startsWith("delete") && t.inputType !== "deleteByCut") {
348
- let e = C();
349
- const f = t.getTargetRanges?.()[0];
350
- if (f && c) {
351
- const p = c.offsetAt(f.startContainer, f.startOffset), m = c.offsetAt(f.endContainer, f.endOffset);
352
- p !== void 0 && m !== void 0 && p !== m && (e = { start: p, end: m });
365
+ let f = k();
366
+ const r = (e = t.getTargetRanges) == null ? void 0 : e.call(t)[0];
367
+ if (r && g) {
368
+ const v = g.offsetAt(r.startContainer, r.startOffset), T = g.offsetAt(r.endContainer, r.endOffset);
369
+ v !== void 0 && T !== void 0 && v !== T && (f = { start: v, end: T });
353
370
  }
354
- X(t, t.inputType.endsWith("Backward") ? -1 : 1, e);
371
+ j(t, t.inputType.endsWith("Backward") ? -1 : 1, f);
355
372
  return;
356
373
  }
357
374
  if (t.inputType === "insertText" && t.data !== null) {
358
- const e = C();
359
- U(e) && (t.preventDefault(), A(e, [t.data], { typed: t.data }));
375
+ const f = k();
376
+ X(f) && (t.preventDefault(), A(f, [t.data], { typed: t.data }));
360
377
  }
361
378
  }
362
379
  }
363
- function Bt(t) {
380
+ function Lt(t) {
381
+ var f;
364
382
  t.preventDefault();
365
- const e = t.clipboardData?.getData("text/plain");
366
- e && A(C(), [e]);
383
+ const e = (f = t.clipboardData) == null ? void 0 : f.getData("text/plain");
384
+ e && A(k(), [e]);
367
385
  }
368
- function It(t) {
369
- const e = I();
370
- !e || !U(e) || !t.clipboardData || (t.preventDefault(), t.clipboardData.setData("text/plain", ct(R(u.value, e.start, e.end))), A(e, []));
386
+ function Rt(t) {
387
+ const e = R();
388
+ !e || !X(e) || !t.clipboardData || (t.preventDefault(), t.clipboardData.setData("text/plain", dt($(d.value, e.start, e.end))), A(e, []));
371
389
  }
372
- function rt(t) {
373
- O = g.value !== null && t.composedPath().includes(g.value), O || D();
390
+ function ut(t) {
391
+ V = h.value !== null && t.composedPath().includes(h.value), V || w();
374
392
  }
375
- function P() {
376
- O = !1;
393
+ function K() {
394
+ V = !1;
377
395
  }
378
- function Lt(t) {
379
- v.value && (t.relatedTarget instanceof Node && g.value?.contains(t.relatedTarget) || !t.relatedTarget && O || queueMicrotask(() => {
380
- g.value?.contains(E?.activeElement ?? null) || D();
396
+ function Ot(t) {
397
+ var e;
398
+ b.value && (t.relatedTarget instanceof Node && ((e = h.value) != null && e.contains(t.relatedTarget)) || !t.relatedTarget && V || queueMicrotask(() => {
399
+ var f;
400
+ (f = h.value) != null && f.contains((c == null ? void 0 : c.activeElement) ?? null) || w();
381
401
  }));
382
402
  }
383
- function Rt(t) {
384
- !v.value || y.value || t.isComposing || t.keyCode === 229 || (t.preventDefault(), D(), q());
403
+ function Pt(t) {
404
+ !b.value || y.value || t.isComposing || t.keyCode === 229 || (t.preventDefault(), w(), W());
385
405
  }
386
- return Kt(() => {
387
- E = i.value?.ownerDocument, L(u.value, null), E?.addEventListener("selectionchange", nt), E?.addEventListener("pointerdown", rt, !0), E?.addEventListener("pointerup", P, !0), E?.addEventListener("pointercancel", P, !0);
388
- }), Ft(() => {
389
- E?.removeEventListener("selectionchange", nt), E?.removeEventListener("pointerdown", rt, !0), E?.removeEventListener("pointerup", P, !0), E?.removeEventListener("pointercancel", P, !0);
390
- }), n({ focus: q, setAgent: z, insertTag: Dt }), (t, e) => (T(), S("div", {
406
+ return Wt(() => {
407
+ var t;
408
+ c = (t = i.value) == null ? void 0 : t.ownerDocument, O(d.value, null), c == null || c.addEventListener("selectionchange", it), c == null || c.addEventListener("pointerdown", ut, !0), c == null || c.addEventListener("pointerup", K, !0), c == null || c.addEventListener("pointercancel", K, !0);
409
+ }), zt(() => {
410
+ c == null || c.removeEventListener("selectionchange", it), c == null || c.removeEventListener("pointerdown", ut, !0), c == null || c.removeEventListener("pointerup", K, !0), c == null || c.removeEventListener("pointercancel", K, !0);
411
+ }), n({ focus: W, openSuggestion: xt, setAgent: G, insertTag: kt }), (t, e) => (C(), S("div", {
391
412
  ref_key: "root",
392
- ref: g,
413
+ ref: h,
393
414
  class: "agent-input",
394
- "data-theme": r.theme,
395
- style: Wt({ "--agent-input-min-rows": tt.value, "--agent-input-max-rows": yt.value }),
396
- onFocusout: Lt,
397
- onKeydown: qt(Rt, ["esc"])
415
+ "data-theme": s.theme,
416
+ style: Jt({ "--agent-input-min-rows": ot.value, "--agent-input-max-rows": bt.value }),
417
+ onFocusout: Ot,
418
+ onKeydown: Gt(Pt, ["esc"])
398
419
  }, [
399
- v.value && t.$slots.suggestion ? (T(), S("div", {
420
+ b.value && t.$slots.suggestion ? (C(), S("div", {
400
421
  key: 0,
401
- id: h,
422
+ id: m,
402
423
  class: "agent-input__suggestion"
403
424
  }, [
404
- Q(t.$slots, "suggestion", {
405
- trigger: v.value.trigger,
406
- query: v.value.query,
407
- setAgent: _t,
408
- insertTag: kt,
409
- close: Ct
425
+ Z(t.$slots, "suggestion", {
426
+ trigger: b.value.trigger,
427
+ query: b.value.query,
428
+ setAgent: Ct,
429
+ insertTag: _t,
430
+ close: St
410
431
  })
411
- ])) : B("", !0),
412
- t.$slots.header ? (T(), S("div", Xt, [
413
- Q(t.$slots, "header")
414
- ])) : B("", !0),
432
+ ])) : L("", !0),
433
+ t.$slots.header ? (C(), S("div", Qt, [
434
+ Z(t.$slots, "header")
435
+ ])) : L("", !0),
415
436
  _("div", {
416
437
  ref_key: "scrollArea",
417
- ref: s,
438
+ ref: l,
418
439
  class: "agent-input__body"
419
440
  }, [
420
- w.value ? (T(), S("div", jt, [
421
- w.value.img ? (T(), S("img", {
441
+ D.value ? (C(), S("div", Yt, [
442
+ D.value.img ? (C(), S("img", {
422
443
  key: 0,
423
- src: w.value.img,
444
+ src: D.value.img,
424
445
  alt: "",
425
446
  draggable: "false"
426
- }, null, 8, Ht)) : B("", !0),
427
- _("span", Qt, "@" + lt(w.value.label), 1),
447
+ }, null, 8, Zt)) : L("", !0),
448
+ _("span", te, "@" + ct(D.value.label), 1),
428
449
  _("button", {
429
450
  type: "button",
430
451
  class: "agent-input__remove",
431
- "aria-label": `移除智能体 ${w.value.label}`,
432
- onClick: wt
452
+ "aria-label": `移除智能体 ${D.value.label}`,
453
+ onClick: Dt
433
454
  }, [...e[1] || (e[1] = [
434
455
  _("svg", {
435
456
  viewBox: "0 0 24 24",
@@ -438,9 +459,9 @@ const Ut = ["data-theme"], Xt = {
438
459
  }, [
439
460
  _("path", { d: "m7 7 10 10M17 7 7 17" })
440
461
  ], -1)
441
- ])], 8, Yt)
442
- ])) : B("", !0),
443
- r.placeholder && !u.value.length && !y.value ? (T(), S("div", Zt, lt(r.placeholder), 1)) : B("", !0),
462
+ ])], 8, ee)
463
+ ])) : L("", !0),
464
+ s.placeholder && !d.value.length && !y.value ? (C(), S("div", ne, ct(s.placeholder), 1)) : L("", !0),
444
465
  _("div", {
445
466
  ref_key: "editor",
446
467
  ref: i,
@@ -448,33 +469,33 @@ const Ut = ["data-theme"], Xt = {
448
469
  contenteditable: "true",
449
470
  role: "textbox",
450
471
  "aria-multiline": "true",
451
- "aria-label": r.ariaLabel,
452
- "aria-placeholder": r.placeholder,
453
- "aria-controls": v.value ? h : void 0,
454
- onMousedown: St,
455
- onClick: At,
456
- onKeydown: Nt,
457
- onBeforeinput: Mt,
458
- onInput: bt,
459
- onCompositionstart: xt,
460
- onCompositionend: Et,
461
- onPaste: Bt,
462
- onCut: It,
463
- onDrop: e[0] || (e[0] = zt(() => {
472
+ "aria-label": s.ariaLabel,
473
+ "aria-placeholder": s.placeholder,
474
+ "aria-controls": b.value ? m : void 0,
475
+ onMousedown: Nt,
476
+ onClick: Mt,
477
+ onKeydown: Bt,
478
+ onBeforeinput: It,
479
+ onInput: Et,
480
+ onCompositionstart: Tt,
481
+ onCompositionend: wt,
482
+ onPaste: Lt,
483
+ onCut: Rt,
484
+ onDrop: e[0] || (e[0] = Ut(() => {
464
485
  }, ["prevent"]))
465
- }, null, 40, te)
486
+ }, null, 40, oe)
466
487
  ], 512),
467
- _("div", ee, [
468
- t.$slots.footer ? (T(), S("div", ne, [
469
- Q(t.$slots, "footer")
470
- ])) : B("", !0),
488
+ _("div", ae, [
489
+ t.$slots.footer ? (C(), S("div", ie, [
490
+ Z(t.$slots, "footer")
491
+ ])) : L("", !0),
471
492
  _("button", {
472
493
  type: "button",
473
494
  class: "agent-input__action",
474
- "aria-label": r.loading ? "停止生成" : "发送消息",
475
- onClick: Tt
495
+ "aria-label": s.loading ? "停止生成" : "发送消息",
496
+ onClick: At
476
497
  }, [
477
- r.loading ? (T(), S("svg", ae, [...e[2] || (e[2] = [
498
+ s.loading ? (C(), S("svg", se, [...e[2] || (e[2] = [
478
499
  _("rect", {
479
500
  x: "7",
480
501
  y: "7",
@@ -483,14 +504,14 @@ const Ut = ["data-theme"], Xt = {
483
504
  rx: "2",
484
505
  fill: "currentColor"
485
506
  }, null, -1)
486
- ])])) : (T(), S("svg", ie, [...e[3] || (e[3] = [
507
+ ])])) : (C(), S("svg", le, [...e[3] || (e[3] = [
487
508
  _("path", { d: "M12 19V5m-5 5 5-5 5 5" }, null, -1)
488
509
  ])]))
489
- ], 8, oe)
510
+ ], 8, re)
490
511
  ])
491
- ], 44, Ut));
512
+ ], 44, Ht));
492
513
  }
493
514
  });
494
515
  export {
495
- se as AgentInput
516
+ ce as AgentInput
496
517
  };
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- .agent-input{--agent-input-surface: #fff;--agent-input-text: #171717;--agent-input-placeholder: #626262;--agent-input-border: #d4d4d4;--agent-input-focus: #595959;--agent-input-tag-background: #efefef;--agent-input-tag-color: #06f;--agent-input-agent-color: #292929;--agent-input-action-background: #171717;--agent-input-action-hover: #3b3b3b;--agent-input-action-color: #fff;--agent-input-line-height: 1.5rem;position:relative;box-sizing:border-box;display:grid;gap:.375rem;min-inline-size:0;padding:.75rem;border:1px solid var(--agent-input-border);border-radius:1rem;background:var(--agent-input-surface);color:var(--agent-input-text);color-scheme:light}.agent-input[data-theme=dark]{--agent-input-surface: #1c1c1c;--agent-input-text: #f5f5f5;--agent-input-placeholder: #ababab;--agent-input-border: #4a4a4a;--agent-input-focus: #bdbdbd;--agent-input-tag-background: #363636;--agent-input-agent-color: #f2f2f2;--agent-input-action-background: #f5f5f5;--agent-input-action-hover: #d7d7d7;--agent-input-action-color: #171717;color-scheme:dark}.agent-input:focus-within{border-color:var(--agent-input-focus)}.agent-input__header{min-inline-size:0}.agent-input__body{min-inline-size:0;max-block-size:calc(var(--agent-input-line-height) * var(--agent-input-max-rows));padding-inline:.25rem;overflow:auto}.agent-input__editor{min-block-size:calc(var(--agent-input-line-height) * var(--agent-input-min-rows));overflow-wrap:anywhere;white-space:pre-wrap;white-space:break-spaces;outline:none;font-size:1rem;line-height:var(--agent-input-line-height)}.agent-input__placeholder{block-size:var(--agent-input-line-height);margin-block-end:calc(-1 * var(--agent-input-line-height));overflow:hidden;color:var(--agent-input-placeholder);font-size:1rem;line-height:var(--agent-input-line-height);text-overflow:ellipsis;white-space:nowrap;pointer-events:none}.agent-input__tag,.agent-input__agent{display:inline-flex;box-sizing:border-box;align-items:center;gap:.3rem;max-inline-size:100%;padding-inline:.4rem;border-radius:.375rem;vertical-align:middle}.agent-input__tag img,.agent-input__agent img{flex:none;inline-size:1rem;block-size:1rem;border-radius:.2rem;object-fit:cover}.agent-input__tag{height:1.25rem;margin-inline:.125rem;max-inline-size:calc(100% - .25rem);padding-block:0;border:0;background:transparent;color:var(--agent-input-tag-color);font:inherit;font-size:.875rem;white-space:nowrap;cursor:pointer}.agent-input__tag:hover,.agent-input__tag:focus-visible{background:var(--agent-input-tag-background)}.agent-input__tag:focus-visible{outline:2px solid var(--agent-input-focus);outline-offset:-2px}.agent-input__agent{float:inline-start;max-inline-size:55%;block-size:var(--agent-input-line-height);margin-inline-end:.375rem;background:var(--agent-input-tag-background);color:var(--agent-input-agent-color);font-size:.875rem}.agent-input__tag-label,.agent-input__agent-label{min-inline-size:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.agent-input__footer{display:flex;justify-content:flex-end;align-items:center;gap:.5rem}.agent-input__footer-content{flex:1 1 0;min-inline-size:0}.agent-input__remove,.agent-input__action{display:grid;flex:none;place-items:center;padding:0;border:0;cursor:pointer}.agent-input__remove svg,.agent-input__action svg{inline-size:1.125rem;block-size:1.125rem}.agent-input__remove path,.agent-input__action path{stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}.agent-input__remove{inline-size:1.75rem;block-size:1.5rem;appearance:none;background:transparent;box-shadow:none;outline:none;color:inherit;-webkit-tap-highlight-color:transparent}.agent-input__remove:focus-visible path{stroke-width:2.6}.agent-input__action{inline-size:2.75rem;block-size:2.75rem;border-radius:.75rem;background:var(--agent-input-action-background);color:var(--agent-input-action-color)}.agent-input__action:hover{background:var(--agent-input-action-hover)}.agent-input__action:focus-visible{outline:2px solid var(--agent-input-focus);outline-offset:2px}.agent-input__suggestion{box-sizing:border-box;min-inline-size:0;max-block-size:min(16rem,50dvh);overflow:auto;overscroll-behavior:contain;border-block-end:1px solid var(--agent-input-border)}
1
+ @supports not (float: inline-start){:where([dir=ltr i]){--agent-input-float-start: left}:where([dir=rtl i]){--agent-input-float-start: right}}.agent-input{--agent-input-surface: #fff;--agent-input-text: #171717;--agent-input-placeholder: #626262;--agent-input-border: #d4d4d4;--agent-input-focus: #595959;--agent-input-tag-background: #efefef;--agent-input-tag-color: #06f;--agent-input-agent-color: #292929;--agent-input-action-background: #171717;--agent-input-action-hover: #3b3b3b;--agent-input-action-color: #fff;--agent-input-line-height: 1.5rem;position:relative;box-sizing:border-box;display:grid;gap:.375rem;min-inline-size:0;padding:.75rem;border:1px solid var(--agent-input-border);border-radius:1rem;background:var(--agent-input-surface);color:var(--agent-input-text);color-scheme:light}.agent-input[data-theme=dark]{--agent-input-surface: #1c1c1c;--agent-input-text: #f5f5f5;--agent-input-placeholder: #ababab;--agent-input-border: #4a4a4a;--agent-input-focus: #bdbdbd;--agent-input-tag-background: #363636;--agent-input-agent-color: #f2f2f2;--agent-input-action-background: #f5f5f5;--agent-input-action-hover: #d7d7d7;--agent-input-action-color: #171717;color-scheme:dark}.agent-input:focus-within{border-color:var(--agent-input-focus)}.agent-input__header{min-inline-size:0}.agent-input__body{min-inline-size:0;max-block-size:calc(var(--agent-input-line-height) * var(--agent-input-max-rows));padding-inline:.25rem;overflow:auto}.agent-input__editor{min-block-size:calc(var(--agent-input-line-height) * var(--agent-input-min-rows));overflow-wrap:anywhere;white-space:break-spaces;outline:none;font-size:1rem;line-height:var(--agent-input-line-height)}.agent-input__placeholder{block-size:var(--agent-input-line-height);margin-block-end:calc(-1 * var(--agent-input-line-height));overflow:hidden;color:var(--agent-input-placeholder);font-size:1rem;line-height:var(--agent-input-line-height);text-overflow:ellipsis;white-space:nowrap;pointer-events:none}.agent-input__tag,.agent-input__agent{display:inline-flex;box-sizing:border-box;align-items:center;gap:.3rem;max-inline-size:100%;padding-inline:.4rem;border-radius:.375rem;vertical-align:middle}.agent-input__tag img,.agent-input__agent img{flex:none;inline-size:1rem;block-size:1rem;border-radius:.2rem;object-fit:cover}.agent-input__tag{height:1.25rem;margin-inline:.125rem;max-inline-size:calc(100% - .25rem);padding-block:0;border:0;background:transparent;color:var(--agent-input-tag-color);font:inherit;font-size:.875rem;white-space:nowrap;cursor:pointer}.agent-input__tag:hover,.agent-input__tag:focus-visible{background:var(--agent-input-tag-background)}.agent-input__tag:focus-visible{outline:2px solid var(--agent-input-focus);outline-offset:-2px}.agent-input__agent{float:var(--agent-input-float-start, left);max-inline-size:55%;block-size:var(--agent-input-line-height);margin-inline-end:.375rem;background:var(--agent-input-tag-background);color:var(--agent-input-agent-color);font-size:.875rem}@supports (float: inline-start){.agent-input__agent{--agent-input-float-start: inline-start}}.agent-input__tag-label,.agent-input__agent-label{min-inline-size:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.agent-input__footer{display:flex;justify-content:flex-end;align-items:center;gap:.5rem}.agent-input__footer-content{flex:1 1 0;min-inline-size:0}.agent-input__remove,.agent-input__action{display:grid;flex:none;place-items:center;padding:0;border:0;cursor:pointer}.agent-input__remove svg,.agent-input__action svg{inline-size:1.125rem;block-size:1.125rem}.agent-input__remove path,.agent-input__action path{stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}.agent-input__remove{inline-size:1.75rem;block-size:1.5rem;appearance:none;background:transparent;box-shadow:none;outline:none;color:inherit;-webkit-tap-highlight-color:transparent}.agent-input__remove:focus-visible path{stroke-width:2.6}.agent-input__action{inline-size:2.75rem;block-size:2.75rem;border-radius:.75rem;background:var(--agent-input-action-background);color:var(--agent-input-action-color)}.agent-input__action:hover{background:var(--agent-input-action-hover)}.agent-input__action:focus-visible{outline:2px solid var(--agent-input-focus);outline-offset:2px}.agent-input__suggestion{box-sizing:border-box;min-inline-size:0;max-block-size:min(16rem,var(--agent-input-half-viewport, 50vh));overflow:auto;overscroll-behavior:contain;border-block-end:1px solid var(--agent-input-border)}@supports (height: 1dvh){.agent-input__suggestion{--agent-input-half-viewport: 50dvh}}
package/dist/types.d.ts CHANGED
@@ -26,6 +26,7 @@ export interface AgentInputSendPayload {
26
26
  }
27
27
  export interface AgentInputExpose {
28
28
  focus(): void;
29
+ openSuggestion(trigger: AgentInputTrigger): void;
29
30
  setAgent(item: AgentInputItem | null): void;
30
31
  insertTag(item: AgentInputTag): void;
31
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-agent-input",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "A Vue composer with inline tags and customizable suggestion panels.",
5
5
  "license": "MIT",
6
6
  "keywords": [