@marimo-team/islands 0.23.17-dev56 → 0.23.17-dev58
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/{common-04M48ICO.js → common-DG7DA_Ws.js} +1 -1
- package/dist/main.js +2 -2
- package/dist/{reveal-component-CshIEPkn.js → reveal-component-BFcV7ayV.js} +1 -1
- package/package.json +1 -1
- package/src/components/chat/chat-panel.tsx +2 -2
- package/src/core/codemirror/code-lens/__tests__/extension.test.ts +81 -1
- package/src/core/codemirror/code-lens/extension.ts +141 -44
|
@@ -36331,7 +36331,7 @@ ${d}`,
|
|
|
36331
36331
|
return Logger.warn("Failed to get version from mount config"), null;
|
|
36332
36332
|
}
|
|
36333
36333
|
}
|
|
36334
|
-
marimoVersionAtom = atom(getVersionFromMountConfig() || "0.23.17-
|
|
36334
|
+
marimoVersionAtom = atom(getVersionFromMountConfig() || "0.23.17-dev58");
|
|
36335
36335
|
showCodeInRunModeAtom = atom(true);
|
|
36336
36336
|
atom(null);
|
|
36337
36337
|
var import_compiler_runtime = require_compiler_runtime();
|
package/dist/main.js
CHANGED
|
@@ -26,7 +26,7 @@ import { $ as notebookOutline, $t as isUninstantiated, A as ChevronDownIcon, An
|
|
|
26
26
|
import { __tla as __tla_1 } from "./chunk-5FQGJX7Z-BRZ_XYUw.js";
|
|
27
27
|
import { o as useSize, s as Root$1, u as createLucideIcon } from "./dist-j30bBjjN.js";
|
|
28
28
|
import { A as SquareFunction, C as DEFAULT_COLOR_SCHEME, D as SCALE_TYPE_DESCRIPTIONS, E as EMPTY_VALUE$1, O as TIME_UNIT_DESCRIPTIONS, S as DEFAULT_AGGREGATION, T as DEFAULT_TIME_UNIT, _ as AGGREGATION_TYPE_DESCRIPTIONS, a as AGGREGATION_FNS, b as COLOR_SCHEMES, c as COLOR_BY_FIELDS, d as NONE_VALUE, f as SELECTABLE_DATA_TYPES, g as TIME_UNITS, h as STRING_AGGREGATION_FNS, i as convertDataTypeToSelectable, j as ChartColumn, k as escapeFieldName, l as COMBINED_TIME_UNITS, m as SORT_TYPES, n as createSpecWithoutData, o as BIN_AGGREGATION, p as SINGLE_TIME_UNITS, r as isFieldSet, s as CHART_TYPES, t as augmentSpecWithData, u as ChartType, v as AGGREGATION_TYPE_ICON, w as DEFAULT_MAX_BINS_FACET, x as COUNT_FIELD, y as CHART_TYPE_ICON } from "./spec-BL1GSUUF.js";
|
|
29
|
-
import { $ as CommandSeparator, $t as Kbd, A as ErrorState, At as getPageIndexForRow, B as ContextMenuTrigger, Bt as dateToLocalISODate, C as downloadHTMLAsImage, Ct as inferFieldTypes, D as ColumnName, Dt as DelayMount, E as downloadSizeLimitAtom, Et as ColumnChartSpecModel, F as getUserColumnVisibilityCounts, Ft as TOO_MANY_ROWS, G as DateRangePicker, Gt as TabsList, H as useSelectList, Ht as dateToLocalISOTime, I as ContextMenu, It as toFieldTypes, J as Command, Jt as ChartInfoState, K as Combobox, Kt as TabsTrigger, L as ContextMenuContent, Lt as getMimeValues, M as prettifyRowColumnCount, Mt as loadTableData, N as prettifyRowCount, Nt as INDEX_COLUMN_NAME, O as ColumnPreviewContainer, Ot as useIntersectionObserver, P as getColumnCountForDisplay, Pt as SELECT_COLUMN_ID, Q as CommandList, Qt as RenderTextWithLinks, R as ContextMenuItem, Rt as isNullishFilter, S as downloadExportedFile, St as generateColumns, T as Filenames, Tt as ColumnChartContext, U as CompactChipRow, Ut as Tabs, V as useInternalStateWithSync, Vt as dateToLocalISODateTime, W as DatePicker, Wt as TabsContent, X as CommandInput, Xt as LazyVegaEmbed, Y as CommandEmpty, Yt as ChartLoadingState, Z as CommandItem, Zt as useOverflowDetection, _ as DataTable, _n as ChevronLeft, _t as TableCell, an as TextWrap, at as contextAwarePanelType, b as downloadBlob, bt as TableRow, c as SLIDE_TYPE_OPTIONS_BY_VALUE, cn as EyeOff, ct as slotsController, d as Switch, dn as Download, en as HtmlOutput, et as smartMatch, f as RadioGroup, fn as Code, g as OutputRenderer, gn as ChevronsDownUp, gt as TableBody, h as OutputArea, hn as ChevronsLeft, ht as Table, i as showCodeInRunModeAtom, in as $fae977aafc393c5c$export$6b862160d295c8e, it as contextAwarePanelOwner, j as LoadingState, jt as loadTableAndRawData, k as EmptyState, kt as usePrevious$1, lt as Toggle, m as JsonOutput, mn as ChevronsRight, mt as Provider$1, n as useNotebookCodeAvailable, nn as safeLocale, nt as PANEL_TYPES, on as GripHorizontal, ot as isCellAwareAtom, p as RadioGroupItem, pn as ChevronsUpDown, pt as Fill, q as ComboboxItem, qt as ChartErrorState, r as marimoVersionAtom, rn as $fae977aafc393c5c$export$588937bcd60ade55, rt as contextAwarePanelOpen, sn as Funnel, st as SlotNames, t as cellDomProps, tn as EmotionCacheProvider, tt as ContextAwarePanelItem, u as Slide, un as Ellipsis, v as InstallPackageButton, vn as ArrowDownWideNarrow, vt as TableHead, w as Progress, wt as renderCellValue, x as downloadByURL, xt as NAMELESS_COLUMN_PREFIX, y as ADD_PRINTING_CLASS, yt as TableHeader, z as ContextMenuSeparator, zt as Maps, __tla as __tla_2 } from "./common-
|
|
29
|
+
import { $ as CommandSeparator, $t as Kbd, A as ErrorState, At as getPageIndexForRow, B as ContextMenuTrigger, Bt as dateToLocalISODate, C as downloadHTMLAsImage, Ct as inferFieldTypes, D as ColumnName, Dt as DelayMount, E as downloadSizeLimitAtom, Et as ColumnChartSpecModel, F as getUserColumnVisibilityCounts, Ft as TOO_MANY_ROWS, G as DateRangePicker, Gt as TabsList, H as useSelectList, Ht as dateToLocalISOTime, I as ContextMenu, It as toFieldTypes, J as Command, Jt as ChartInfoState, K as Combobox, Kt as TabsTrigger, L as ContextMenuContent, Lt as getMimeValues, M as prettifyRowColumnCount, Mt as loadTableData, N as prettifyRowCount, Nt as INDEX_COLUMN_NAME, O as ColumnPreviewContainer, Ot as useIntersectionObserver, P as getColumnCountForDisplay, Pt as SELECT_COLUMN_ID, Q as CommandList, Qt as RenderTextWithLinks, R as ContextMenuItem, Rt as isNullishFilter, S as downloadExportedFile, St as generateColumns, T as Filenames, Tt as ColumnChartContext, U as CompactChipRow, Ut as Tabs, V as useInternalStateWithSync, Vt as dateToLocalISODateTime, W as DatePicker, Wt as TabsContent, X as CommandInput, Xt as LazyVegaEmbed, Y as CommandEmpty, Yt as ChartLoadingState, Z as CommandItem, Zt as useOverflowDetection, _ as DataTable, _n as ChevronLeft, _t as TableCell, an as TextWrap, at as contextAwarePanelType, b as downloadBlob, bt as TableRow, c as SLIDE_TYPE_OPTIONS_BY_VALUE, cn as EyeOff, ct as slotsController, d as Switch, dn as Download, en as HtmlOutput, et as smartMatch, f as RadioGroup, fn as Code, g as OutputRenderer, gn as ChevronsDownUp, gt as TableBody, h as OutputArea, hn as ChevronsLeft, ht as Table, i as showCodeInRunModeAtom, in as $fae977aafc393c5c$export$6b862160d295c8e, it as contextAwarePanelOwner, j as LoadingState, jt as loadTableAndRawData, k as EmptyState, kt as usePrevious$1, lt as Toggle, m as JsonOutput, mn as ChevronsRight, mt as Provider$1, n as useNotebookCodeAvailable, nn as safeLocale, nt as PANEL_TYPES, on as GripHorizontal, ot as isCellAwareAtom, p as RadioGroupItem, pn as ChevronsUpDown, pt as Fill, q as ComboboxItem, qt as ChartErrorState, r as marimoVersionAtom, rn as $fae977aafc393c5c$export$588937bcd60ade55, rt as contextAwarePanelOpen, sn as Funnel, st as SlotNames, t as cellDomProps, tn as EmotionCacheProvider, tt as ContextAwarePanelItem, u as Slide, un as Ellipsis, v as InstallPackageButton, vn as ArrowDownWideNarrow, vt as TableHead, w as Progress, wt as renderCellValue, x as downloadByURL, xt as NAMELESS_COLUMN_PREFIX, y as ADD_PRINTING_CLASS, yt as TableHeader, z as ContextMenuSeparator, zt as Maps, __tla as __tla_2 } from "./common-DG7DA_Ws.js";
|
|
30
30
|
import { c as Calendar, i as createReducerAndAtoms, n as useOnUnmount, o as ToggleLeft, t as useOnMount } from "./useLifecycle-Bw4wRj_O.js";
|
|
31
31
|
import { t as Check } from "./check-58HHfHKy.js";
|
|
32
32
|
import { A as Icon, C as logNever, D as $18f2051aff69b9bf$export$a54013f0d02a8f82, E as $18f2051aff69b9bf$export$43bb16f9c6d9e3f7, F as createCollection, I as X, M as clamp$2, N as usePrevious$2, P as useDirection, R as ChevronDown, S as assertNever, a as SelectGroup, c as SelectSeparator, d as NativeSelect, i as SelectContent, j as Trigger$1, l as SelectTrigger, n as capitalize, o as SelectItem, r as Select, s as SelectLabel, t as Strings, u as SelectValue, w as $a916eb452884faea$export$b7a616150fdb9f44 } from "./strings-DMLVGXRo.js";
|
|
@@ -38213,7 +38213,7 @@ ${c}
|
|
|
38213
38213
|
function _temp2$2(e) {
|
|
38214
38214
|
e.target === e.currentTarget && e.key === "Enter" && (e.preventDefault(), e.stopPropagation(), e.currentTarget.click());
|
|
38215
38215
|
}
|
|
38216
|
-
var LazySlidesComponent = import_react.lazy(() => import("./reveal-component-
|
|
38216
|
+
var LazySlidesComponent = import_react.lazy(() => import("./reveal-component-BFcV7ayV.js"));
|
|
38217
38217
|
const SlidesLayoutRenderer = ({ layout: e, setLayout: r, cells: c, mode: l }) => {
|
|
38218
38218
|
var _a5;
|
|
38219
38219
|
let u = useAtomValue(kioskModeAtom), d = l === "read" || u, f = useAtomValue(numColumnsAtom) > 1, [p, m] = (0, import_react.useState)(null), { slideCells: h, skippedIds: g, noOutputIds: _, slideTypes: v, startCellIndex: y } = (0, import_react.useMemo)(() => computeSlideCellsInfo(c, e), [
|
|
@@ -9,7 +9,7 @@ import { t as require_compiler_runtime } from "./compiler-runtime-DsR6imPN.js";
|
|
|
9
9
|
import { ut as outputIsStale } from "./html-to-image-BOiFHx3u.js";
|
|
10
10
|
import "./chunk-5FQGJX7Z-BRZ_XYUw.js";
|
|
11
11
|
import { u as createLucideIcon } from "./dist-j30bBjjN.js";
|
|
12
|
-
import { a as DEFAULT_DECK_TRANSITION, cn as EyeOff, dt as PanelGroup, fn as Code, ft as PanelResizeHandle, l as SlideSidebar, ln as Expand, n as useNotebookCodeAvailable, o as DEFAULT_DECK_VERTICAL_ALIGN, s as DEFAULT_SLIDE_TYPE, t as cellDomProps, u as Slide, ut as Panel } from "./common-
|
|
12
|
+
import { a as DEFAULT_DECK_TRANSITION, cn as EyeOff, dt as PanelGroup, fn as Code, ft as PanelResizeHandle, l as SlideSidebar, ln as Expand, n as useNotebookCodeAvailable, o as DEFAULT_DECK_VERTICAL_ALIGN, s as DEFAULT_SLIDE_TYPE, t as cellDomProps, u as Slide, ut as Panel } from "./common-DG7DA_Ws.js";
|
|
13
13
|
import { R as ChevronDown } from "./strings-DMLVGXRo.js";
|
|
14
14
|
import { X as useDebouncedCallback } from "./input-BRE2a7Ay.js";
|
|
15
15
|
import { v as kioskModeAtom } from "./toDate-BGM7kFtQ.js";
|
package/package.json
CHANGED
|
@@ -329,9 +329,9 @@ const ChatInputFooter: React.FC<ChatInputFooterProps> = memo(
|
|
|
329
329
|
},
|
|
330
330
|
{
|
|
331
331
|
value: "code_mode",
|
|
332
|
-
label: "Code Mode",
|
|
332
|
+
label: "Code Mode (beta)",
|
|
333
333
|
subtitle:
|
|
334
|
-
"AI with access to the notebook's kernel.
|
|
334
|
+
"AI with access to the notebook's kernel. Potentially destructive.",
|
|
335
335
|
Icon: CodeIcon,
|
|
336
336
|
},
|
|
337
337
|
];
|
|
@@ -23,7 +23,11 @@ import type { StorageNamespace } from "@/core/storage/types";
|
|
|
23
23
|
import { variablesAtom } from "@/core/variables/state";
|
|
24
24
|
import type { Variables } from "@/core/variables/types";
|
|
25
25
|
import { openLensTarget } from "../actions";
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
CODE_LENS_HOVER_DELAY_MS,
|
|
28
|
+
CODE_LENS_HOVER_GRACE_MS,
|
|
29
|
+
codeLensBundle,
|
|
30
|
+
} from "../extension";
|
|
27
31
|
import { mountLensPopover } from "../popover";
|
|
28
32
|
|
|
29
33
|
vi.mock("@/core/config/feature-flag", () => ({
|
|
@@ -236,9 +240,85 @@ describe("codeLensBundle", () => {
|
|
|
236
240
|
);
|
|
237
241
|
|
|
238
242
|
lens.dispatchEvent(new MouseEvent("mouseleave"));
|
|
243
|
+
// Not hidden immediately: the pointer may be on its way into the popover
|
|
244
|
+
expect(v.dom.querySelector(".mo-cm-tooltip")).not.toBeNull();
|
|
245
|
+
vi.advanceTimersByTime(CODE_LENS_HOVER_GRACE_MS);
|
|
246
|
+
expect(v.dom.querySelector(".mo-cm-tooltip")).toBeNull();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("stays open while the pointer is over the popover", async () => {
|
|
250
|
+
seedStore({ tables: [DF_TABLE] });
|
|
251
|
+
const v = await mount("df = load()");
|
|
252
|
+
const lens = lenses(v)[0];
|
|
253
|
+
|
|
254
|
+
lens.dispatchEvent(new MouseEvent("mouseenter"));
|
|
255
|
+
vi.advanceTimersByTime(CODE_LENS_HOVER_DELAY_MS);
|
|
256
|
+
const popover = v.dom.querySelector<HTMLElement>(".mo-cm-tooltip");
|
|
257
|
+
expect(popover).not.toBeNull();
|
|
258
|
+
|
|
259
|
+
// Icon -> popover within the grace period
|
|
260
|
+
lens.dispatchEvent(new MouseEvent("mouseleave"));
|
|
261
|
+
vi.advanceTimersByTime(CODE_LENS_HOVER_GRACE_MS / 2);
|
|
262
|
+
popover?.dispatchEvent(new MouseEvent("mouseenter"));
|
|
263
|
+
vi.advanceTimersByTime(CODE_LENS_HOVER_GRACE_MS * 5);
|
|
264
|
+
expect(v.dom.querySelector(".mo-cm-tooltip")).toBe(popover);
|
|
265
|
+
|
|
266
|
+
// Popover -> icon: no re-show; the popover is kept as-is
|
|
267
|
+
popover?.dispatchEvent(new MouseEvent("mouseleave"));
|
|
268
|
+
lens.dispatchEvent(new MouseEvent("mouseenter"));
|
|
269
|
+
vi.advanceTimersByTime(CODE_LENS_HOVER_DELAY_MS * 2);
|
|
270
|
+
expect(v.dom.querySelector(".mo-cm-tooltip")).toBe(popover);
|
|
271
|
+
expect(mountLensPopover).toHaveBeenCalledTimes(1);
|
|
272
|
+
|
|
273
|
+
// Leaving the popover for good hides it after the grace period
|
|
274
|
+
lens.dispatchEvent(new MouseEvent("mouseleave"));
|
|
275
|
+
popover?.dispatchEvent(new MouseEvent("mouseenter"));
|
|
276
|
+
popover?.dispatchEvent(new MouseEvent("mouseleave"));
|
|
277
|
+
vi.advanceTimersByTime(CODE_LENS_HOVER_GRACE_MS);
|
|
278
|
+
expect(v.dom.querySelector(".mo-cm-tooltip")).toBeNull();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("keeps the popover open across a lens rebuild for the same lens", async () => {
|
|
282
|
+
seedStore({ tables: [DF_TABLE] });
|
|
283
|
+
const v = await mount("df = load()");
|
|
284
|
+
const lens = lenses(v)[0];
|
|
285
|
+
|
|
286
|
+
lens.dispatchEvent(new MouseEvent("mouseenter"));
|
|
287
|
+
vi.advanceTimersByTime(CODE_LENS_HOVER_DELAY_MS);
|
|
288
|
+
const popover = v.dom.querySelector(".mo-cm-tooltip");
|
|
289
|
+
expect(popover).not.toBeNull();
|
|
290
|
+
|
|
291
|
+
// A store update triggers a (debounced) recompute of the same lenses
|
|
292
|
+
seedStore({ tables: [DF_TABLE] });
|
|
293
|
+
vi.advanceTimersByTime(300);
|
|
294
|
+
await Promise.resolve();
|
|
295
|
+
v.dispatch({});
|
|
296
|
+
expect(v.dom.querySelector(".mo-cm-tooltip")).toBe(popover);
|
|
297
|
+
|
|
298
|
+
// ...but a rebuild that drops the hovered lens closes it
|
|
299
|
+
seedStore({ tables: [] });
|
|
300
|
+
vi.advanceTimersByTime(300);
|
|
301
|
+
await Promise.resolve();
|
|
302
|
+
v.dispatch({});
|
|
303
|
+
expect(lenses(v)).toHaveLength(0);
|
|
239
304
|
expect(v.dom.querySelector(".mo-cm-tooltip")).toBeNull();
|
|
240
305
|
});
|
|
241
306
|
|
|
307
|
+
it("dismisses the editor's own hover tooltips when the icon is entered", async () => {
|
|
308
|
+
seedStore({ tables: [DF_TABLE] });
|
|
309
|
+
const v = await mount("df = load()");
|
|
310
|
+
const lens = lenses(v)[0];
|
|
311
|
+
// CodeMirror's `hoverTooltip` listens for `mouseleave` on `view.dom` to
|
|
312
|
+
// cancel a pending hover and close an open one
|
|
313
|
+
const onLeave = vi.fn();
|
|
314
|
+
v.dom.addEventListener("mouseleave", onLeave);
|
|
315
|
+
|
|
316
|
+
lens.dispatchEvent(new MouseEvent("mouseenter"));
|
|
317
|
+
|
|
318
|
+
expect(onLeave).toHaveBeenCalledTimes(1);
|
|
319
|
+
expect(onLeave.mock.calls[0][0].relatedTarget).toBe(lens);
|
|
320
|
+
});
|
|
321
|
+
|
|
242
322
|
it("does not show a popover before the hover delay", async () => {
|
|
243
323
|
seedStore({ tables: [DF_TABLE] });
|
|
244
324
|
const v = await mount("df = load()");
|
|
@@ -29,12 +29,108 @@ import { mountLensPopover } from "./popover";
|
|
|
29
29
|
// Delay (in ms) before showing the hover popover, matching the app's
|
|
30
30
|
// tooltip delay
|
|
31
31
|
export const CODE_LENS_HOVER_DELAY_MS = 400;
|
|
32
|
+
// Grace period (in ms) after the pointer leaves the icon (or the popover)
|
|
33
|
+
// before hiding, so the pointer can travel from the icon into the popover
|
|
34
|
+
// without it closing underneath
|
|
35
|
+
export const CODE_LENS_HOVER_GRACE_MS = 200;
|
|
32
36
|
|
|
33
37
|
const setCodeLenses = StateEffect.define<CodeLensSpec[]>();
|
|
34
38
|
const setHoveredLens = StateEffect.define<CodeLensSpec | null>();
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
function specEquals(a: CodeLensSpec, b: CodeLensSpec): boolean {
|
|
41
|
+
return (
|
|
42
|
+
a.pos === b.pos &&
|
|
43
|
+
a.kind === b.kind &&
|
|
44
|
+
a.name === b.name &&
|
|
45
|
+
a.cache?.boundName === b.cache?.boundName &&
|
|
46
|
+
a.cache?.cacheName === b.cache?.cacheName
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Per-view hover state shared by the lens icons and their popover, so the
|
|
52
|
+
* popover stays open while the pointer is over either of them.
|
|
53
|
+
*/
|
|
54
|
+
class LensHoverController {
|
|
55
|
+
private readonly view: EditorView;
|
|
56
|
+
private showTimer: number | undefined;
|
|
57
|
+
private hideTimer: number | undefined;
|
|
58
|
+
|
|
59
|
+
constructor(view: EditorView) {
|
|
60
|
+
this.view = view;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Pointer entered a lens icon */
|
|
64
|
+
enterLens(spec: CodeLensSpec, icon: HTMLElement): void {
|
|
65
|
+
this.clearTimers();
|
|
66
|
+
dismissEditorHoverTooltips(this.view, icon);
|
|
67
|
+
const hovered = this.view.state.field(codeLensHoverField, false);
|
|
68
|
+
if (hovered && specEquals(hovered.spec, spec)) {
|
|
69
|
+
// Already showing this lens (e.g. pointer came back from the popover)
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this.showTimer = window.setTimeout(() => {
|
|
73
|
+
this.showTimer = undefined;
|
|
74
|
+
this.view.dispatch({ effects: setHoveredLens.of(spec) });
|
|
75
|
+
}, CODE_LENS_HOVER_DELAY_MS);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Pointer left a lens icon or the popover */
|
|
79
|
+
leave(): void {
|
|
80
|
+
this.clearTimers();
|
|
81
|
+
this.hideTimer = window.setTimeout(() => {
|
|
82
|
+
this.hideTimer = undefined;
|
|
83
|
+
this.hide();
|
|
84
|
+
}, CODE_LENS_HOVER_GRACE_MS);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Pointer entered the popover */
|
|
88
|
+
enterPopover(): void {
|
|
89
|
+
window.clearTimeout(this.hideTimer);
|
|
90
|
+
this.hideTimer = undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
hide(): void {
|
|
94
|
+
this.clearTimers();
|
|
95
|
+
if (this.view.state.field(codeLensHoverField, false)) {
|
|
96
|
+
this.view.dispatch({ effects: setHoveredLens.of(null) });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
destroy(): void {
|
|
101
|
+
this.clearTimers();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private clearTimers(): void {
|
|
105
|
+
window.clearTimeout(this.showTimer);
|
|
106
|
+
window.clearTimeout(this.hideTimer);
|
|
107
|
+
this.showTimer = undefined;
|
|
108
|
+
this.hideTimer = undefined;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const lensHoverPlugin = ViewPlugin.define(
|
|
113
|
+
(view) => new LensHoverController(view),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Keeps the editor's own hover tooltips (LSP / documentation hints) from
|
|
118
|
+
* showing for the token the icon sits after.
|
|
119
|
+
*
|
|
120
|
+
* CodeMirror's `hoverTooltip` tracks the last `mousemove` seen on `view.dom`
|
|
121
|
+
* and, once the pointer has rested for its hover delay, opens a tooltip for
|
|
122
|
+
* that position. The icon swallows `mousemove` (see the widget), so a pointer
|
|
123
|
+
* resting on the icon looks to CodeMirror like a pointer resting on the last
|
|
124
|
+
* character it crossed on the way in, and any hover already open for that
|
|
125
|
+
* token never gets closed. A `mouseleave` on `view.dom` is the signal it uses
|
|
126
|
+
* to cancel a pending hover and close an open one, so synthesize that.
|
|
127
|
+
*/
|
|
128
|
+
function dismissEditorHoverTooltips(
|
|
129
|
+
view: EditorView,
|
|
130
|
+
relatedTarget: HTMLElement,
|
|
131
|
+
): void {
|
|
132
|
+
view.dom.dispatchEvent(new MouseEvent("mouseleave", { relatedTarget }));
|
|
133
|
+
}
|
|
38
134
|
|
|
39
135
|
class CodeLensWidget extends WidgetType {
|
|
40
136
|
private readonly spec: CodeLensSpec;
|
|
@@ -45,15 +141,9 @@ class CodeLensWidget extends WidgetType {
|
|
|
45
141
|
}
|
|
46
142
|
|
|
47
143
|
override eq(other: CodeLensWidget): boolean {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.spec.pos === other.spec.pos &&
|
|
52
|
-
this.spec.kind === other.spec.kind &&
|
|
53
|
-
this.spec.name === other.spec.name &&
|
|
54
|
-
this.spec.cache?.boundName === other.spec.cache?.boundName &&
|
|
55
|
-
this.spec.cache?.cacheName === other.spec.cache?.cacheName
|
|
56
|
-
);
|
|
144
|
+
// `pos` is captured by the DOM hover/click handlers, so a reused widget
|
|
145
|
+
// whose anchor moved must not be treated as equal
|
|
146
|
+
return specEquals(this.spec, other.spec);
|
|
57
147
|
}
|
|
58
148
|
|
|
59
149
|
override toDOM(view: EditorView): HTMLElement {
|
|
@@ -67,23 +157,13 @@ class CodeLensWidget extends WidgetType {
|
|
|
67
157
|
element.setAttribute("aria-label", LENS_TOOLTIPS[spec.kind]);
|
|
68
158
|
// Static, trusted markup (see icons.ts)
|
|
69
159
|
element.innerHTML = LENS_ICONS[spec.kind];
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
view.dispatch({ effects: setHoveredLens.of(null) });
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
element.onmouseenter = () => {
|
|
78
|
-
const timer = window.setTimeout(() => {
|
|
79
|
-
view.dispatch({ effects: setHoveredLens.of(spec) });
|
|
80
|
-
}, CODE_LENS_HOVER_DELAY_MS);
|
|
81
|
-
HOVER_TIMERS.set(element, timer);
|
|
82
|
-
};
|
|
83
|
-
element.onmouseleave = hidePopover;
|
|
160
|
+
const hover = () => view.plugin(lensHoverPlugin);
|
|
161
|
+
const hidePopover = () => hover()?.hide();
|
|
162
|
+
element.onmouseenter = () => hover()?.enterLens(spec, element);
|
|
163
|
+
element.onmouseleave = () => hover()?.leave();
|
|
84
164
|
element.onmousemove = (event) => {
|
|
85
|
-
// Keep the editor's built-in hover
|
|
86
|
-
//
|
|
165
|
+
// Keep the editor's built-in hover tooltip from re-arming while the
|
|
166
|
+
// pointer is over the icon (see `dismissEditorHoverTooltips`)
|
|
87
167
|
event.stopPropagation();
|
|
88
168
|
};
|
|
89
169
|
element.onmousedown = (event) => {
|
|
@@ -108,48 +188,58 @@ class CodeLensWidget extends WidgetType {
|
|
|
108
188
|
return element;
|
|
109
189
|
}
|
|
110
190
|
|
|
111
|
-
override destroy(dom: HTMLElement): void {
|
|
112
|
-
window.clearTimeout(HOVER_TIMERS.get(dom));
|
|
113
|
-
HOVER_TIMERS.delete(dom);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
191
|
override ignoreEvent(): boolean {
|
|
117
192
|
// The widget handles its own events
|
|
118
193
|
return true;
|
|
119
194
|
}
|
|
120
195
|
}
|
|
121
196
|
|
|
122
|
-
|
|
123
|
-
|
|
197
|
+
interface HoveredLens {
|
|
198
|
+
spec: CodeLensSpec;
|
|
199
|
+
tooltip: Tooltip;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function createHoveredLens(spec: CodeLensSpec): HoveredLens {
|
|
203
|
+
const tooltip: Tooltip = {
|
|
124
204
|
pos: spec.pos,
|
|
125
205
|
above: true,
|
|
126
|
-
create: () => {
|
|
206
|
+
create: (view) => {
|
|
127
207
|
const dom = document.createElement("div");
|
|
128
208
|
// Same chrome as the SQL completion/hover popovers
|
|
129
209
|
dom.classList.add("mo-cm-tooltip", "docs-documentation");
|
|
210
|
+
// The popover is scrollable, so keep it open while the pointer is
|
|
211
|
+
// inside it
|
|
212
|
+
dom.onmouseenter = () => view.plugin(lensHoverPlugin)?.enterPopover();
|
|
213
|
+
dom.onmouseleave = () => view.plugin(lensHoverPlugin)?.leave();
|
|
130
214
|
const unmount = mountLensPopover(dom, spec);
|
|
131
215
|
return { dom, resize: false, destroy: unmount };
|
|
132
216
|
},
|
|
133
217
|
};
|
|
218
|
+
return { spec, tooltip };
|
|
134
219
|
}
|
|
135
220
|
|
|
136
|
-
const codeLensHoverField = StateField.define<
|
|
221
|
+
const codeLensHoverField = StateField.define<HoveredLens | null>({
|
|
137
222
|
create() {
|
|
138
223
|
return null;
|
|
139
224
|
},
|
|
140
|
-
update(
|
|
225
|
+
update(hovered, tr) {
|
|
141
226
|
for (const effect of tr.effects) {
|
|
142
227
|
if (effect.is(setHoveredLens)) {
|
|
143
|
-
return effect.value ?
|
|
228
|
+
return effect.value ? createHoveredLens(effect.value) : null;
|
|
144
229
|
}
|
|
145
|
-
if (effect.is(setCodeLenses)) {
|
|
146
|
-
// Lenses were rebuilt
|
|
147
|
-
|
|
230
|
+
if (effect.is(setCodeLenses) && hovered) {
|
|
231
|
+
// Lenses were rebuilt (e.g. after a store update); keep the popover
|
|
232
|
+
// only if the hovered lens is still there, unchanged
|
|
233
|
+
const stillPresent = effect.value.some((spec) =>
|
|
234
|
+
specEquals(spec, hovered.spec),
|
|
235
|
+
);
|
|
236
|
+
return stillPresent ? hovered : null;
|
|
148
237
|
}
|
|
149
238
|
}
|
|
150
|
-
return tr.docChanged ? null :
|
|
239
|
+
return tr.docChanged ? null : hovered;
|
|
151
240
|
},
|
|
152
|
-
provide: (field) =>
|
|
241
|
+
provide: (field) =>
|
|
242
|
+
showTooltip.from(field, (hovered) => hovered?.tooltip ?? null),
|
|
153
243
|
});
|
|
154
244
|
|
|
155
245
|
const codeLensField = StateField.define<DecorationSet>({
|
|
@@ -263,13 +353,19 @@ class CodeLensPlugin {
|
|
|
263
353
|
}
|
|
264
354
|
}
|
|
265
355
|
|
|
356
|
+
// Padding around the 12px icon so the hover/click target isn't tiny
|
|
357
|
+
const LENS_HIT_PADDING = "3px";
|
|
358
|
+
|
|
266
359
|
const codeLensTheme = EditorView.baseTheme({
|
|
267
360
|
".mo-code-lens": {
|
|
268
361
|
display: "inline-flex",
|
|
269
362
|
verticalAlign: "baseline",
|
|
270
363
|
// Optically center the icon against the text
|
|
271
364
|
transform: "translateY(1.5px)",
|
|
272
|
-
|
|
365
|
+
// Enlarge the hit area without affecting layout: the padding is pulled
|
|
366
|
+
// back in with negative vertical margins so the line height is unchanged
|
|
367
|
+
padding: LENS_HIT_PADDING,
|
|
368
|
+
margin: `-${LENS_HIT_PADDING} 0 -${LENS_HIT_PADDING} calc(0.3em - ${LENS_HIT_PADDING})`,
|
|
273
369
|
cursor: "pointer",
|
|
274
370
|
opacity: "0.5",
|
|
275
371
|
},
|
|
@@ -290,6 +386,7 @@ export function codeLensBundle(cellId: CellId, enabled = true): Extension {
|
|
|
290
386
|
return [
|
|
291
387
|
codeLensField,
|
|
292
388
|
codeLensHoverField,
|
|
389
|
+
lensHoverPlugin,
|
|
293
390
|
ViewPlugin.define(
|
|
294
391
|
(view) => new CodeLensPlugin(view, cellId, getFeatureFlag("cache_panel")),
|
|
295
392
|
),
|