@burdenoff/fe-libs 2026.1113.1 → 2026.1113.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/dist/shared/assistant/askAbout/AskAboutLayer.js +47 -47
- package/dist/shared/assistant/askAbout/askAboutStore.d.ts +7 -0
- package/dist/shared/assistant/askAbout/focus.js +1 -1
- package/dist/shared/assistant/askAbout/placement.d.ts +9 -0
- package/dist/shared/assistant/askAbout/placement.js +5 -1
- package/dist/shared/assistant/askAbout/useAskable.js +6 -5
- package/dist/shared/assistant/i18nManifest.d.ts +40 -0
- package/dist/shared/assistant/i18nManifest.js +40 -0
- package/dist/shared/proactive/ProactiveProvider.d.ts +67 -0
- package/dist/shared/proactive/ProactiveProvider.js +128 -0
- package/dist/shared/proactive/actions.d.ts +101 -0
- package/dist/shared/proactive/actions.js +71 -0
- package/dist/shared/proactive/activity.d.ts +27 -0
- package/dist/shared/proactive/activity.js +37 -0
- package/dist/shared/proactive/adapters.d.ts +54 -0
- package/dist/shared/proactive/adapters.js +62 -0
- package/dist/shared/proactive/anchors.d.ts +47 -0
- package/dist/shared/proactive/anchors.js +53 -0
- package/dist/shared/proactive/budget.d.ts +17 -0
- package/dist/shared/proactive/budget.js +30 -0
- package/dist/shared/proactive/capabilities.d.ts +26 -0
- package/dist/shared/proactive/capabilities.js +63 -0
- package/dist/shared/proactive/coalesce.d.ts +11 -0
- package/dist/shared/proactive/coalesce.js +15 -0
- package/dist/shared/proactive/context.d.ts +42 -0
- package/dist/shared/proactive/context.js +31 -0
- package/dist/shared/proactive/flags.d.ts +5 -0
- package/dist/shared/proactive/flags.js +11 -0
- package/dist/shared/proactive/index.d.ts +40 -0
- package/dist/shared/proactive/metadata.d.ts +48 -0
- package/dist/shared/proactive/metadata.js +126 -0
- package/dist/shared/proactive/operations.d.ts +96 -0
- package/dist/shared/proactive/operations.js +117 -0
- package/dist/shared/proactive/severityCopy.d.ts +4 -0
- package/dist/shared/proactive/severityCopy.js +10 -0
- package/dist/shared/proactive/snooze.d.ts +4 -0
- package/dist/shared/proactive/snooze.js +9 -0
- package/dist/shared/proactive/transport.d.ts +32 -0
- package/dist/shared/proactive/transport.js +124 -0
- package/dist/shared/proactive/types.d.ts +83 -0
- package/dist/shared/proactive/ui/ProactiveInbox.d.ts +20 -0
- package/dist/shared/proactive/ui/ProactiveInbox.js +78 -0
- package/dist/shared/proactive/ui/ProactiveSettingsPanel.d.ts +8 -0
- package/dist/shared/proactive/ui/ProactiveSettingsPanel.js +210 -0
- package/dist/shared/proactive/ui/SuggestionAnchorsLayer.d.ts +9 -0
- package/dist/shared/proactive/ui/SuggestionAnchorsLayer.js +140 -0
- package/dist/shared/proactive/ui/SuggestionBadge.d.ts +11 -0
- package/dist/shared/proactive/ui/SuggestionBadge.js +53 -0
- package/dist/shared/proactive/ui/SuggestionCard.d.ts +23 -0
- package/dist/shared/proactive/ui/SuggestionCard.js +119 -0
- package/dist/shared/proactive/ui/anchorLayerDom.d.ts +28 -0
- package/dist/shared/proactive/ui/anchorLayerDom.js +23 -0
- package/dist/shared/proactive/useProactiveSession.d.ts +56 -0
- package/dist/shared/proactive/useProactiveSession.js +150 -0
- package/dist/shared/proactive/useSuggestionControls.d.ts +25 -0
- package/dist/shared/proactive/useSuggestionControls.js +118 -0
- package/dist/shared-assistant.js +301 -301
- package/dist/shared-proactive.d.ts +2 -0
- package/dist/shared-proactive.js +21 -0
- package/package.json +5 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { usePrefersReducedMotion as e } from "../../assistant/ui/usePrefersReducedMotion.js";
|
|
2
|
+
import { Popover as t, PopoverContent as n, PopoverTrigger as r } from "../../../ui/popover.js";
|
|
3
|
+
import { cn as i } from "../../utils/cn.js";
|
|
4
|
+
import { useProactiveOrNull as a } from "../context.js";
|
|
5
|
+
import { SuggestionCard as o } from "./SuggestionCard.js";
|
|
6
|
+
import { useId as s, useState as c } from "react";
|
|
7
|
+
import { Sparkles as l } from "lucide-react";
|
|
8
|
+
import { jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
9
|
+
// src/shared/proactive/ui/ProactiveInbox.tsx
|
|
10
|
+
function f({ className: e, onSettled: t, hideHeading: n = !1 }) {
|
|
11
|
+
let r = a(), c = s();
|
|
12
|
+
if (!r || r.status !== "ready") return null;
|
|
13
|
+
let l = r.controls.tr, { suggestions: f, controls: p } = r;
|
|
14
|
+
return /* @__PURE__ */ d("section", {
|
|
15
|
+
"aria-labelledby": n ? void 0 : c,
|
|
16
|
+
"aria-label": n ? l("proactive.inbox.title", "Suggestions") : void 0,
|
|
17
|
+
"data-agent": "deny",
|
|
18
|
+
"data-proactive-ui": "",
|
|
19
|
+
"data-testid": "proactive-inbox",
|
|
20
|
+
className: i("flex flex-col gap-3", e),
|
|
21
|
+
children: [n ? null : /* @__PURE__ */ u("h2", {
|
|
22
|
+
id: c,
|
|
23
|
+
className: "text-sm font-semibold text-text-primary",
|
|
24
|
+
children: l("proactive.inbox.title", "Suggestions")
|
|
25
|
+
}), f.length === 0 ? /* @__PURE__ */ u("p", {
|
|
26
|
+
className: "text-xs text-text-secondary",
|
|
27
|
+
children: l("proactive.inbox.empty", "No suggestions right now. When the assistant finds something worth a look, it shows up here.")
|
|
28
|
+
}) : /* @__PURE__ */ u("ul", {
|
|
29
|
+
className: "flex flex-col gap-2",
|
|
30
|
+
children: f.map((e) => /* @__PURE__ */ u("li", {
|
|
31
|
+
className: "rounded-card border border-border-subtle bg-bg-surface p-3",
|
|
32
|
+
children: /* @__PURE__ */ u(o, {
|
|
33
|
+
suggestion: e,
|
|
34
|
+
controls: p,
|
|
35
|
+
headingLevel: "h3",
|
|
36
|
+
...t ? { onSettled: t } : {}
|
|
37
|
+
})
|
|
38
|
+
}, e.notificationId))
|
|
39
|
+
})]
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function p({ className: o, side: s = "bottom", align: p = "end" }) {
|
|
43
|
+
let m = a(), [h, g] = c(!1), _ = e();
|
|
44
|
+
if (!m || m.status !== "ready") return null;
|
|
45
|
+
let v = m.controls.tr, y = m.suggestions.length;
|
|
46
|
+
return /* @__PURE__ */ d(t, {
|
|
47
|
+
open: h,
|
|
48
|
+
onOpenChange: g,
|
|
49
|
+
children: [/* @__PURE__ */ u(r, {
|
|
50
|
+
asChild: !0,
|
|
51
|
+
children: /* @__PURE__ */ d("button", {
|
|
52
|
+
type: "button",
|
|
53
|
+
"aria-label": y === 0 ? v("proactive.inbox.button", "Suggestions") : v("proactive.inbox.buttonWithCount", "Suggestions ({{count}})", { count: y }),
|
|
54
|
+
"data-agent": "deny",
|
|
55
|
+
"data-proactive-ui": "",
|
|
56
|
+
"data-testid": "proactive-inbox-button",
|
|
57
|
+
className: i("relative inline-flex size-9 items-center justify-center rounded-button text-text-secondary outline-none", "hover:bg-action-ghost-bgHover hover:text-text-primary motion-safe:transition-colors", "focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)]", o),
|
|
58
|
+
children: [/* @__PURE__ */ u(l, {
|
|
59
|
+
"aria-hidden": "true",
|
|
60
|
+
className: "size-4"
|
|
61
|
+
}), y > 0 ? /* @__PURE__ */ u("span", {
|
|
62
|
+
"aria-hidden": "true",
|
|
63
|
+
className: "absolute -top-0.5 -end-0.5 min-w-4 rounded-full bg-action-primary-bg px-1 text-[10px] font-semibold leading-4 text-action-primary-text",
|
|
64
|
+
children: y > 9 ? "9+" : y
|
|
65
|
+
}) : null]
|
|
66
|
+
})
|
|
67
|
+
}), /* @__PURE__ */ u(n, {
|
|
68
|
+
side: s,
|
|
69
|
+
align: p,
|
|
70
|
+
collisionPadding: 8,
|
|
71
|
+
"data-agent": "deny",
|
|
72
|
+
"data-proactive-ui": "",
|
|
73
|
+
className: i("max-h-[min(32rem,80vh)] w-96 max-w-[calc(100vw-1rem)] overflow-y-auto p-3", _ && "animate-none!"),
|
|
74
|
+
children: /* @__PURE__ */ u(f, { onSettled: y <= 1 ? () => g(!1) : void 0 })
|
|
75
|
+
})]
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
export { f as ProactiveInbox, p as ProactiveInboxButton };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ProactiveSettingsPanelProps {
|
|
2
|
+
/** The product's display name for the consent copy. Default: "this app". */
|
|
3
|
+
productName?: string;
|
|
4
|
+
/** Where the user's notification settings (quiet hours, channels) live. */
|
|
5
|
+
notificationSettingsHref?: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function ProactiveSettingsPanel({ productName, notificationSettingsHref, className, }: ProactiveSettingsPanelProps): import('react').JSX.Element | null;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { Button as e } from "../../../ui/button.js";
|
|
2
|
+
import { Switch as t } from "../../../ui/switch.js";
|
|
3
|
+
import { useOptionalI18n as n } from "../../providers/shell/I18nProvider.js";
|
|
4
|
+
import { cn as r } from "../../utils/cn.js";
|
|
5
|
+
import { useProactiveOrNull as i } from "../context.js";
|
|
6
|
+
import { useId as a, useMemo as o, useState as s } from "react";
|
|
7
|
+
import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
8
|
+
// src/shared/proactive/ui/ProactiveSettingsPanel.tsx
|
|
9
|
+
function d() {
|
|
10
|
+
let e = n()?.locale, t = o(() => {
|
|
11
|
+
try {
|
|
12
|
+
return new Intl.DateTimeFormat(e, { dateStyle: "medium" });
|
|
13
|
+
} catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}, [e]);
|
|
17
|
+
return (e) => {
|
|
18
|
+
let n = Date.parse(e);
|
|
19
|
+
return Number.isFinite(n) ? t ? t.format(new Date(n)) : new Date(n).toISOString().slice(0, 10) : null;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function f({ productName: t, notificationSettingsHref: n, className: a }) {
|
|
23
|
+
let o = i();
|
|
24
|
+
if (!o) return null;
|
|
25
|
+
let { status: s, settings: d } = o;
|
|
26
|
+
if (s === "disabled" || s === "unsupported") return null;
|
|
27
|
+
let f = o.controls.tr;
|
|
28
|
+
return d ? /* @__PURE__ */ l(v, {
|
|
29
|
+
proactive: o,
|
|
30
|
+
settings: d,
|
|
31
|
+
productName: t ?? f("proactive.settings.productFallback", "this app"),
|
|
32
|
+
notificationSettingsHref: n,
|
|
33
|
+
className: a
|
|
34
|
+
}) : /* @__PURE__ */ l("section", {
|
|
35
|
+
"data-proactive-ui": "",
|
|
36
|
+
"data-testid": "proactive-settings",
|
|
37
|
+
className: r("flex flex-col gap-2", a),
|
|
38
|
+
children: s === "error" ? /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("p", {
|
|
39
|
+
className: "text-sm text-text-secondary",
|
|
40
|
+
children: f("proactive.settings.loadFailed", "Your suggestion settings couldn't be loaded.")
|
|
41
|
+
}), /* @__PURE__ */ l("div", { children: /* @__PURE__ */ l(e, {
|
|
42
|
+
type: "button",
|
|
43
|
+
size: "sm",
|
|
44
|
+
variant: "outline",
|
|
45
|
+
onClick: o.refresh,
|
|
46
|
+
children: f("proactive.settings.retry", "Try again")
|
|
47
|
+
}) })] }) : /* @__PURE__ */ l("p", {
|
|
48
|
+
className: "text-sm text-text-secondary",
|
|
49
|
+
children: f("proactive.settings.loading", "Loading your suggestion settings…")
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function p(e, t) {
|
|
54
|
+
let [n, r] = s({}), [i, a] = s(!1), [o, c] = s(null), l = n.enabled ?? t.enabled, u = n.frequency ?? t.frequency, d = l && u !== t.frequency, f = l !== t.enabled || d;
|
|
55
|
+
return {
|
|
56
|
+
enabled: l,
|
|
57
|
+
frequency: u,
|
|
58
|
+
dirty: f,
|
|
59
|
+
saving: i,
|
|
60
|
+
notice: o,
|
|
61
|
+
setEnabled: (e) => r((t) => ({
|
|
62
|
+
...t,
|
|
63
|
+
enabled: e
|
|
64
|
+
})),
|
|
65
|
+
setFrequency: (e) => r((t) => ({
|
|
66
|
+
...t,
|
|
67
|
+
frequency: e
|
|
68
|
+
})),
|
|
69
|
+
submit: async (t) => {
|
|
70
|
+
if (t.preventDefault(), !i && f) {
|
|
71
|
+
a(!0), c(null);
|
|
72
|
+
try {
|
|
73
|
+
let t = await e.saveSettings({
|
|
74
|
+
enabled: l,
|
|
75
|
+
...d ? { frequency: u } : {}
|
|
76
|
+
});
|
|
77
|
+
t.status === "saved" && r({}), c(m(t));
|
|
78
|
+
} catch {
|
|
79
|
+
c("failed");
|
|
80
|
+
} finally {
|
|
81
|
+
a(!1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function m(e) {
|
|
88
|
+
return e.status === "saved" ? e.frequencyUnavailable ? "frequency-unavailable" : "saved" : "failed";
|
|
89
|
+
}
|
|
90
|
+
function h({ tr: e, name: t, value: n, disabled: r, onChange: i }) {
|
|
91
|
+
let a = [
|
|
92
|
+
{
|
|
93
|
+
value: "IMMEDIATE",
|
|
94
|
+
label: e("proactive.settings.frequency.immediate", "As they come")
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
value: "DAILY_DIGEST",
|
|
98
|
+
label: e("proactive.settings.frequency.daily", "In a daily digest")
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
value: "WEEKLY_DIGEST",
|
|
102
|
+
label: e("proactive.settings.frequency.weekly", "In a weekly digest")
|
|
103
|
+
}
|
|
104
|
+
];
|
|
105
|
+
return /* @__PURE__ */ u("fieldset", {
|
|
106
|
+
className: "flex flex-col gap-2",
|
|
107
|
+
disabled: r,
|
|
108
|
+
children: [/* @__PURE__ */ l("legend", {
|
|
109
|
+
className: "mb-1 text-sm font-medium text-text-primary",
|
|
110
|
+
children: e("proactive.settings.frequencyLegend", "When you're away, send suggestions")
|
|
111
|
+
}), a.map((e) => /* @__PURE__ */ u("label", {
|
|
112
|
+
className: "flex items-center gap-2 text-sm text-text-primary",
|
|
113
|
+
children: [/* @__PURE__ */ l("input", {
|
|
114
|
+
type: "radio",
|
|
115
|
+
name: t,
|
|
116
|
+
value: e.value,
|
|
117
|
+
checked: n === e.value,
|
|
118
|
+
onChange: () => i(e.value),
|
|
119
|
+
className: "size-4 accent-action-primary-bg"
|
|
120
|
+
}), e.label]
|
|
121
|
+
}, e.value))]
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function g(e, t) {
|
|
125
|
+
switch (t) {
|
|
126
|
+
case "saved": return e("proactive.settings.saved", "Saved.");
|
|
127
|
+
case "frequency-unavailable": return e("proactive.settings.frequencyUnavailable", "Saved. The delivery choice can't be stored yet, so suggestions arrive as they come.");
|
|
128
|
+
case "failed": return e("proactive.settings.saveFailed", "Your settings couldn't be saved. Try again.");
|
|
129
|
+
case null: return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function _({ tr: t, saving: n, dirty: r, notice: i }) {
|
|
133
|
+
return /* @__PURE__ */ u("div", {
|
|
134
|
+
className: "flex items-center gap-3",
|
|
135
|
+
children: [/* @__PURE__ */ l(e, {
|
|
136
|
+
type: "submit",
|
|
137
|
+
size: "sm",
|
|
138
|
+
disabled: n || !r,
|
|
139
|
+
"aria-busy": n || void 0,
|
|
140
|
+
children: n ? t("proactive.settings.saving", "Saving…") : t("proactive.settings.save", "Save")
|
|
141
|
+
}), /* @__PURE__ */ l("p", {
|
|
142
|
+
role: "status",
|
|
143
|
+
className: "text-xs text-text-secondary",
|
|
144
|
+
children: g(t, i)
|
|
145
|
+
})]
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function v({ proactive: e, settings: n, productName: i, notificationSettingsHref: o, className: s }) {
|
|
149
|
+
let c = e.controls.tr, f = a(), m = d(), g = p(e, n), v = n.enabled && n.consentExpiresAt ? m(n.consentExpiresAt) : null;
|
|
150
|
+
return /* @__PURE__ */ u("section", {
|
|
151
|
+
"aria-labelledby": `${f}-title`,
|
|
152
|
+
"data-proactive-ui": "",
|
|
153
|
+
"data-testid": "proactive-settings",
|
|
154
|
+
className: r("flex flex-col gap-4", s),
|
|
155
|
+
children: [/* @__PURE__ */ u("div", {
|
|
156
|
+
className: "flex flex-col gap-1",
|
|
157
|
+
children: [/* @__PURE__ */ l("h2", {
|
|
158
|
+
id: `${f}-title`,
|
|
159
|
+
className: "text-base font-semibold text-text-primary",
|
|
160
|
+
children: c("proactive.settings.title", "Proactive suggestions")
|
|
161
|
+
}), /* @__PURE__ */ l("p", {
|
|
162
|
+
id: `${f}-consent`,
|
|
163
|
+
className: "text-sm leading-relaxed text-text-secondary",
|
|
164
|
+
children: c("proactive.settings.consent", "When this is on, the assistant looks through {{product}} in the background to find problems and opportunities. It reads as you and only reads: it never changes anything, and every suggestion waits for you to act on it.", { product: i })
|
|
165
|
+
})]
|
|
166
|
+
}), /* @__PURE__ */ u("form", {
|
|
167
|
+
className: "flex flex-col gap-4",
|
|
168
|
+
onSubmit: (e) => void g.submit(e),
|
|
169
|
+
children: [
|
|
170
|
+
/* @__PURE__ */ u("div", {
|
|
171
|
+
className: "flex items-center gap-3",
|
|
172
|
+
children: [/* @__PURE__ */ l(t, {
|
|
173
|
+
id: `${f}-enabled`,
|
|
174
|
+
checked: g.enabled,
|
|
175
|
+
onCheckedChange: g.setEnabled,
|
|
176
|
+
"aria-describedby": `${f}-consent`,
|
|
177
|
+
disabled: g.saving
|
|
178
|
+
}), /* @__PURE__ */ l("label", {
|
|
179
|
+
htmlFor: `${f}-enabled`,
|
|
180
|
+
className: "text-sm font-medium text-text-primary",
|
|
181
|
+
children: c("proactive.settings.toggle", "Let the assistant look for suggestions")
|
|
182
|
+
})]
|
|
183
|
+
}),
|
|
184
|
+
g.enabled ? /* @__PURE__ */ l(h, {
|
|
185
|
+
tr: c,
|
|
186
|
+
name: `${f}-frequency`,
|
|
187
|
+
value: g.frequency,
|
|
188
|
+
disabled: g.saving,
|
|
189
|
+
onChange: g.setFrequency
|
|
190
|
+
}) : null,
|
|
191
|
+
v ? /* @__PURE__ */ l("p", {
|
|
192
|
+
className: "text-xs text-text-secondary",
|
|
193
|
+
children: c("proactive.settings.consentUntil", "Your permission lasts until {{date}}. Turning this off withdraws it at once.", { date: v })
|
|
194
|
+
}) : null,
|
|
195
|
+
o ? /* @__PURE__ */ l("a", {
|
|
196
|
+
href: o,
|
|
197
|
+
className: "text-xs text-text-link underline-offset-4 hover:underline",
|
|
198
|
+
children: c("proactive.settings.quietHours", "Quiet hours and delivery channels")
|
|
199
|
+
}) : null,
|
|
200
|
+
/* @__PURE__ */ l(_, {
|
|
201
|
+
tr: c,
|
|
202
|
+
saving: g.saving,
|
|
203
|
+
dirty: g.dirty,
|
|
204
|
+
notice: g.notice
|
|
205
|
+
})
|
|
206
|
+
]
|
|
207
|
+
})]
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
export { f as ProactiveSettingsPanel };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SuggestionControls } from '../adapters';
|
|
2
|
+
import { ProactiveSuggestion } from '../types';
|
|
3
|
+
export interface SuggestionAnchorsLayerProps {
|
|
4
|
+
/** Severity-ordered live suggestions. */
|
|
5
|
+
suggestions: readonly ProactiveSuggestion[];
|
|
6
|
+
controls: SuggestionControls;
|
|
7
|
+
maxVisiblePins: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function SuggestionAnchorsLayer({ suggestions, controls, maxVisiblePins, }: SuggestionAnchorsLayerProps): import('react').ReactPortal | null;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { SUGGEST_ANCHOR_ATTRIBUTE as e, findAnchorElement as t, queryAnchorCandidates as n } from "../anchors.js";
|
|
2
|
+
import { EMPTY_CONTROLS as r, getSuggestionAnchorAdapter as i, getSuggestionAnchorAdapterVersion as a, listSuggestionAnchorAdapterTypes as o, subscribeSuggestionAnchorAdapters as s } from "../adapters.js";
|
|
3
|
+
import { selectPinnedSuggestions as c } from "../budget.js";
|
|
4
|
+
import { OWN_SELECTOR as l, mutationsConcernAnchors as u, pinPositionFor as d } from "./anchorLayerDom.js";
|
|
5
|
+
import { SuggestionBadge as f } from "./SuggestionBadge.js";
|
|
6
|
+
import { memo as p, useCallback as m, useEffect as h, useRef as g, useState as _, useSyncExternalStore as v } from "react";
|
|
7
|
+
import { jsx as y } from "react/jsx-runtime";
|
|
8
|
+
import { createPortal as b } from "react-dom";
|
|
9
|
+
// src/shared/proactive/ui/SuggestionAnchorsLayer.tsx
|
|
10
|
+
var x = 2e3;
|
|
11
|
+
function S(e, t) {
|
|
12
|
+
return e.length === t.length && e.every((e, n) => e.suggestion === t[n]?.suggestion && e.element === t[n]?.element);
|
|
13
|
+
}
|
|
14
|
+
function C(e, t) {
|
|
15
|
+
return e !== void 0 && e.length === t.length && e.every((e, n) => e === t[n]);
|
|
16
|
+
}
|
|
17
|
+
function w({ suggestions: d, controls: f, maxVisiblePins: p }) {
|
|
18
|
+
let w = v(s, a, () => 0), [T, E] = _([]), O = g(/* @__PURE__ */ new Map()), k = g({
|
|
19
|
+
suggestions: d,
|
|
20
|
+
controls: f,
|
|
21
|
+
maxVisiblePins: p
|
|
22
|
+
});
|
|
23
|
+
h(() => {
|
|
24
|
+
k.current = {
|
|
25
|
+
suggestions: d,
|
|
26
|
+
controls: f,
|
|
27
|
+
maxVisiblePins: p
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
let A = m(() => {
|
|
31
|
+
let { suggestions: e, controls: r, maxVisiblePins: a } = k.current, s = n(document).filter((e) => e.closest(l) === null), u = /* @__PURE__ */ new Map(), d = c(e, (e) => {
|
|
32
|
+
let n = i(e.anchor.entityType);
|
|
33
|
+
if (n) return n.canResolve?.(e.anchor) ?? !0;
|
|
34
|
+
let r = t(s, e.anchor);
|
|
35
|
+
return r && u.set(e.notificationId, r), r !== null;
|
|
36
|
+
}, a), f = /* @__PURE__ */ new Map(), p = [];
|
|
37
|
+
for (let e of d) {
|
|
38
|
+
let t = e.anchor.entityType, n = u.get(e.notificationId);
|
|
39
|
+
i(t) ? f.set(t, [...f.get(t) ?? [], e]) : n && p.push({
|
|
40
|
+
suggestion: e,
|
|
41
|
+
element: n
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
for (let e of o()) {
|
|
45
|
+
let t = i(e);
|
|
46
|
+
if (!t) continue;
|
|
47
|
+
let n = f.get(e) ?? [], a = O.current.get(e);
|
|
48
|
+
a && a.adapter === t && a.controls === r && C(a.suggestions, n) || (O.current.set(e, {
|
|
49
|
+
adapter: t,
|
|
50
|
+
suggestions: n,
|
|
51
|
+
controls: r
|
|
52
|
+
}), t.update(n, r));
|
|
53
|
+
}
|
|
54
|
+
for (let e of [...O.current.keys()]) i(e) || O.current.delete(e);
|
|
55
|
+
E((e) => S(e, p) ? e : p);
|
|
56
|
+
}, []), j = g(null), M = m(() => {
|
|
57
|
+
j.current === null && (j.current = requestAnimationFrame(() => {
|
|
58
|
+
j.current = null, A();
|
|
59
|
+
}));
|
|
60
|
+
}, [A]);
|
|
61
|
+
return h(() => {
|
|
62
|
+
if (typeof document > "u" || !document.body) return;
|
|
63
|
+
let t = typeof MutationObserver > "u" ? null : new MutationObserver((e) => {
|
|
64
|
+
u(e) && M();
|
|
65
|
+
});
|
|
66
|
+
t?.observe(document.body, {
|
|
67
|
+
childList: !0,
|
|
68
|
+
subtree: !0,
|
|
69
|
+
attributes: !0,
|
|
70
|
+
attributeFilter: [e]
|
|
71
|
+
}), window.addEventListener("resize", M);
|
|
72
|
+
let n = window.setInterval(M, x);
|
|
73
|
+
return () => {
|
|
74
|
+
t?.disconnect(), window.removeEventListener("resize", M), window.clearInterval(n), j.current !== null && cancelAnimationFrame(j.current), j.current = null;
|
|
75
|
+
};
|
|
76
|
+
}, [M]), h(() => {
|
|
77
|
+
M();
|
|
78
|
+
}, [
|
|
79
|
+
d,
|
|
80
|
+
f,
|
|
81
|
+
p,
|
|
82
|
+
w,
|
|
83
|
+
M
|
|
84
|
+
]), h(() => {
|
|
85
|
+
let e = O.current;
|
|
86
|
+
return () => {
|
|
87
|
+
for (let t of e.keys()) i(t)?.update([], r);
|
|
88
|
+
e.clear();
|
|
89
|
+
};
|
|
90
|
+
}, []), typeof document > "u" || !document.body || T.length === 0 ? null : b(/* @__PURE__ */ y("div", {
|
|
91
|
+
"data-proactive-ui": "",
|
|
92
|
+
"data-agent": "deny",
|
|
93
|
+
"data-testid": "proactive-anchor-layer",
|
|
94
|
+
children: T.map((e) => /* @__PURE__ */ y(D, {
|
|
95
|
+
suggestion: e.suggestion,
|
|
96
|
+
element: e.element,
|
|
97
|
+
controls: f
|
|
98
|
+
}, e.suggestion.notificationId))
|
|
99
|
+
}), document.body);
|
|
100
|
+
}
|
|
101
|
+
function T(e, t) {
|
|
102
|
+
return e !== null && e.top === t.top && e.left === t.left && e.visible === t.visible;
|
|
103
|
+
}
|
|
104
|
+
function E(e) {
|
|
105
|
+
let t = typeof getComputedStyle == "function" && getComputedStyle(document.documentElement).direction === "rtl";
|
|
106
|
+
return d(e.getBoundingClientRect(), {
|
|
107
|
+
width: window.innerWidth,
|
|
108
|
+
height: window.innerHeight
|
|
109
|
+
}, t);
|
|
110
|
+
}
|
|
111
|
+
var D = p(function({ suggestion: e, element: t, controls: n }) {
|
|
112
|
+
let [r, i] = _(null);
|
|
113
|
+
return h(() => {
|
|
114
|
+
let e = null, n = () => {
|
|
115
|
+
e === null && (e = requestAnimationFrame(() => {
|
|
116
|
+
e = null;
|
|
117
|
+
let n = E(t);
|
|
118
|
+
i((e) => T(e, n) ? e : n);
|
|
119
|
+
}));
|
|
120
|
+
};
|
|
121
|
+
n();
|
|
122
|
+
let r = typeof ResizeObserver > "u" ? null : new ResizeObserver(n);
|
|
123
|
+
return r?.observe(t), window.addEventListener("scroll", n, !0), window.addEventListener("resize", n), () => {
|
|
124
|
+
r?.disconnect(), window.removeEventListener("scroll", n, !0), window.removeEventListener("resize", n), e !== null && cancelAnimationFrame(e);
|
|
125
|
+
};
|
|
126
|
+
}, [t]), !r || !r.visible ? null : /* @__PURE__ */ y("div", {
|
|
127
|
+
"data-proactive-ui": "",
|
|
128
|
+
"data-agent": "deny",
|
|
129
|
+
className: "fixed z-30",
|
|
130
|
+
style: {
|
|
131
|
+
top: r.top,
|
|
132
|
+
left: r.left
|
|
133
|
+
},
|
|
134
|
+
children: /* @__PURE__ */ y(f, {
|
|
135
|
+
suggestion: e,
|
|
136
|
+
controls: n
|
|
137
|
+
})
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
export { w as SuggestionAnchorsLayer };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SuggestionControls } from '../adapters';
|
|
2
|
+
import { ProactiveSuggestion } from '../types';
|
|
3
|
+
export interface SuggestionBadgeProps {
|
|
4
|
+
suggestion: ProactiveSuggestion;
|
|
5
|
+
controls: SuggestionControls;
|
|
6
|
+
/** Which side of the badge the card opens on. Default `bottom`. */
|
|
7
|
+
side?: 'top' | 'right' | 'bottom' | 'left';
|
|
8
|
+
align?: 'start' | 'center' | 'end';
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function SuggestionBadge({ suggestion, controls, side, align, className, }: SuggestionBadgeProps): import('react').JSX.Element;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { usePrefersReducedMotion as e } from "../../assistant/ui/usePrefersReducedMotion.js";
|
|
2
|
+
import { Popover as t, PopoverContent as n, PopoverTrigger as r } from "../../../ui/popover.js";
|
|
3
|
+
import { cn as i } from "../../utils/cn.js";
|
|
4
|
+
import { SuggestionCard as a } from "./SuggestionCard.js";
|
|
5
|
+
import { useState as o } from "react";
|
|
6
|
+
import { Sparkles as s } from "lucide-react";
|
|
7
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
8
|
+
// src/shared/proactive/ui/SuggestionBadge.tsx
|
|
9
|
+
var u = {
|
|
10
|
+
urgent: "border-status-error-border text-status-error-text bg-status-error-bg-subtle",
|
|
11
|
+
high: "border-status-warning-border text-status-warning-text bg-status-warning-bg-subtle",
|
|
12
|
+
medium: "border-status-info-border text-status-info-text bg-status-info-bg-subtle",
|
|
13
|
+
low: "border-border-default text-text-secondary bg-bg-elevated"
|
|
14
|
+
};
|
|
15
|
+
function d({ suggestion: d, controls: f, side: p = "bottom", align: m = "start", className: h }) {
|
|
16
|
+
let g = f.tr, [_, v] = o(!1), y = e();
|
|
17
|
+
return /* @__PURE__ */ l(t, {
|
|
18
|
+
open: _,
|
|
19
|
+
onOpenChange: (e) => {
|
|
20
|
+
v(e), e && f.markSeen(d);
|
|
21
|
+
},
|
|
22
|
+
children: [/* @__PURE__ */ c(r, {
|
|
23
|
+
asChild: !0,
|
|
24
|
+
children: /* @__PURE__ */ c("button", {
|
|
25
|
+
type: "button",
|
|
26
|
+
"aria-label": g("proactive.pin.label", "AI suggestion: {{title}}", { title: d.title }),
|
|
27
|
+
"data-agent": "deny",
|
|
28
|
+
"data-proactive-ui": "",
|
|
29
|
+
"data-testid": "proactive-suggestion-pin",
|
|
30
|
+
"data-severity": d.severity,
|
|
31
|
+
className: i("inline-flex size-6 items-center justify-center rounded-full border shadow-elevation-2 outline-none", "motion-safe:transition-colors hover:border-border-strong", "focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)]", u[d.severity], h),
|
|
32
|
+
children: /* @__PURE__ */ c(s, {
|
|
33
|
+
"aria-hidden": "true",
|
|
34
|
+
className: "size-3.5"
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
}), /* @__PURE__ */ c(n, {
|
|
38
|
+
side: p,
|
|
39
|
+
align: m,
|
|
40
|
+
collisionPadding: 8,
|
|
41
|
+
"aria-label": g("proactive.pin.cardLabel", "AI suggestion"),
|
|
42
|
+
"data-agent": "deny",
|
|
43
|
+
"data-proactive-ui": "",
|
|
44
|
+
className: i("w-80 max-w-[calc(100vw-1rem)] p-3", y && "animate-none!"),
|
|
45
|
+
children: /* @__PURE__ */ c(a, {
|
|
46
|
+
suggestion: d,
|
|
47
|
+
controls: f,
|
|
48
|
+
onSettled: () => v(!1)
|
|
49
|
+
})
|
|
50
|
+
})]
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export { d as SuggestionBadge };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { AssistantTr } from '../../assistant/i18n';
|
|
3
|
+
import { SuggestionControls } from '../adapters';
|
|
4
|
+
import { ProactiveSeverity, ProactiveSuggestion } from '../types';
|
|
5
|
+
export declare function SeverityBadge({ severity, tr }: {
|
|
6
|
+
severity: ProactiveSeverity;
|
|
7
|
+
tr: AssistantTr;
|
|
8
|
+
}): import('react').JSX.Element;
|
|
9
|
+
export declare function AiBadge({ tr }: {
|
|
10
|
+
tr: AssistantTr;
|
|
11
|
+
}): import('react').JSX.Element;
|
|
12
|
+
export interface SuggestionCardProps {
|
|
13
|
+
suggestion: ProactiveSuggestion;
|
|
14
|
+
controls: SuggestionControls;
|
|
15
|
+
/** Called after an action ran, or the suggestion was dismissed or snoozed. */
|
|
16
|
+
onSettled?: () => void;
|
|
17
|
+
/** Heading level of the title; the inbox nests cards under its own heading. */
|
|
18
|
+
headingLevel?: 'h3' | 'h4';
|
|
19
|
+
/** Extra content under the buttons (e.g. a product's "open" link). */
|
|
20
|
+
footer?: ReactNode;
|
|
21
|
+
className?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function SuggestionCard({ suggestion, controls, onSettled, headingLevel, footer, className, }: SuggestionCardProps): import('react').JSX.Element;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Badge as e } from "../../../ui/badge.js";
|
|
2
|
+
import { Button as t } from "../../../ui/button.js";
|
|
3
|
+
import { cn as n } from "../../utils/cn.js";
|
|
4
|
+
import { severityLabel as r } from "../severityCopy.js";
|
|
5
|
+
import { useId as i, useState as a } from "react";
|
|
6
|
+
import { Sparkles as o } from "lucide-react";
|
|
7
|
+
import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
8
|
+
// src/shared/proactive/ui/SuggestionCard.tsx
|
|
9
|
+
var u = {
|
|
10
|
+
urgent: "destructive",
|
|
11
|
+
high: "warning",
|
|
12
|
+
medium: "info",
|
|
13
|
+
low: "secondary"
|
|
14
|
+
};
|
|
15
|
+
function d({ severity: t, tr: n }) {
|
|
16
|
+
return /* @__PURE__ */ c(e, {
|
|
17
|
+
variant: u[t],
|
|
18
|
+
"data-severity": t,
|
|
19
|
+
children: r(n, t)
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function f({ tr: t }) {
|
|
23
|
+
return /* @__PURE__ */ l(e, {
|
|
24
|
+
variant: "outline",
|
|
25
|
+
children: [/* @__PURE__ */ c(o, { "aria-hidden": "true" }), t("proactive.card.aiBadge", "AI suggestion")]
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function p({ suggestion: e, controls: r, onSettled: o, headingLevel: u = "h3", footer: p, className: m }) {
|
|
29
|
+
let h = r.tr, g = i(), [_, v] = a(null), [y, b] = a(null), x = r.offeredActions(e), S = u, C = async (t) => {
|
|
30
|
+
v({
|
|
31
|
+
kind: "action",
|
|
32
|
+
id: t.id
|
|
33
|
+
}), b(null);
|
|
34
|
+
let n = await r.runAction(e, t);
|
|
35
|
+
v(null), n.status === "done" ? o?.() : b(n.status === "failed" ? h("proactive.card.actionFailed", "That didn't work. Try again, or open it yourself.") : h("proactive.card.actionUnavailable", "This action isn't available any more."));
|
|
36
|
+
}, w = async () => {
|
|
37
|
+
v({ kind: "dismiss" }), b(null);
|
|
38
|
+
let t = await r.dismiss(e);
|
|
39
|
+
v(null), t ? o?.() : b(h("proactive.card.dismissFailed", "Couldn't dismiss this suggestion. Try again."));
|
|
40
|
+
}, T = async (t) => {
|
|
41
|
+
v({ kind: "snooze" }), b(null);
|
|
42
|
+
let n = await r.snooze(e, t);
|
|
43
|
+
v(null), n ? o?.() : b(h("proactive.card.snoozeFailed", "Couldn't snooze this suggestion. Try again."));
|
|
44
|
+
};
|
|
45
|
+
return /* @__PURE__ */ l("article", {
|
|
46
|
+
"aria-labelledby": g,
|
|
47
|
+
"data-agent": "deny",
|
|
48
|
+
"data-proactive-ui": "",
|
|
49
|
+
"data-testid": "proactive-suggestion-card",
|
|
50
|
+
"data-suggestion-id": e.suggestionId,
|
|
51
|
+
className: n("flex flex-col gap-2 text-start", m),
|
|
52
|
+
children: [
|
|
53
|
+
/* @__PURE__ */ l("div", {
|
|
54
|
+
className: "flex flex-wrap items-center gap-1.5",
|
|
55
|
+
children: [/* @__PURE__ */ c(d, {
|
|
56
|
+
severity: e.severity,
|
|
57
|
+
tr: h
|
|
58
|
+
}), /* @__PURE__ */ c(f, { tr: h })]
|
|
59
|
+
}),
|
|
60
|
+
/* @__PURE__ */ c(S, {
|
|
61
|
+
id: g,
|
|
62
|
+
className: "text-sm font-semibold text-text-primary break-words",
|
|
63
|
+
children: e.title
|
|
64
|
+
}),
|
|
65
|
+
/* @__PURE__ */ c("p", {
|
|
66
|
+
className: "text-xs leading-relaxed text-text-secondary break-words",
|
|
67
|
+
children: e.why
|
|
68
|
+
}),
|
|
69
|
+
x.length > 0 ? /* @__PURE__ */ c("div", {
|
|
70
|
+
className: "flex flex-wrap gap-2 pt-1",
|
|
71
|
+
children: x.map((e) => /* @__PURE__ */ c(t, {
|
|
72
|
+
type: "button",
|
|
73
|
+
size: "sm",
|
|
74
|
+
variant: "secondary",
|
|
75
|
+
disabled: _ !== null,
|
|
76
|
+
"aria-busy": _?.kind === "action" && _.id === e.id || void 0,
|
|
77
|
+
onClick: () => void C(e),
|
|
78
|
+
children: e.label
|
|
79
|
+
}, e.id))
|
|
80
|
+
}) : null,
|
|
81
|
+
/* @__PURE__ */ l("div", {
|
|
82
|
+
className: "flex flex-wrap items-center gap-1 border-t border-border-subtle pt-2",
|
|
83
|
+
children: [/* @__PURE__ */ c(t, {
|
|
84
|
+
type: "button",
|
|
85
|
+
size: "sm",
|
|
86
|
+
variant: "ghost",
|
|
87
|
+
className: "px-2",
|
|
88
|
+
disabled: _ !== null,
|
|
89
|
+
"aria-busy": _?.kind === "dismiss" || void 0,
|
|
90
|
+
onClick: () => void w(),
|
|
91
|
+
children: h("proactive.card.dismiss", "Dismiss")
|
|
92
|
+
}), r.canSnooze ? /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ c(t, {
|
|
93
|
+
type: "button",
|
|
94
|
+
size: "sm",
|
|
95
|
+
variant: "ghost",
|
|
96
|
+
className: "px-2",
|
|
97
|
+
disabled: _ !== null,
|
|
98
|
+
onClick: () => void T("1d"),
|
|
99
|
+
children: h("proactive.card.snoozeDay", "Snooze 1 day")
|
|
100
|
+
}), /* @__PURE__ */ c(t, {
|
|
101
|
+
type: "button",
|
|
102
|
+
size: "sm",
|
|
103
|
+
variant: "ghost",
|
|
104
|
+
className: "px-2",
|
|
105
|
+
disabled: _ !== null,
|
|
106
|
+
onClick: () => void T("1w"),
|
|
107
|
+
children: h("proactive.card.snoozeWeek", "Snooze 1 week")
|
|
108
|
+
})] }) : null]
|
|
109
|
+
}),
|
|
110
|
+
y ? /* @__PURE__ */ c("p", {
|
|
111
|
+
role: "alert",
|
|
112
|
+
className: "text-xs text-status-error-text",
|
|
113
|
+
children: y
|
|
114
|
+
}) : null,
|
|
115
|
+
p
|
|
116
|
+
]
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
export { f as AiBadge, d as SeverityBadge, p as SuggestionCard };
|