@kanzo-tech/ai 0.17.0 → 0.19.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/dist/assist.d.ts +8 -1
- package/dist/assist.d.ts.map +1 -1
- package/dist/assist.js +168 -157
- package/dist/assist.js.map +1 -1
- package/dist/engine.d.ts +15 -4
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +179 -141
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/proposals.d.ts.map +1 -1
- package/dist/proposals.js +40 -28
- package/dist/proposals.js.map +1 -1
- package/package.json +5 -5
package/dist/assist.d.ts
CHANGED
|
@@ -23,11 +23,13 @@ export interface AssistTranslations {
|
|
|
23
23
|
thinking: string;
|
|
24
24
|
/** When the model had nothing to offer. */
|
|
25
25
|
empty: string;
|
|
26
|
+
/** When asking failed and what was thrown carries no message of its own. */
|
|
27
|
+
failed: string;
|
|
26
28
|
/** A candidate's ✕, given the candidate's text. */
|
|
27
29
|
dismiss: (text: string) => string;
|
|
28
30
|
}
|
|
29
31
|
export interface AssistProviderProps {
|
|
30
|
-
/** The model every assisted field below asks — `
|
|
32
|
+
/** The model every assisted field below asks — `gateway("complete")`. */
|
|
31
33
|
model: LanguageModel;
|
|
32
34
|
/**
|
|
33
35
|
* What the rest of the form says, for every field below: read at the moment a field asks, so it
|
|
@@ -36,6 +38,11 @@ export interface AssistProviderProps {
|
|
|
36
38
|
context?: string | (() => string | undefined);
|
|
37
39
|
/** Each proposal's life — shown, accepted, partly accepted, rejected, ignored. */
|
|
38
40
|
onEvent?: (event: AssistEvent) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Called with what the model's stream threw, whole, when a field's ask fails — including an
|
|
43
|
+
* `AiError` coded `ai/silent` when it sent nothing for 30 s. The field also says so under itself.
|
|
44
|
+
*/
|
|
45
|
+
onFailure?: (error: unknown) => void;
|
|
39
46
|
translations?: Partial<AssistTranslations>;
|
|
40
47
|
children: React.ReactNode;
|
|
41
48
|
}
|
package/dist/assist.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assist.d.ts","sourceRoot":"","sources":["../src/assist.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,OAAO,EACL,KAAK,WAAW,EAKjB,MAAM,aAAa,CAAC;AAKrB,0GAA0G;AAC1G,MAAM,WAAW,kBAAkB;IACjC,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAC;IACf,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC;IACf,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,YAAY,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACnC;
|
|
1
|
+
{"version":3,"file":"assist.d.ts","sourceRoot":"","sources":["../src/assist.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,OAAO,EACL,KAAK,WAAW,EAKjB,MAAM,aAAa,CAAC;AAKrB,0GAA0G;AAC1G,MAAM,WAAW,kBAAkB;IACjC,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAC;IACf,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC;IACf,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,YAAY,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACnC;AA6BD,MAAM,WAAW,mBAAmB;IAClC,yEAAyE;IACzE,KAAK,EAAE,aAAa,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC;IAC9C,kFAAkF;IAClF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACvC;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC3C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,qBAaxD;AA4FD,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE;IACtD;;;OAGG;IACH,KAAK,EAAE,CAAC,CAAC;IACT,aAAa,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAClC,qFAAqF;IACrF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iGAAiG;IACjG,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,qBAOxE"}
|
package/dist/assist.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
2
|
+
import { jsx as c, jsxs as E, Fragment as pe } from "react/jsx-runtime";
|
|
3
3
|
import { ark as R } from "@ark-ui/react/factory";
|
|
4
|
-
import { Undo2Icon as
|
|
4
|
+
import { Undo2Icon as ye, XIcon as ve } from "lucide-react";
|
|
5
5
|
import * as l from "react";
|
|
6
|
-
import { cn as M,
|
|
6
|
+
import { cn as M, ButtonGroup as be, Suggestion as xe, Button as ke, Spinner as Ee, Suggestions as Se, Kbd as j } from "@kanzo-tech/ui";
|
|
7
7
|
import { AiMark as U } from "./ai-mark.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
const
|
|
8
|
+
import { useCandidates as Y, useContinuation as Ce, MIN_CONTINUE_LENGTH as Re } from "./engine.js";
|
|
9
|
+
import { candidates as Z, continuation as we } from "./proposals.js";
|
|
10
|
+
const Ne = {
|
|
11
11
|
assist: "AI assist",
|
|
12
12
|
accept: "Accept suggestion",
|
|
13
13
|
others: "Suggest different values",
|
|
@@ -18,31 +18,33 @@ const we = {
|
|
|
18
18
|
announcement: "Suggestion ready. Press Tab to accept, Escape to dismiss.",
|
|
19
19
|
thinking: "Thinking…",
|
|
20
20
|
empty: "Nothing to suggest.",
|
|
21
|
+
failed: "Couldn’t suggest anything.",
|
|
21
22
|
dismiss: (n) => `Dismiss ${n}`
|
|
22
|
-
},
|
|
23
|
-
function
|
|
24
|
-
const { model: t, context: s, onEvent: r, translations:
|
|
23
|
+
}, ee = l.createContext(null);
|
|
24
|
+
function Ue(n) {
|
|
25
|
+
const { model: t, context: s, onEvent: r, onFailure: o, translations: d, children: a } = n, f = l.useMemo(
|
|
25
26
|
() => ({
|
|
26
27
|
model: t,
|
|
27
28
|
context: typeof s == "function" ? s : () => s,
|
|
28
29
|
onEvent: r,
|
|
29
|
-
|
|
30
|
+
onFailure: o,
|
|
31
|
+
t: { ...Ne, ...d }
|
|
30
32
|
}),
|
|
31
|
-
[s, t, r,
|
|
33
|
+
[s, t, r, o, d]
|
|
32
34
|
);
|
|
33
|
-
return /* @__PURE__ */
|
|
35
|
+
return /* @__PURE__ */ c(ee.Provider, { value: f, children: a });
|
|
34
36
|
}
|
|
35
|
-
const
|
|
37
|
+
const Q = (n) => (n ?? "").split(/\s+/).map((t) => {
|
|
36
38
|
var s, r;
|
|
37
39
|
return t ? (r = (s = document.getElementById(t)) == null ? void 0 : s.textContent) == null ? void 0 : r.trim() : "";
|
|
38
40
|
}).filter(Boolean).join(" ");
|
|
39
|
-
function
|
|
40
|
-
return n ? { name:
|
|
41
|
+
function q(n, t, s) {
|
|
42
|
+
return n ? { name: Q(n.getAttribute("aria-labelledby")) || [...n.labels ?? []].map((o) => {
|
|
41
43
|
var d;
|
|
42
|
-
return (d =
|
|
43
|
-
}).filter(Boolean).join(" ") || n.getAttribute("aria-label") || n.getAttribute("placeholder") || "", description:
|
|
44
|
+
return (d = o.textContent) == null ? void 0 : d.trim();
|
|
45
|
+
}).filter(Boolean).join(" ") || n.getAttribute("aria-label") || n.getAttribute("placeholder") || "", description: Q(n.getAttribute("aria-describedby")) || void 0, instructions: t, context: s } : { name: "", instructions: t, context: s };
|
|
44
46
|
}
|
|
45
|
-
const
|
|
47
|
+
const Ae = [
|
|
46
48
|
"fontFamily",
|
|
47
49
|
"fontSize",
|
|
48
50
|
"fontWeight",
|
|
@@ -59,137 +61,139 @@ const Ne = [
|
|
|
59
61
|
"borderBottomWidth",
|
|
60
62
|
"borderLeftWidth"
|
|
61
63
|
], F = (n) => Number.parseFloat(n) || 0;
|
|
62
|
-
function
|
|
63
|
-
const r = n.getBoundingClientRect(),
|
|
64
|
+
function _(n, t, s) {
|
|
65
|
+
const r = n.getBoundingClientRect(), o = t.getBoundingClientRect();
|
|
64
66
|
return {
|
|
65
|
-
insetBlockStart: r.top -
|
|
66
|
-
insetBlockEnd:
|
|
67
|
-
insetInlineStart: s ?
|
|
68
|
-
insetInlineEnd: s ? r.left -
|
|
67
|
+
insetBlockStart: r.top - o.top,
|
|
68
|
+
insetBlockEnd: o.bottom - r.bottom,
|
|
69
|
+
insetInlineStart: s ? o.right - r.right : r.left - o.left,
|
|
70
|
+
insetInlineEnd: s ? r.left - o.left : o.right - r.right
|
|
69
71
|
};
|
|
70
72
|
}
|
|
71
|
-
function
|
|
72
|
-
const s = getComputedStyle(n), r = s.direction === "rtl",
|
|
73
|
+
function Be(n, t) {
|
|
74
|
+
const s = getComputedStyle(n), r = s.direction === "rtl", o = n.offsetWidth - n.clientWidth - F(s.borderLeftWidth) - F(s.borderRightWidth), d = _(n, t, r), a = {
|
|
73
75
|
...d,
|
|
74
|
-
insetInlineEnd: d.insetInlineEnd + (
|
|
76
|
+
insetInlineEnd: d.insetInlineEnd + (o > 0 ? o : 0),
|
|
75
77
|
borderStyle: "solid",
|
|
76
78
|
borderColor: "transparent"
|
|
77
79
|
};
|
|
78
|
-
for (const
|
|
80
|
+
for (const f of Ae) a[f] = s[f];
|
|
79
81
|
return { metrics: a, rtl: r };
|
|
80
82
|
}
|
|
81
|
-
const
|
|
83
|
+
const te = "2.25rem", Ie = (n) => {
|
|
82
84
|
var t;
|
|
83
85
|
return ((t = /^\s*\S+/.exec(n)) == null ? void 0 : t[0]) ?? "";
|
|
84
86
|
}, I = (...n) => (t) => {
|
|
85
87
|
for (const s of n) s == null || s(t);
|
|
86
|
-
},
|
|
88
|
+
}, Te = (...n) => (t) => {
|
|
87
89
|
for (const s of n)
|
|
88
90
|
typeof s == "function" ? s(t) : s && (s.current = t);
|
|
89
91
|
};
|
|
90
|
-
function
|
|
91
|
-
const t = l.useContext(
|
|
92
|
+
function Ge(n) {
|
|
93
|
+
const t = l.useContext(ee);
|
|
92
94
|
if (!t) throw new Error("<Assist> must render inside <AssistProvider>");
|
|
93
|
-
return Array.isArray(n.value) ? /* @__PURE__ */
|
|
95
|
+
return Array.isArray(n.value) ? /* @__PURE__ */ c(Pe, { ...n, settings: t }) : /* @__PURE__ */ c(Ke, { ...n, settings: t });
|
|
94
96
|
}
|
|
95
|
-
const
|
|
96
|
-
function
|
|
97
|
+
const Le = (n) => (n == null ? void 0 : n.querySelector("textarea, input:not([type=hidden])")) ?? null;
|
|
98
|
+
function ne(n, t) {
|
|
97
99
|
return l.useCallback(
|
|
98
100
|
(s, r) => {
|
|
99
|
-
var
|
|
100
|
-
return (
|
|
101
|
+
var o;
|
|
102
|
+
return (o = n.onEvent) == null ? void 0 : o.call(n, { kind: s, proposal: r, field: q(t(), void 0, void 0).name });
|
|
101
103
|
},
|
|
102
104
|
[t, n]
|
|
103
105
|
);
|
|
104
106
|
}
|
|
105
|
-
function
|
|
106
|
-
const { value: t, onValueChange: s, instructions: r, children:
|
|
107
|
+
function Ke(n) {
|
|
108
|
+
const { value: t, onValueChange: s, instructions: r, children: o, className: d, settings: a } = n, { t: f } = a, h = l.useRef(null), m = l.useRef(null), [g, C] = l.useState(!1), [w, P] = l.useState(
|
|
107
109
|
{ metrics: {}, rtl: !1, mark: {} }
|
|
108
|
-
), [
|
|
110
|
+
), [y, v] = l.useState(t.length), [H, O] = l.useState(!1), [N, S] = l.useState(null), u = l.useRef(null), b = l.useCallback(() => m.current, []), T = ne(a, b), L = () => {
|
|
109
111
|
var e;
|
|
110
|
-
return
|
|
111
|
-
}, p =
|
|
112
|
-
source: (e) =>
|
|
112
|
+
return q(m.current, r, (e = a.context) == null ? void 0 : e.call(a));
|
|
113
|
+
}, p = Ce({
|
|
114
|
+
source: (e) => we(a.model, L(), e),
|
|
113
115
|
onEvent: T
|
|
114
|
-
}),
|
|
115
|
-
source: ({ signal: e }) =>
|
|
116
|
+
}), x = Y({
|
|
117
|
+
source: ({ signal: e }) => Z(a.model, L(), { value: t, existing: [t], signal: e, count: 6, list: !1 }),
|
|
116
118
|
existing: [t],
|
|
117
119
|
onEvent: T
|
|
118
|
-
})
|
|
120
|
+
});
|
|
121
|
+
G(a, p), G(a, x);
|
|
122
|
+
const k = g ? p.ghost : "";
|
|
119
123
|
l.useLayoutEffect(() => {
|
|
120
|
-
const e =
|
|
121
|
-
if (!e || !
|
|
122
|
-
C(e instanceof HTMLTextAreaElement), e.style.paddingInlineEnd =
|
|
124
|
+
const e = m.current, i = h.current;
|
|
125
|
+
if (!e || !i) return;
|
|
126
|
+
C(e instanceof HTMLTextAreaElement), e.style.paddingInlineEnd = te;
|
|
123
127
|
const W = () => {
|
|
124
|
-
const
|
|
125
|
-
P({ ...
|
|
128
|
+
const J = Be(e, i), z = _(e, i, J.rtl), he = e instanceof HTMLTextAreaElement ? { insetInlineEnd: z.insetInlineEnd + 4, insetBlockEnd: z.insetBlockEnd + 4 } : { insetInlineEnd: z.insetInlineEnd + 2, insetBlockStart: z.insetBlockStart, height: e.offsetHeight };
|
|
129
|
+
P({ ...J, mark: he });
|
|
126
130
|
};
|
|
127
131
|
if (W(), typeof ResizeObserver > "u") return;
|
|
128
132
|
const V = new ResizeObserver(W);
|
|
129
|
-
return V.observe(e), V.observe(
|
|
133
|
+
return V.observe(e), V.observe(i), () => V.disconnect();
|
|
130
134
|
}, []), l.useLayoutEffect(() => {
|
|
131
|
-
const e =
|
|
132
|
-
!e ||
|
|
135
|
+
const e = m.current, i = u.current;
|
|
136
|
+
!e || i === null || (u.current = null, e.setSelectionRange(i, i), v(i));
|
|
133
137
|
}, [t]);
|
|
134
138
|
const K = l.useCallback(() => {
|
|
135
|
-
const e =
|
|
139
|
+
const e = m.current;
|
|
136
140
|
if (!e || u.current !== null) return;
|
|
137
|
-
const
|
|
138
|
-
if ((e.selectionEnd ??
|
|
141
|
+
const i = e.selectionStart ?? e.value.length;
|
|
142
|
+
if ((e.selectionEnd ?? i) !== i) {
|
|
139
143
|
p.dismiss("ignored");
|
|
140
144
|
return;
|
|
141
145
|
}
|
|
142
|
-
|
|
146
|
+
v(i);
|
|
143
147
|
}, [p]);
|
|
144
148
|
l.useEffect(() => {
|
|
145
149
|
const e = () => {
|
|
146
|
-
document.activeElement ===
|
|
150
|
+
document.activeElement === m.current && K();
|
|
147
151
|
};
|
|
148
152
|
return document.addEventListener("selectionchange", e), () => document.removeEventListener("selectionchange", e);
|
|
149
153
|
}, [K]);
|
|
150
|
-
const D = (e,
|
|
151
|
-
u.current =
|
|
152
|
-
},
|
|
154
|
+
const D = (e, i) => {
|
|
155
|
+
u.current = i, s(e);
|
|
156
|
+
}, $ = () => {
|
|
153
157
|
var e;
|
|
154
|
-
|
|
155
|
-
},
|
|
156
|
-
const e =
|
|
158
|
+
k && (S(t), D(t.slice(0, y) + k + t.slice(y), y + k.length), p.settle("accepted", k), (e = m.current) == null || e.focus());
|
|
159
|
+
}, oe = () => {
|
|
160
|
+
const e = Ie(k);
|
|
157
161
|
if (!e) return;
|
|
158
|
-
const
|
|
159
|
-
D(
|
|
160
|
-
},
|
|
161
|
-
S(t), D(e, e.length),
|
|
162
|
-
}, ie = () => {
|
|
163
|
-
var e;
|
|
164
|
-
N !== null && (D(N, N.length), S(null), (e = f.current) == null || e.focus());
|
|
162
|
+
const i = t.slice(0, y) + e + t.slice(y);
|
|
163
|
+
D(i, y + e.length), p.settle("partial", e), p.setValue(i, y + e.length);
|
|
164
|
+
}, ie = (e) => {
|
|
165
|
+
S(t), D(e, e.length), x.take(e);
|
|
165
166
|
}, ce = () => {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}, le = (
|
|
169
|
-
const
|
|
170
|
-
|
|
167
|
+
var e;
|
|
168
|
+
N !== null && (D(N, N.length), S(null), (e = m.current) == null || e.focus());
|
|
169
|
+
}, le = () => {
|
|
170
|
+
const e = m.current, i = e && e === document.activeElement ? e.selectionStart ?? y : y;
|
|
171
|
+
v(i), p.ask(t, i), e == null || e.focus(), e == null || e.setSelectionRange(i, i);
|
|
171
172
|
}, ae = (e) => {
|
|
173
|
+
const i = e.target, W = i.selectionStart ?? i.value.length;
|
|
174
|
+
v(W), S(null), s(i.value), g && p.setValue(i.value, W);
|
|
175
|
+
}, ue = (e) => {
|
|
172
176
|
if (e.defaultPrevented) return;
|
|
173
|
-
if (!
|
|
174
|
-
e.key === "Escape" &&
|
|
177
|
+
if (!g) {
|
|
178
|
+
e.key === "Escape" && x.items.length > 0 && x.cancel();
|
|
175
179
|
return;
|
|
176
180
|
}
|
|
177
|
-
const
|
|
181
|
+
const i = w.rtl ? "ArrowLeft" : "ArrowRight";
|
|
178
182
|
if (e.altKey && (e.key === "]" || e.key === "[" || e.code === "BracketRight" || e.code === "BracketLeft")) {
|
|
179
183
|
e.preventDefault(), p.cycle(e.key === "]" || e.code === "BracketRight" ? 1 : -1);
|
|
180
184
|
return;
|
|
181
185
|
}
|
|
182
|
-
|
|
183
|
-
},
|
|
186
|
+
k && (e.key === "Tab" ? (e.preventDefault(), $()) : e.key === i && (e.ctrlKey || e.metaKey) ? (e.preventDefault(), oe()) : e.key === "Escape" && p.dismiss("rejected"));
|
|
187
|
+
}, X = o, A = X.props, de = l.cloneElement(X, {
|
|
184
188
|
value: t,
|
|
185
|
-
onChange: I(A.onChange,
|
|
186
|
-
onKeyDown: I(A.onKeyDown,
|
|
189
|
+
onChange: I(A.onChange, ae),
|
|
190
|
+
onKeyDown: I(A.onKeyDown, ue),
|
|
187
191
|
onClick: I(A.onClick, K),
|
|
188
192
|
onKeyUp: I(A.onKeyUp, K),
|
|
189
193
|
onSelect: I(A.onSelect, K),
|
|
190
|
-
ref:
|
|
191
|
-
"aria-keyshortcuts":
|
|
192
|
-
}), B =
|
|
194
|
+
ref: Te(A.ref, m),
|
|
195
|
+
"aria-keyshortcuts": k ? "Tab Escape Alt+]" : void 0
|
|
196
|
+
}), B = g ? k.length > 0 : x.items.length > 0, fe = (g ? p.status : x.status) === "loading" && !B, me = N !== null && !B, ge = !g || t.trim().length >= Re;
|
|
193
197
|
return /* @__PURE__ */ E(
|
|
194
198
|
R.div,
|
|
195
199
|
{
|
|
@@ -201,55 +205,55 @@ function Le(n) {
|
|
|
201
205
|
onFocus: () => O(!0),
|
|
202
206
|
ref: h,
|
|
203
207
|
children: [
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
/* @__PURE__ */
|
|
208
|
+
de,
|
|
209
|
+
g && /* @__PURE__ */ c(We, { caret: y, field: m, ghost: k, metrics: w.metrics, value: t }),
|
|
210
|
+
/* @__PURE__ */ c(
|
|
207
211
|
R.span,
|
|
208
212
|
{
|
|
209
213
|
className: M("absolute flex items-center", w.mark.insetInlineEnd === void 0 && "invisible"),
|
|
210
214
|
"data-slot": "assist-mark",
|
|
211
215
|
style: w.mark,
|
|
212
|
-
children:
|
|
216
|
+
children: me ? /* @__PURE__ */ c(U, { label: f.revert, onClick: ce, children: /* @__PURE__ */ c(ye, {}) }) : /* @__PURE__ */ c(
|
|
213
217
|
U,
|
|
214
218
|
{
|
|
215
|
-
busy:
|
|
216
|
-
disabled: !B && !
|
|
217
|
-
label: B ?
|
|
219
|
+
busy: fe,
|
|
220
|
+
disabled: !B && !ge,
|
|
221
|
+
label: B ? g ? f.accept : f.others : f.assist,
|
|
218
222
|
offering: B,
|
|
219
|
-
onClick:
|
|
223
|
+
onClick: g ? B ? $ : le : x.press
|
|
220
224
|
}
|
|
221
225
|
)
|
|
222
226
|
}
|
|
223
227
|
),
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
/* @__PURE__ */
|
|
227
|
-
/* @__PURE__ */
|
|
228
|
-
] }) : H && /* @__PURE__ */
|
|
228
|
+
g ? /* @__PURE__ */ E(pe, { children: [
|
|
229
|
+
k && /* @__PURE__ */ c(Me, { t: f }),
|
|
230
|
+
/* @__PURE__ */ c("span", { "aria-live": "polite", className: "sr-only", "data-slot": "assist-status", children: k ? f.announcement : "" }),
|
|
231
|
+
/* @__PURE__ */ c(se, { error: p.error, status: p.status, t: f })
|
|
232
|
+
] }) : H && /* @__PURE__ */ c(re, { list: x, onPick: ie, t: f })
|
|
229
233
|
]
|
|
230
234
|
}
|
|
231
235
|
);
|
|
232
236
|
}
|
|
233
|
-
function
|
|
234
|
-
const { field: t, ghost: s, value: r, caret:
|
|
237
|
+
function We(n) {
|
|
238
|
+
const { field: t, ghost: s, value: r, caret: o, metrics: d } = n, a = l.useRef(null);
|
|
235
239
|
l.useLayoutEffect(() => {
|
|
236
|
-
const h = t.current,
|
|
237
|
-
if (!h || !
|
|
240
|
+
const h = t.current, m = a.current;
|
|
241
|
+
if (!h || !m) return;
|
|
238
242
|
if (!s) {
|
|
239
243
|
h.style.removeProperty("min-height");
|
|
240
244
|
return;
|
|
241
245
|
}
|
|
242
|
-
const
|
|
246
|
+
const g = getComputedStyle(h), C = m.scrollHeight + F(g.borderTopWidth) + F(g.borderBottomWidth);
|
|
243
247
|
C > h.getBoundingClientRect().height + 1 && h.style.setProperty("min-height", `${C}px`);
|
|
244
248
|
}, [t, s, r]), l.useLayoutEffect(() => {
|
|
245
|
-
const h = t.current,
|
|
246
|
-
if (!h || !
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
+
const h = t.current, m = a.current;
|
|
250
|
+
if (!h || !m) return;
|
|
251
|
+
const g = () => {
|
|
252
|
+
m.scrollLeft = h.scrollLeft, m.scrollTop = h.scrollTop;
|
|
249
253
|
};
|
|
250
|
-
return
|
|
251
|
-
}, [
|
|
252
|
-
const
|
|
254
|
+
return g(), h.addEventListener("scroll", g), () => h.removeEventListener("scroll", g);
|
|
255
|
+
}, [o, t, s, r]);
|
|
256
|
+
const f = Math.min(o, r.length);
|
|
253
257
|
return /* @__PURE__ */ E(
|
|
254
258
|
R.div,
|
|
255
259
|
{
|
|
@@ -262,40 +266,47 @@ function Ke(n) {
|
|
|
262
266
|
ref: a,
|
|
263
267
|
style: d,
|
|
264
268
|
children: [
|
|
265
|
-
/* @__PURE__ */
|
|
266
|
-
/* @__PURE__ */
|
|
267
|
-
/* @__PURE__ */
|
|
269
|
+
/* @__PURE__ */ c("span", { className: "invisible", children: r.slice(0, f) }),
|
|
270
|
+
/* @__PURE__ */ c("span", { className: "text-faint", children: s }),
|
|
271
|
+
/* @__PURE__ */ c("span", { className: "invisible", children: r.slice(f) })
|
|
268
272
|
]
|
|
269
273
|
}
|
|
270
274
|
);
|
|
271
275
|
}
|
|
272
|
-
function
|
|
276
|
+
function Me({ t: n }) {
|
|
273
277
|
return /* @__PURE__ */ E(R.span, { className: "inline-flex flex-wrap items-center gap-3 text-muted-foreground text-xs", "data-slot": "assist-keys", children: [
|
|
274
278
|
/* @__PURE__ */ E("span", { className: "inline-flex items-center gap-1 whitespace-nowrap", children: [
|
|
275
|
-
/* @__PURE__ */
|
|
279
|
+
/* @__PURE__ */ c(j, { children: "Tab" }),
|
|
276
280
|
" ",
|
|
277
281
|
n.acceptKey
|
|
278
282
|
] }),
|
|
279
283
|
/* @__PURE__ */ E("span", { className: "inline-flex items-center gap-1 whitespace-nowrap", children: [
|
|
280
|
-
/* @__PURE__ */
|
|
284
|
+
/* @__PURE__ */ c(j, { children: "Alt ]" }),
|
|
281
285
|
" ",
|
|
282
286
|
n.nextKey
|
|
283
287
|
] }),
|
|
284
288
|
/* @__PURE__ */ E("span", { className: "inline-flex items-center gap-1 whitespace-nowrap", children: [
|
|
285
|
-
/* @__PURE__ */
|
|
289
|
+
/* @__PURE__ */ c(j, { children: "Esc" }),
|
|
286
290
|
" ",
|
|
287
291
|
n.dismissKey
|
|
288
292
|
] })
|
|
289
293
|
] });
|
|
290
294
|
}
|
|
291
|
-
function
|
|
292
|
-
|
|
295
|
+
function G(n, t) {
|
|
296
|
+
const { onFailure: s } = n, { status: r, error: o } = t;
|
|
297
|
+
l.useEffect(() => {
|
|
298
|
+
r === "error" && (s == null || s(o));
|
|
299
|
+
}, [r, o, s]);
|
|
293
300
|
}
|
|
294
301
|
function se(n) {
|
|
295
|
-
const {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
302
|
+
const { error: t, status: s, t: r } = n;
|
|
303
|
+
return s !== "error" ? null : /* @__PURE__ */ c(R.p, { className: "text-destructive-foreground text-sm", "data-slot": "assist-error", role: "alert", children: t instanceof Error && t.message ? t.message : r.failed });
|
|
304
|
+
}
|
|
305
|
+
function re(n) {
|
|
306
|
+
const { list: t, onPick: s, t: r } = n, o = t.status === "error" ? /* @__PURE__ */ c(se, { error: t.error, status: t.status, t: r }) : t.items.length > 0 ? t.items.map((d) => /* @__PURE__ */ E(be, { "aria-label": d.text, slot: "assist-candidate", children: [
|
|
307
|
+
/* @__PURE__ */ c(xe, { onSelect: s, title: d.rationale, value: d.text, children: d.text }),
|
|
308
|
+
/* @__PURE__ */ c(
|
|
309
|
+
ke,
|
|
299
310
|
{
|
|
300
311
|
"aria-label": r.dismiss(d.text),
|
|
301
312
|
className: "h-auto min-h-[24px] self-stretch px-2 py-1",
|
|
@@ -304,20 +315,20 @@ function se(n) {
|
|
|
304
315
|
size: "sm",
|
|
305
316
|
slot: "assist-dismiss",
|
|
306
317
|
variant: "outline",
|
|
307
|
-
children: /* @__PURE__ */
|
|
318
|
+
children: /* @__PURE__ */ c(ve, {})
|
|
308
319
|
}
|
|
309
320
|
)
|
|
310
321
|
] }, d.text)) : t.status === "loading" ? /* @__PURE__ */ E("span", { className: "inline-flex items-center gap-2 text-muted-foreground text-sm", "data-slot": "assist-pending", children: [
|
|
311
|
-
/* @__PURE__ */
|
|
322
|
+
/* @__PURE__ */ c(Ee, { "aria-hidden": !0 }),
|
|
312
323
|
r.thinking
|
|
313
|
-
] }) : t.status === "ready" ? /* @__PURE__ */
|
|
314
|
-
return
|
|
324
|
+
] }) : t.status === "ready" ? /* @__PURE__ */ c("span", { className: "text-muted-foreground text-sm", "data-slot": "assist-empty", children: r.empty }) : null;
|
|
325
|
+
return o === null ? null : /* @__PURE__ */ c(Se, { className: "min-h-8", slot: "assist-candidates", children: o });
|
|
315
326
|
}
|
|
316
|
-
function
|
|
317
|
-
const { value: t, onValueChange: s, instructions: r, children:
|
|
327
|
+
function Pe(n) {
|
|
328
|
+
const { value: t, onValueChange: s, instructions: r, children: o, className: d, settings: a } = n, { t: f } = a, h = l.useRef(null), [m, g] = l.useState(!1), [C, w] = l.useState({}), P = l.useCallback(() => Le(h.current), []), y = ne(a, P), v = Y({
|
|
318
329
|
source: ({ signal: u }) => {
|
|
319
|
-
var
|
|
320
|
-
return
|
|
330
|
+
var b;
|
|
331
|
+
return Z(a.model, q(P(), r, (b = a.context) == null ? void 0 : b.call(a)), {
|
|
321
332
|
value: "",
|
|
322
333
|
existing: t,
|
|
323
334
|
signal: u,
|
|
@@ -326,61 +337,61 @@ function Me(n) {
|
|
|
326
337
|
});
|
|
327
338
|
},
|
|
328
339
|
existing: t,
|
|
329
|
-
onEvent:
|
|
340
|
+
onEvent: y
|
|
330
341
|
});
|
|
331
|
-
l.useLayoutEffect(() => {
|
|
332
|
-
const u = h.current,
|
|
333
|
-
if (!u || !
|
|
334
|
-
|
|
342
|
+
G(a, v), l.useLayoutEffect(() => {
|
|
343
|
+
const u = h.current, b = (u == null ? void 0 : u.querySelector("[data-part=control]")) ?? (u == null ? void 0 : u.firstElementChild);
|
|
344
|
+
if (!u || !b) return;
|
|
345
|
+
b.style.paddingInlineEnd = te;
|
|
335
346
|
const T = () => {
|
|
336
|
-
const p = getComputedStyle(
|
|
337
|
-
w({ insetInlineEnd:
|
|
347
|
+
const p = getComputedStyle(b).direction === "rtl", x = _(b, u, p);
|
|
348
|
+
w({ insetInlineEnd: x.insetInlineEnd + 2, insetBlockStart: x.insetBlockStart, height: b.offsetHeight });
|
|
338
349
|
};
|
|
339
350
|
if (T(), typeof ResizeObserver > "u") return;
|
|
340
351
|
const L = new ResizeObserver(T);
|
|
341
|
-
return L.observe(
|
|
352
|
+
return L.observe(b), () => L.disconnect();
|
|
342
353
|
}, []);
|
|
343
|
-
const H =
|
|
354
|
+
const H = o, O = H.props, N = l.cloneElement(H, {
|
|
344
355
|
value: t,
|
|
345
356
|
onValueChange: I(O.onValueChange, (u) => s(u.value))
|
|
346
|
-
}), S =
|
|
357
|
+
}), S = v.items.length > 0;
|
|
347
358
|
return /* @__PURE__ */ E(
|
|
348
359
|
R.div,
|
|
349
360
|
{
|
|
350
361
|
className: M("relative flex w-full min-w-0 flex-col gap-2", d),
|
|
351
362
|
"data-slot": "assist",
|
|
352
363
|
onBlur: (u) => {
|
|
353
|
-
u.currentTarget.contains(u.relatedTarget) ||
|
|
364
|
+
u.currentTarget.contains(u.relatedTarget) || g(!1);
|
|
354
365
|
},
|
|
355
|
-
onFocus: () =>
|
|
366
|
+
onFocus: () => g(!0),
|
|
356
367
|
ref: h,
|
|
357
368
|
children: [
|
|
358
369
|
N,
|
|
359
|
-
/* @__PURE__ */
|
|
370
|
+
/* @__PURE__ */ c(
|
|
360
371
|
R.span,
|
|
361
372
|
{
|
|
362
373
|
className: M("absolute flex items-center", C.insetInlineEnd === void 0 && "invisible"),
|
|
363
374
|
"data-slot": "assist-mark",
|
|
364
375
|
style: C,
|
|
365
|
-
children: /* @__PURE__ */
|
|
376
|
+
children: /* @__PURE__ */ c(
|
|
366
377
|
U,
|
|
367
378
|
{
|
|
368
|
-
busy:
|
|
369
|
-
label: S ?
|
|
379
|
+
busy: v.status === "loading" && !S,
|
|
380
|
+
label: S ? f.others : f.assist,
|
|
370
381
|
offering: S,
|
|
371
|
-
onClick:
|
|
382
|
+
onClick: v.press
|
|
372
383
|
}
|
|
373
384
|
)
|
|
374
385
|
}
|
|
375
386
|
),
|
|
376
|
-
|
|
377
|
-
|
|
387
|
+
m && /* @__PURE__ */ c(
|
|
388
|
+
re,
|
|
378
389
|
{
|
|
379
|
-
list:
|
|
390
|
+
list: v,
|
|
380
391
|
onPick: (u) => {
|
|
381
|
-
s([...t, u]),
|
|
392
|
+
s([...t, u]), v.take(u);
|
|
382
393
|
},
|
|
383
|
-
t:
|
|
394
|
+
t: f
|
|
384
395
|
}
|
|
385
396
|
)
|
|
386
397
|
]
|
|
@@ -388,7 +399,7 @@ function Me(n) {
|
|
|
388
399
|
);
|
|
389
400
|
}
|
|
390
401
|
export {
|
|
391
|
-
|
|
392
|
-
|
|
402
|
+
Ge as Assist,
|
|
403
|
+
Ue as AssistProvider
|
|
393
404
|
};
|
|
394
405
|
//# sourceMappingURL=assist.js.map
|