@burdenoff/fe-libs 2026.1115.5 → 2026.1115.7

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.
@@ -15,5 +15,10 @@ import { FC } from 'react';
15
15
  export interface AskAboutLayerProps {
16
16
  /** Open the full assistant (the overlay's `openFull`). */
17
17
  onOpenAssistant: () => void;
18
+ /**
19
+ * ★ BOFF-14630: right-click anything and select any text to ask about it,
20
+ * not only what the product marked (`askAnywhere.ts`). Off by default.
21
+ */
22
+ anywhere?: boolean;
18
23
  }
19
24
  export declare const AskAboutLayer: FC<AskAboutLayerProps>;
@@ -1,65 +1,94 @@
1
1
  import { useAssistantTr as e } from "../i18n.js";
2
2
  import { useAskAboutStore as t } from "./askAboutStore.js";
3
- import { ASK_ABOUT_HINT_SHOWN_MS as n, markAskAboutHintSeen as r } from "./hint.js";
4
- import { readAskableSelection as i } from "./askableSelection.js";
5
- import { placeAskAboutMenu as a, placeAskSelectionButton as o, scrollClosesMenu as s, visiblePart as c } from "./placement.js";
6
- import { useEffect as l, useRef as u, useState as d } from "react";
7
- import { Sparkles as f } from "lucide-react";
8
- import { Fragment as p, jsx as m, jsxs as h } from "react/jsx-runtime";
9
- import { createPortal as g } from "react-dom";
3
+ import { attachAskAnywhere as n } from "./askAnywhere.js";
4
+ import { GENERIC_KIND_FALLBACK as r } from "./describeAnything.js";
5
+ import { ASK_ABOUT_HINT_SHOWN_MS as i, markAskAboutHintSeen as a } from "./hint.js";
6
+ import { readAskableSelection as o } from "./askableSelection.js";
7
+ import { placeAskAboutMenu as s, placeAskSelectionButton as c, scrollClosesMenu as l, visiblePart as u } from "./placement.js";
8
+ import { useEffect as d, useRef as f, useState as p } from "react";
9
+ import { Copy as m, ExternalLink as h, Link2 as g, Sparkles as _ } from "lucide-react";
10
+ import { Fragment as v, jsx as y, jsxs as b } from "react/jsx-runtime";
11
+ import { createPortal as x } from "react-dom";
10
12
  // src/shared/assistant/askAbout/AskAboutLayer.tsx
11
- var _ = ({ onOpenAssistant: e }) => {
12
- l(() => t.getState().actions.registerHost(), []);
13
- let n = (n, r) => {
13
+ function S() {
14
+ let t = e(), n = {
15
+ link: t("askAbout.kind.link", "link"),
16
+ button: t("askAbout.kind.button", "button"),
17
+ tab: t("askAbout.kind.tab", "tab"),
18
+ menuItem: t("askAbout.kind.menuItem", "menu item"),
19
+ tableRow: t("askAbout.kind.tableRow", "table row"),
20
+ heading: t("askAbout.kind.heading", "heading"),
21
+ listItem: t("askAbout.kind.listItem", "list item"),
22
+ card: t("askAbout.kind.card", "card"),
23
+ image: t("askAbout.kind.image", "image"),
24
+ formField: t("askAbout.kind.formField", "form field"),
25
+ dialog: t("askAbout.kind.dialog", "dialog"),
26
+ section: t("askAbout.kind.section", "section"),
27
+ page: t("askAbout.kind.page", "page")
28
+ };
29
+ return (e) => n[e] || r[e];
30
+ }
31
+ var C = ({ onOpenAssistant: e, anywhere: r = !1 }) => {
32
+ d(() => t.getState().actions.registerHost(), []);
33
+ let i = S(), a = f(i);
34
+ d(() => {
35
+ a.current = i;
36
+ }, [i]), d(() => {
37
+ if (r && typeof document < "u") return n(document, () => a.current);
38
+ }, [r]);
39
+ let o = (n, r) => {
14
40
  t.getState().actions.pick(n, r), e();
15
- }, r = t((e) => e.openRequested), i = u(e);
16
- return l(() => {
17
- i.current = e;
18
- }, [e]), l(() => {
19
- r && (t.getState().actions.opened(), i.current());
20
- }, [r]), /* @__PURE__ */ h(p, { children: [
21
- /* @__PURE__ */ m(v, { onAsk: n }),
22
- /* @__PURE__ */ m(T, {}),
23
- /* @__PURE__ */ m(E, {}),
24
- /* @__PURE__ */ m(y, { onAsk: n })
41
+ }, s = t((e) => e.openRequested), c = f(e);
42
+ return d(() => {
43
+ c.current = e;
44
+ }, [e]), d(() => {
45
+ s && (t.getState().actions.opened(), c.current());
46
+ }, [s]), /* @__PURE__ */ b(v, { children: [
47
+ /* @__PURE__ */ y(w, { onAsk: o }),
48
+ /* @__PURE__ */ y(N, {}),
49
+ /* @__PURE__ */ y(P, {}),
50
+ /* @__PURE__ */ y(D, {
51
+ onAsk: o,
52
+ anywhere: r ? a : null
53
+ })
25
54
  ] });
26
- }, v = ({ onAsk: n }) => {
27
- let r = e(), i = t((e) => e.menu), o = u(null);
28
- if (l(() => {
55
+ }, w = ({ onAsk: n }) => {
56
+ let r = e(), i = t((e) => e.menu), a = f(null);
57
+ if (d(() => {
29
58
  if (!i) return;
30
59
  let { closeMenu: e } = t.getState().actions;
31
- o.current?.querySelector("[role=\"menuitem\"]")?.focus({ preventScroll: !0 });
60
+ a.current?.querySelector("[role=\"menuitem\"]")?.focus({ preventScroll: !0 });
32
61
  let n = (t) => {
33
- t.target instanceof Node && o.current?.contains(t.target) || e();
62
+ t.target instanceof Node && a.current?.contains(t.target) || e();
34
63
  }, r = (t) => {
35
- s(t.target, i.anchor, o.current) && e();
64
+ l(t.target, i.anchor, a.current) && e();
36
65
  };
37
66
  return document.addEventListener("pointerdown", n, !0), window.addEventListener("scroll", r, !0), window.addEventListener("resize", e), window.addEventListener("popstate", e), window.addEventListener("blur", e), () => {
38
67
  document.removeEventListener("pointerdown", n, !0), window.removeEventListener("scroll", r, !0), window.removeEventListener("resize", e), window.removeEventListener("popstate", e), window.removeEventListener("blur", e);
39
68
  };
40
69
  }, [i]), !i || typeof document > "u") return null;
41
- let { left: c, top: d } = a(i, {
70
+ let { copyText: o, href: c } = i, u = +!!o + (c ? 2 : 0), { left: p, top: v } = s(i, {
42
71
  width: window.innerWidth,
43
72
  height: window.innerHeight
44
- }), p = () => {
73
+ }, u), S = () => {
45
74
  t.getState().actions.closeMenu(), i.returnFocusTo?.focus({ preventScroll: !0 });
46
75
  };
47
- return g(/* @__PURE__ */ m("div", {
48
- ref: o,
76
+ return x(/* @__PURE__ */ b("div", {
77
+ ref: a,
49
78
  role: "menu",
50
79
  "aria-label": r("askAbout.menuLabel", "Ask AI"),
51
80
  "data-agent": "deny",
52
81
  "data-testid": "assistant-ask-about-menu",
53
82
  onKeyDown: (e) => {
54
83
  if (e.key === "Escape") {
55
- e.preventDefault(), e.stopPropagation(), p();
84
+ e.preventDefault(), e.stopPropagation(), S();
56
85
  return;
57
86
  }
58
87
  if (e.key === "Tab") {
59
- e.preventDefault(), p();
88
+ e.preventDefault(), S();
60
89
  return;
61
90
  }
62
- let t = Array.from(o.current?.querySelectorAll("[role=\"menuitem\"]") ?? []);
91
+ let t = Array.from(a.current?.querySelectorAll("[role=\"menuitem\"]") ?? []);
63
92
  if (t.length === 0) return;
64
93
  let n = t.findIndex((e) => e === document.activeElement), r = e.key === "ArrowDown" ? (n + 1) % t.length : e.key === "ArrowUp" ? (n - 1 + t.length) % t.length : e.key === "Home" ? 0 : e.key === "End" ? t.length - 1 : -1;
65
94
  r !== -1 && (e.preventDefault(), t[r]?.focus());
@@ -67,36 +96,89 @@ var _ = ({ onOpenAssistant: e }) => {
67
96
  onContextMenu: (e) => e.preventDefault(),
68
97
  className: "fixed z-[1100] max-w-[calc(100vw-16px)] overflow-hidden rounded-card border border-border-subtle bg-bg-elevated p-1 shadow-[var(--shadow-elevation-4)]",
69
98
  style: {
70
- left: c,
71
- top: d,
99
+ left: p,
100
+ top: v,
72
101
  width: 256
73
102
  },
74
- children: /* @__PURE__ */ h("button", {
75
- type: "button",
76
- role: "menuitem",
77
- onClick: () => n(i.focus, i.anchor ?? null),
78
- className: "flex w-full items-start gap-2 rounded-button px-3 py-2 text-start text-sm text-text-primary transition-colors hover:bg-bg-sunken focus:bg-bg-sunken focus:outline-none",
79
- "data-testid": "assistant-ask-about-item",
80
- children: [/* @__PURE__ */ m(f, {
81
- className: "mt-0.5 size-4 shrink-0 text-action-primary-bg",
82
- "aria-hidden": "true"
83
- }), /* @__PURE__ */ h("span", {
84
- className: "min-w-0",
85
- children: [/* @__PURE__ */ m("span", {
86
- className: "block font-medium",
87
- children: r("askAbout.menuItem", "Ask AI about this")
88
- }), /* @__PURE__ */ m("span", {
89
- className: "block truncate text-xs text-text-muted",
90
- children: i.focus.label
103
+ children: [
104
+ /* @__PURE__ */ b("button", {
105
+ type: "button",
106
+ role: "menuitem",
107
+ onClick: () => n(i.focus, i.anchor ?? null),
108
+ className: "flex w-full items-start gap-2 rounded-button px-3 py-2 text-start text-sm text-text-primary transition-colors hover:bg-bg-sunken focus:bg-bg-sunken focus:outline-none",
109
+ "data-testid": "assistant-ask-about-item",
110
+ children: [/* @__PURE__ */ y(_, {
111
+ className: "mt-0.5 size-4 shrink-0 text-action-primary-bg",
112
+ "aria-hidden": "true"
113
+ }), /* @__PURE__ */ b("span", {
114
+ className: "min-w-0",
115
+ children: [/* @__PURE__ */ y("span", {
116
+ className: "block font-medium",
117
+ children: r("askAbout.menuItem", "Ask AI about this")
118
+ }), /* @__PURE__ */ y("span", {
119
+ className: "block truncate text-xs text-text-muted",
120
+ children: i.focus.label
121
+ })]
91
122
  })]
92
- })]
93
- })
123
+ }),
124
+ o && /* @__PURE__ */ y(E, {
125
+ icon: /* @__PURE__ */ y(m, {
126
+ className: "size-4 shrink-0 text-text-muted",
127
+ "aria-hidden": "true"
128
+ }),
129
+ label: r("askAbout.copy", "Copy"),
130
+ testId: "assistant-ask-about-copy",
131
+ onSelect: () => {
132
+ T(o), S();
133
+ }
134
+ }),
135
+ c && /* @__PURE__ */ y(E, {
136
+ icon: /* @__PURE__ */ y(h, {
137
+ className: "size-4 shrink-0 text-text-muted",
138
+ "aria-hidden": "true"
139
+ }),
140
+ label: r("askAbout.openLinkNewTab", "Open link in new tab"),
141
+ testId: "assistant-ask-about-open-link",
142
+ onSelect: () => {
143
+ window.open(c, "_blank", "noopener,noreferrer"), t.getState().actions.closeMenu();
144
+ }
145
+ }),
146
+ c && /* @__PURE__ */ y(E, {
147
+ icon: /* @__PURE__ */ y(g, {
148
+ className: "size-4 shrink-0 text-text-muted",
149
+ "aria-hidden": "true"
150
+ }),
151
+ label: r("askAbout.copyLink", "Copy link address"),
152
+ testId: "assistant-ask-about-copy-link",
153
+ onSelect: () => {
154
+ T(c), S();
155
+ }
156
+ })
157
+ ]
94
158
  }), document.body);
95
- }, y = ({ onAsk: t }) => {
96
- let n = e(), [r, a] = d(null);
97
- l(() => {
159
+ };
160
+ async function T(e) {
161
+ try {
162
+ await navigator.clipboard?.writeText(e);
163
+ } catch {}
164
+ }
165
+ var E = ({ icon: e, label: t, testId: n, onSelect: r }) => /* @__PURE__ */ b("button", {
166
+ type: "button",
167
+ role: "menuitem",
168
+ onClick: r,
169
+ className: "flex w-full items-center gap-2 rounded-button px-3 py-2 text-start text-sm text-text-primary transition-colors hover:bg-bg-sunken focus:bg-bg-sunken focus:outline-none",
170
+ "data-testid": n,
171
+ children: [e, /* @__PURE__ */ y("span", {
172
+ className: "min-w-0 truncate",
173
+ children: t
174
+ })]
175
+ }), D = ({ onAsk: t, anywhere: n }) => {
176
+ let r = e(), [i, a] = p(null), s = f(n);
177
+ d(() => {
178
+ s.current = n;
179
+ }, [n]), d(() => {
98
180
  let e = 0, t = () => {
99
- e = 0, a(i(document));
181
+ e = 0, a(o(document, { anywhere: s.current?.current ?? null }));
100
182
  }, n = () => {
101
183
  e === 0 && (e = requestAnimationFrame(t));
102
184
  };
@@ -104,44 +186,44 @@ var _ = ({ onOpenAssistant: e }) => {
104
186
  e !== 0 && cancelAnimationFrame(e), document.removeEventListener("selectionchange", n);
105
187
  };
106
188
  }, []);
107
- let s = r !== null;
108
- if (l(() => {
109
- if (!s) return;
189
+ let l = i !== null;
190
+ if (d(() => {
191
+ if (!l) return;
110
192
  let e = () => a(null);
111
193
  return window.addEventListener("scroll", e, !0), window.addEventListener("resize", e), () => {
112
194
  window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", e);
113
195
  };
114
- }, [s]), !r || typeof document > "u") return null;
115
- let { left: c, top: u } = o(r.rect, {
196
+ }, [l]), !i || typeof document > "u") return null;
197
+ let { left: u, top: m } = c(i.rect, {
116
198
  width: window.innerWidth,
117
199
  height: window.innerHeight
118
200
  });
119
- return g(/* @__PURE__ */ h("button", {
201
+ return x(/* @__PURE__ */ b("button", {
120
202
  type: "button",
121
203
  "data-agent": "deny",
122
204
  "data-testid": "assistant-ask-about-selection",
123
205
  onMouseDown: (e) => e.preventDefault(),
124
206
  onClick: () => {
125
- a(null), t(r.focus, r.anchor);
207
+ a(null), t(i.focus, i.anchor);
126
208
  },
127
209
  className: "fixed z-[1100] inline-flex items-center gap-1.5 rounded-full border border-border-subtle bg-bg-elevated px-3 py-1.5 text-xs font-medium text-text-primary shadow-[var(--shadow-elevation-4)] transition-colors hover:bg-bg-sunken focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-focus-ring)]",
128
210
  style: {
129
- left: c,
130
- top: u
211
+ left: u,
212
+ top: m
131
213
  },
132
- children: [/* @__PURE__ */ m(f, {
214
+ children: [/* @__PURE__ */ y(_, {
133
215
  className: "size-3.5 text-action-primary-bg",
134
216
  "aria-hidden": "true"
135
- }), n("askAbout.selectionButton", "Ask AI")]
217
+ }), r("askAbout.selectionButton", "Ask AI")]
136
218
  }), document.body);
137
- }, b = /* @__PURE__ */ new Set([
219
+ }, O = /* @__PURE__ */ new Set([
138
220
  "hidden",
139
221
  "clip",
140
222
  "auto",
141
223
  "scroll",
142
224
  "overlay"
143
225
  ]);
144
- function x(e) {
226
+ function k(e) {
145
227
  let t = [], n = e.ownerDocument.defaultView;
146
228
  for (let r = e.parentElement; r && n; r = r.parentElement) {
147
229
  let e = n.getComputedStyle(r);
@@ -149,42 +231,42 @@ function x(e) {
149
231
  e.overflow,
150
232
  e.overflowX,
151
233
  e.overflowY
152
- ].some((e) => b.has(e)) && t.push(r);
234
+ ].some((e) => O.has(e)) && t.push(r);
153
235
  }
154
236
  return t;
155
237
  }
156
- var S = (e) => ({
238
+ var A = (e) => ({
157
239
  left: e.left,
158
240
  top: e.top,
159
241
  width: e.width,
160
242
  height: e.height
161
243
  });
162
- function C(e, t = {}) {
163
- let n = t.clip === !0, [r, i] = d(null);
164
- return l(() => {
244
+ function j(e, t = {}) {
245
+ let n = t.clip === !0, [r, i] = p(null);
246
+ return d(() => {
165
247
  if (!e) {
166
248
  i(null);
167
249
  return;
168
250
  }
169
- let t = 0, r = "", a = n ? x(e) : [], o = () => {
251
+ let t = 0, r = "", a = n ? k(e) : [], o = () => {
170
252
  if (!e.isConnected) {
171
253
  i(null);
172
254
  return;
173
255
  }
174
- let s = S(e.getBoundingClientRect()), l = n ? c(s, [...a.map((e) => S(e.getBoundingClientRect())), {
256
+ let s = A(e.getBoundingClientRect()), c = n ? u(s, [...a.map((e) => A(e.getBoundingClientRect())), {
175
257
  left: 0,
176
258
  top: 0,
177
259
  width: window.innerWidth,
178
260
  height: window.innerHeight
179
- }]) : s, u = l ? `${l.left},${l.top},${l.width},${l.height}` : "none";
180
- u !== r && (r = u, i(l)), t = requestAnimationFrame(o);
261
+ }]) : s, l = c ? `${c.left},${c.top},${c.width},${c.height}` : "none";
262
+ l !== r && (r = l, i(c)), t = requestAnimationFrame(o);
181
263
  };
182
264
  return o(), () => cancelAnimationFrame(t);
183
265
  }, [e, n]), r;
184
266
  }
185
- var w = 4, T = () => {
186
- let e = t((e) => e.pending ? e.pendingAnchor : null), n = C(e, { clip: !0 });
187
- return l(() => {
267
+ var M = 4, N = () => {
268
+ let e = t((e) => e.pending ? e.pendingAnchor : null), n = j(e, { clip: !0 });
269
+ return d(() => {
188
270
  if (!e) return;
189
271
  let t = setTimeout(() => {
190
272
  if (!e.isConnected) return;
@@ -195,52 +277,52 @@ var w = 4, T = () => {
195
277
  });
196
278
  }, 250);
197
279
  return () => clearTimeout(t);
198
- }, [e]), !n || typeof document > "u" ? null : g(/* @__PURE__ */ m("div", {
280
+ }, [e]), !n || typeof document > "u" ? null : x(/* @__PURE__ */ y("div", {
199
281
  "aria-hidden": "true",
200
282
  "data-agent": "deny",
201
283
  "data-testid": "assistant-ask-about-highlight",
202
284
  className: "pointer-events-none fixed z-[45] rounded-card border-2 border-action-primary-bg shadow-[0_0_0_4px_var(--color-focus-ring)] transition-[left,top,width,height] duration-75",
203
285
  style: {
204
- left: n.left - w,
205
- top: n.top - w,
286
+ left: n.left - M,
287
+ top: n.top - M,
206
288
  width: n.width + 8,
207
289
  height: n.height + 8
208
290
  }
209
291
  }), document.body);
210
- }, E = () => {
211
- let i = e(), a = t((e) => e.hint)?.anchor ?? null, s = C(a);
212
- if (l(() => {
213
- if (!a) return;
214
- r();
215
- let { hideHint: e } = t.getState().actions, i = setTimeout(e, n);
292
+ }, P = () => {
293
+ let n = e(), r = t((e) => e.hint)?.anchor ?? null, o = j(r);
294
+ if (d(() => {
295
+ if (!r) return;
296
+ a();
297
+ let { hideHint: e } = t.getState().actions, n = setTimeout(e, i);
216
298
  return window.addEventListener("pointerdown", e, !0), window.addEventListener("keydown", e, !0), window.addEventListener("scroll", e, !0), window.addEventListener("wheel", e, {
217
299
  capture: !0,
218
300
  passive: !0
219
- }), a.addEventListener("pointerleave", e), () => {
220
- clearTimeout(i), window.removeEventListener("pointerdown", e, !0), window.removeEventListener("keydown", e, !0), window.removeEventListener("scroll", e, !0), window.removeEventListener("wheel", e, !0), a.removeEventListener("pointerleave", e);
301
+ }), r.addEventListener("pointerleave", e), () => {
302
+ clearTimeout(n), window.removeEventListener("pointerdown", e, !0), window.removeEventListener("keydown", e, !0), window.removeEventListener("scroll", e, !0), window.removeEventListener("wheel", e, !0), r.removeEventListener("pointerleave", e);
221
303
  };
222
- }, [a]), !s || typeof document > "u") return null;
223
- let { left: c, top: u } = o({
224
- left: s.left,
225
- top: s.top,
226
- bottom: s.top + s.height
304
+ }, [r]), !o || typeof document > "u") return null;
305
+ let { left: s, top: l } = c({
306
+ left: o.left,
307
+ top: o.top,
308
+ bottom: o.top + o.height
227
309
  }, {
228
310
  width: window.innerWidth,
229
311
  height: window.innerHeight
230
312
  });
231
- return g(/* @__PURE__ */ h("div", {
313
+ return x(/* @__PURE__ */ b("div", {
232
314
  role: "status",
233
315
  "data-agent": "deny",
234
316
  "data-testid": "assistant-ask-about-hint",
235
317
  className: "pointer-events-none fixed z-[1100] inline-flex max-w-[calc(100vw-16px)] items-center gap-1.5 rounded-full border border-border-subtle bg-bg-elevated px-3 py-1.5 text-xs text-text-primary shadow-[var(--shadow-elevation-4)]",
236
318
  style: {
237
- left: c,
238
- top: u
319
+ left: s,
320
+ top: l
239
321
  },
240
- children: [/* @__PURE__ */ m(f, {
322
+ children: [/* @__PURE__ */ y(_, {
241
323
  className: "size-3.5 shrink-0 text-action-primary-bg",
242
324
  "aria-hidden": "true"
243
- }), i("askAbout.hint", "Right-click to ask AI about this")]
325
+ }), n("askAbout.hint", "Right-click to ask AI about this")]
244
326
  }), document.body);
245
327
  };
246
- export { _ as AskAboutLayer };
328
+ export { C as AskAboutLayer };
@@ -22,6 +22,13 @@ export interface AskAboutMenuRequest {
22
22
  * any scroll outside the menu closes it.
23
23
  */
24
24
  readonly anchor?: HTMLElement | null;
25
+ /**
26
+ * ★ BOFF-14630: the menu stands in for the browser's own, so it also offers
27
+ * Copy for the text selected where the person pressed…
28
+ */
29
+ readonly copyText?: string;
30
+ /** …and Open in new tab / Copy link for the link they pressed on (absolute). */
31
+ readonly href?: string;
25
32
  }
26
33
  /** ★ BOFF-13381: the one-time "Right-click to ask AI about this" tip, next to an askable thing. */
27
34
  export interface AskAboutHint {
@@ -0,0 +1,16 @@
1
+ import { GenericKindLabel } from './describeAnything';
2
+ /** What the menu offers besides asking: Copy for a selection, the link's address for a link. */
3
+ export interface AskAboutMenuExtras {
4
+ readonly copyText?: string;
5
+ readonly href?: string;
6
+ }
7
+ /** The selection and link at `target`, for the menu's Copy / Open / Copy link items. */
8
+ export declare function menuExtrasAt(target: Element): AskAboutMenuExtras;
9
+ /** May a right-click (or the menu key) at `target` open the menu anywhere? */
10
+ export declare function mayAskAnywhere(target: EventTarget | null): target is Element;
11
+ /**
12
+ * Listen for a right-click or the menu key anywhere in `doc`. Returns the
13
+ * function that stops listening. `kindLabel` names a kind in the person's
14
+ * language; it is read at the moment of the press.
15
+ */
16
+ export declare function attachAskAnywhere(doc: Document, kindLabel: () => GenericKindLabel): () => void;
@@ -0,0 +1,76 @@
1
+ import { isDenied as e } from "../../agent-tools/ui/dom.js";
2
+ import { useAskAboutStore as t } from "./askAboutStore.js";
3
+ import { describeAnything as n } from "./describeAnything.js";
4
+ import { normaliseFocus as r } from "./focus.js";
5
+ import { markAskAboutHintSeen as i } from "./hint.js";
6
+ // src/shared/assistant/askAbout/askAnywhere.ts
7
+ function a(t) {
8
+ let n = t.ownerDocument.getSelection();
9
+ if (!n || n.isCollapsed || n.rangeCount === 0) return;
10
+ let r = n.getRangeAt(0);
11
+ if (!(t.contains(r.commonAncestorContainer) || r.intersectsNode(t))) return;
12
+ let i = n.toString();
13
+ if (!i.trim()) return;
14
+ let a = n.anchorNode, o = n.focusNode;
15
+ for (let t of [a, o]) {
16
+ let n = t instanceof Element ? t : t?.parentElement;
17
+ if (!n || e(n) || n.closest("[data-agent-sensitive]")) return;
18
+ }
19
+ return i;
20
+ }
21
+ function o(t) {
22
+ let n = a(t), r = t.closest("a[href]"), i;
23
+ if (r instanceof HTMLAnchorElement && !e(r)) try {
24
+ let e = new URL(r.getAttribute("href") ?? "", r.ownerDocument.location?.href);
25
+ (e.protocol === "http:" || e.protocol === "https:") && (i = e.href);
26
+ } catch {
27
+ i = void 0;
28
+ }
29
+ return {
30
+ ...n ? { copyText: n } : {},
31
+ ...i ? { href: i } : {}
32
+ };
33
+ }
34
+ function s(n) {
35
+ return !(n instanceof Element) || t.getState().hosts === 0 || n.closest("input, textarea, select, [contenteditable]:not([contenteditable=\"false\"]), [role=\"textbox\"], .monaco-editor, .cm-editor") ? !1 : !e(n) && n.closest("[data-agent-sensitive]") === null;
36
+ }
37
+ function c(e) {
38
+ let t = e.pointerType;
39
+ return typeof t == "string" && t !== "" && t !== "mouse";
40
+ }
41
+ function l(e, a, s, c, l) {
42
+ let u = n(e, l);
43
+ if (!u) return !1;
44
+ let d = o(e), f = r({
45
+ ...u.input,
46
+ ...d.copyText ? { selectedText: d.copyText } : {}
47
+ }, {
48
+ route: window.location.pathname,
49
+ pickedAt: (/* @__PURE__ */ new Date()).toISOString()
50
+ });
51
+ return f ? (i(), t.getState().actions.openMenu({
52
+ focus: f,
53
+ x: a,
54
+ y: s,
55
+ returnFocusTo: c,
56
+ anchor: u.anchor,
57
+ ...d
58
+ }), !0) : !1;
59
+ }
60
+ function u(e, t) {
61
+ let n = (n) => {
62
+ if (n.defaultPrevented || n.shiftKey || c(n) || !s(n.target)) return;
63
+ let r = e.activeElement, i = r instanceof HTMLElement && r !== e.body ? r : null;
64
+ l(n.target, n.clientX, n.clientY, i, t()) && n.preventDefault();
65
+ }, r = (n) => {
66
+ if (!(n.key === "ContextMenu" || n.shiftKey && n.key === "F10") || n.defaultPrevented) return;
67
+ let r = n.target instanceof Element ? n.target : e.activeElement;
68
+ if (!s(r)) return;
69
+ let i = r.getBoundingClientRect(), a = r instanceof HTMLElement ? r : null;
70
+ l(r, i.left + Math.min(16, i.width / 2), i.bottom, a, t()) && n.preventDefault();
71
+ };
72
+ return e.addEventListener("contextmenu", n), e.addEventListener("keydown", r), () => {
73
+ e.removeEventListener("contextmenu", n), e.removeEventListener("keydown", r);
74
+ };
75
+ }
76
+ export { u as attachAskAnywhere, s as mayAskAnywhere, o as menuExtrasAt };
@@ -1,3 +1,4 @@
1
+ import { GenericKindLabel } from './describeAnything';
1
2
  import { AssistantFocus } from './focus';
2
3
  import { AskableDescribe } from './useAskable';
3
4
  /**
@@ -5,11 +6,15 @@ import { AskableDescribe } from './useAskable';
5
6
  * error message, a log). Selecting text inside one shows a small "Ask AI"
6
7
  * button next to the selection (`AskAboutLayer`).
7
8
  *
8
- * ★★ Opt-in by region, never page-wide: selecting text is something people do
9
- * all the time to copy it, and a button appearing on every selection would be in
10
- * the way. Only text inside ONE region is offered (a selection that starts in
11
- * one and ends outside is not), never text in a region hidden from agents or a
12
- * sensitive field, and never more than the focus limit.
9
+ * ★★ Opt-in by region by default: selecting text is something people do all
10
+ * the time to copy it. Only text inside ONE region is offered (a selection that
11
+ * starts in one and ends outside is not), never text in a region hidden from
12
+ * agents or a sensitive field, and never more than the focus limit.
13
+ *
14
+ * ★ BOFF-14630: a product that turns on "ask anywhere" offers EVERY selection
15
+ * outside the editors (`readAskableSelection`'s `anywhere`). A selection in a
16
+ * region keeps the region's own description; anywhere else, the thing the
17
+ * selection sits in is described from the page (`describeAnything`).
13
18
  */
14
19
  export declare const ASK_SELECTION_ATTRIBUTE = "data-ask-selection";
15
20
  /** Register a region. Returns the function that unregisters it. */
@@ -32,8 +37,15 @@ export interface AskableSelectionOffer {
32
37
  /** The askable region the selection is in (outlined while it is the chip). */
33
38
  readonly anchor: HTMLElement | null;
34
39
  }
40
+ export interface ReadAskableSelectionOptions {
41
+ /**
42
+ * ★ BOFF-14630: offer a selection anywhere on the page, not only in a
43
+ * region; names the kinds of thing in the person's language.
44
+ */
45
+ readonly anywhere?: GenericKindLabel | null;
46
+ }
35
47
  /**
36
- * The selection in `doc`, when it lies inside one askable region and may be
37
- * asked about; otherwise null.
48
+ * The selection in `doc`, when it lies inside one askable region (or, with
49
+ * `anywhere`, anywhere outside the editors) and may be asked about; otherwise null.
38
50
  */
39
- export declare function readAskableSelection(doc?: Document): AskableSelectionOffer | null;
51
+ export declare function readAskableSelection(doc?: Document, options?: ReadAskableSelectionOptions): AskableSelectionOffer | null;