@marimo-team/islands 0.23.2-dev3 → 0.23.2-dev30
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/_basePickBy-C-mod5Dp.js +34 -0
- package/dist/{_baseUniq-C87CckHL.js → _baseUniq-Be_p_Ty6.js} +2 -2
- package/dist/{architecture-7HQA4BMR-BHdkAMvZ.js → architecture-7HQA4BMR-kNyKQXbB.js} +2 -2
- package/dist/{architectureDiagram-VXUJARFQ-B3YQo9At.js → architectureDiagram-VXUJARFQ-Dx_Dniiw.js} +11 -11
- package/dist/{blockDiagram-VD42YOAC-CpQ3TKEN.js → blockDiagram-VD42YOAC-D3hGPvEt.js} +4 -4
- package/dist/{c4Diagram-YG6GDRKO-CZSU4uqU.js → c4Diagram-YG6GDRKO-CtY1WMbV.js} +1 -1
- package/dist/{chat-ui-CNHw9Osh.js → chat-ui-CQtPb6Dj.js} +4 -4
- package/dist/{chunk-4F5CHEZ2-D5mClyDv.js → chunk-4F5CHEZ2-oWcaQSBe.js} +1 -1
- package/dist/{chunk-B2363JML-Br0eA2T3.js → chunk-B2363JML-72CRxZbk.js} +1 -1
- package/dist/{chunk-B4BG7PRW-4BjV11Br.js → chunk-B4BG7PRW-ChYfc4rf.js} +2 -2
- package/dist/{chunk-DI55MBZ5-DITY3EyP.js → chunk-DI55MBZ5-CYNE3N2j.js} +2 -2
- package/dist/{chunk-FRFDVMJY-DnEvEFRR.js → chunk-FRFDVMJY-Dgl-7l0K.js} +1 -1
- package/dist/{chunk-JA3XYJ7Z-BcPEfxk_.js → chunk-JA3XYJ7Z-B2BoMdpr.js} +1 -1
- package/dist/{chunk-JZLCHNYA-2bnLL3xL.js → chunk-JZLCHNYA-CkHD9mQU.js} +2 -2
- package/dist/{chunk-N4CR4FBY-CpZSuGSU.js → chunk-N4CR4FBY-DDeXUk3y.js} +4 -4
- package/dist/{chunk-PL6DKKU2-DnId6G-x.js → chunk-PL6DKKU2-CpBHhdj8.js} +1 -1
- package/dist/{chunk-QXUST7PY-Ch6F5Obl.js → chunk-QXUST7PY-BnSZbSK7.js} +3 -3
- package/dist/{chunk-S3R3BYOJ-B0UOFJwq.js → chunk-S3R3BYOJ-DVdRer7T.js} +1 -1
- package/dist/{chunk-SJTYNZTY-BsBZnJUj.js → chunk-SJTYNZTY-DPOwAZc-.js} +1 -1
- package/dist/{chunk-TCCFYFTB-Clbl-fTg.js → chunk-TCCFYFTB-BdE6BTq1.js} +6 -6
- package/dist/{chunk-TQ3KTPDO-CFkSQ30e.js → chunk-TQ3KTPDO-BCXCq8f2.js} +1 -1
- package/dist/{chunk-UMXZTB3W-D-A834Bq.js → chunk-UMXZTB3W-C5Hu2atA.js} +1 -1
- package/dist/{classDiagram-v2-WZHVMYZB-DrmbGANl.js → classDiagram-2ON5EDUG-sUXB0Obe.js} +6 -6
- package/dist/{classDiagram-2ON5EDUG-C8-zE3Zv.js → classDiagram-v2-WZHVMYZB-JeF9-idj.js} +6 -6
- package/dist/{clone-DZFQCtFJ.js → clone-B48LSK6I.js} +1 -1
- package/dist/{constants-CvyfaCvs.js → constants-CcdcOQyC.js} +2 -1
- package/dist/{dagre-6UL2VRFP-OMItEBnY.js → dagre-6UL2VRFP-Bs_DhCUk.js} +9 -9
- package/dist/{dagre-QVd-lCXU.js → dagre-BLW2E2fh.js} +19 -8
- package/dist/{diagram-PSM6KHXK-CkKbohWI.js → diagram-PSM6KHXK-VB3japmQ.js} +10 -10
- package/dist/{diagram-QEK2KX5R-DjUMpVcx.js → diagram-QEK2KX5R-B8nm2JL9.js} +10 -10
- package/dist/{diagram-S2PKOQOG-b-c0d-wZ.js → diagram-S2PKOQOG-D6PR_2iv.js} +10 -10
- package/dist/{erDiagram-Q2GNP2WA-CDhLaOZ1.js → erDiagram-Q2GNP2WA-gjAse7Jb.js} +5 -5
- package/dist/{flowDiagram-NV44I4VS-BDi4O4CL.js → flowDiagram-NV44I4VS-CQTSZWcI.js} +5 -5
- package/dist/{ganttDiagram-JELNMOA3-BpZE6kVp.js → ganttDiagram-JELNMOA3-aktqk_om.js} +1 -1
- package/dist/{gitGraph-G5XIXVHT-B_c6xFJv.js → gitGraph-G5XIXVHT-Cy06nzLg.js} +2 -2
- package/dist/{gitGraphDiagram-V2S2FVAM-iQnXzbPM.js → gitGraphDiagram-V2S2FVAM-C1ntKO33.js} +10 -10
- package/dist/{glide-data-editor-BFqEJGJW.js → glide-data-editor-DBgJAMqf.js} +2 -2
- package/dist/{graphlib-BV1_gi0C.js → graphlib-Cr691-na.js} +3 -3
- package/dist/{hasIn-DnfJcYpY.js → hasIn-BDDmuo1w.js} +1 -1
- package/dist/{info-VBDWY6EO-BTyzxmhr.js → info-VBDWY6EO-BIO6A8nW.js} +2 -2
- package/dist/{infoDiagram-HS3SLOUP-OYrX6uO3.js → infoDiagram-HS3SLOUP-CtfUf0g_.js} +9 -9
- package/dist/{input-CSVEkmaZ.js → input-Czatnqbz.js} +1 -1
- package/dist/{kanban-definition-3W4ZIXB7-DHEAKdZt.js → kanban-definition-3W4ZIXB7-C5FK4v7x.js} +3 -3
- package/dist/main.js +329 -179
- package/dist/{mermaid-BbhZNQeB.js → mermaid-CcM8GHeT.js} +29 -29
- package/dist/{mermaid-parser.core-ntCgyx0x.js → mermaid-parser.core-fZdPSYor.js} +8 -8
- package/dist/min-DAIOAwWK.js +102 -0
- package/dist/{mindmap-definition-VGOIOE7T-CxEUZZvY.js → mindmap-definition-VGOIOE7T-BvrQf8XZ.js} +5 -5
- package/dist/{packet-DYOGHKS2-BhvnpoGi.js → packet-DYOGHKS2-DDx1z7B-.js} +2 -2
- package/dist/pick-DfX21dj2.js +18 -0
- package/dist/{pie-VRWISCQL-dILuA3iG.js → pie-VRWISCQL-BgRtyDMT.js} +2 -2
- package/dist/{pieDiagram-ADFJNKIX-U3LrUqAS.js → pieDiagram-ADFJNKIX-DAhjFwJD.js} +10 -10
- package/dist/{process-output-Bekznt_B.js → process-output-CzeGyEyz.js} +2138 -2124
- package/dist/{radar-ZZBFDIW7-DwFrOJDj.js → radar-ZZBFDIW7-xwh47Yzn.js} +2 -2
- package/dist/{requirementDiagram-UZGBJVZJ-D0zpQnKC.js → requirementDiagram-UZGBJVZJ-B3nnp0VG.js} +5 -5
- package/dist/{sequenceDiagram-WL72ISMW-D1BJxLjH.js → sequenceDiagram-WL72ISMW-D2mpRRG2.js} +1 -1
- package/dist/{stateDiagram-FKZM4ZOC-B1S8jGMn.js → stateDiagram-FKZM4ZOC-QD9Wuca0.js} +8 -8
- package/dist/{stateDiagram-v2-4FDKWEC3-BH5ozUbc.js → stateDiagram-v2-4FDKWEC3-DnUhJ525.js} +6 -6
- package/dist/{toDate-B1AzlBoW.js → toDate-BxaMtnNb.js} +1 -1
- package/dist/{treemap-GDKQZRPO-bx2ngsgN.js → treemap-GDKQZRPO-5ZsmvXgc.js} +2 -2
- package/dist/{types-pwjdK009.js → types-DZvw9zQT.js} +1 -1
- package/dist/{useDeepCompareMemoize-CsyOnnjc.js → useDeepCompareMemoize-BOrrcIxj.js} +1 -1
- package/dist/{vega-component-KBJXEDZz.js → vega-component-CrVeizNZ.js} +3 -3
- package/dist/{xychartDiagram-PRI3JC2R-CuAZiqHS.js → xychartDiagram-PRI3JC2R-BMsB7VdF.js} +2 -2
- package/package.json +2 -2
- package/src/components/data-table/TableBottomBar.tsx +5 -1
- package/src/components/data-table/__tests__/filters.test.ts +304 -0
- package/src/components/data-table/__tests__/pagination.test.tsx +46 -132
- package/src/components/data-table/column-explorer-panel/column-explorer.tsx +1 -1
- package/src/components/data-table/filters.ts +87 -33
- package/src/components/data-table/pagination.tsx +189 -76
- package/src/components/data-table/types.ts +0 -4
- package/src/components/editor/Output.tsx +1 -1
- package/src/components/editor/actions/useNotebookActions.tsx +12 -0
- package/src/components/editor/cell/code/cell-editor.tsx +1 -0
- package/src/core/cells/__tests__/apply-transaction.test.ts +42 -0
- package/src/core/cells/__tests__/logs.test.ts +101 -0
- package/src/core/cells/logs.ts +9 -1
- package/src/core/codemirror/__tests__/__snapshots__/setup.test.ts.snap +4 -14
- package/src/core/codemirror/cells/extensions.ts +0 -4
- package/src/core/codemirror/keymaps/keymaps.ts +69 -2
- package/src/core/codemirror/language/languages/python.ts +9 -9
- package/src/core/codemirror/lsp/__tests__/notebook-lsp.test.ts +8 -1
- package/src/core/codemirror/lsp/federated-lsp.ts +2 -2
- package/src/core/codemirror/lsp/notebook-lsp.ts +2 -2
- package/src/core/codemirror/lsp/utils.ts +21 -6
- package/src/core/constants.ts +1 -0
- package/src/plugins/impl/DataTablePlugin.tsx +7 -20
- package/src/plugins/impl/TabsPlugin.tsx +18 -12
- package/src/plugins/impl/data-frames/DataFramePlugin.tsx +4 -4
- package/src/plugins/impl/data-frames/schema.ts +41 -9
- package/src/plugins/impl/data-frames/utils/operators.ts +2 -0
- package/src/plugins/impl/matplotlib/matplotlib-renderer.ts +16 -0
- package/dist/_basePickBy-Sow3pJjS.js +0 -41
- package/dist/min-Ds3gG0Ff.js +0 -96
- package/dist/range-fJeId9Ri.js +0 -30
- /package/dist/{isEmpty-B7FX9wKt.js → isEmpty-D3lf6gH3.js} +0 -0
- /package/dist/{memoize-CSTI9eOX.js → memoize-DEvRzlwP.js} +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"use no memo";
|
|
3
3
|
|
|
4
4
|
import type { Table } from "@tanstack/react-table";
|
|
5
|
-
import {
|
|
5
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
6
6
|
import {
|
|
7
7
|
ChevronDown,
|
|
8
8
|
ChevronLeft,
|
|
@@ -37,9 +37,6 @@ import { cn } from "@/utils/cn";
|
|
|
37
37
|
import { Events } from "@/utils/events";
|
|
38
38
|
import { prettyNumber } from "@/utils/numbers";
|
|
39
39
|
import { PluralWord } from "@/utils/pluralize";
|
|
40
|
-
import type { PageRange } from "./types";
|
|
41
|
-
|
|
42
|
-
const MAX_PAGES_BEFORE_CLAMPING = 100;
|
|
43
40
|
|
|
44
41
|
interface DataTablePaginationProps<TData> {
|
|
45
42
|
table: Table<TData>;
|
|
@@ -189,6 +186,81 @@ export const DataTablePagination = <TData,>({
|
|
|
189
186
|
);
|
|
190
187
|
};
|
|
191
188
|
|
|
189
|
+
const PAGE_ITEM_HEIGHT = 32;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Compute contiguous ranges of page numbers whose string starts with `prefix`,
|
|
193
|
+
* without scanning every page. O(log10(totalPages)).
|
|
194
|
+
*
|
|
195
|
+
* For prefix "5", totalPages=500: [[5,5], [50,59], [500,500]]
|
|
196
|
+
*/
|
|
197
|
+
export function matchingPageRanges(
|
|
198
|
+
prefix: string,
|
|
199
|
+
totalPages: number,
|
|
200
|
+
): [number, number][] {
|
|
201
|
+
const n = Number.parseInt(prefix, 10);
|
|
202
|
+
if (Number.isNaN(n) || n <= 0 || String(n) !== prefix) {
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const ranges: [number, number][] = [];
|
|
207
|
+
let power = 1;
|
|
208
|
+
while (n * power <= totalPages) {
|
|
209
|
+
const start = n * power;
|
|
210
|
+
const end = Math.min((n + 1) * power - 1, totalPages);
|
|
211
|
+
ranges.push([start, end]);
|
|
212
|
+
power *= 10;
|
|
213
|
+
}
|
|
214
|
+
return ranges;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
interface PageMapping {
|
|
218
|
+
count: number;
|
|
219
|
+
pageAtIndex: (index: number) => number;
|
|
220
|
+
indexOfPage: (page: number) => number;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function createPageMapping(search: string, totalPages: number): PageMapping {
|
|
224
|
+
if (search === "") {
|
|
225
|
+
return {
|
|
226
|
+
count: totalPages,
|
|
227
|
+
pageAtIndex: (i) => i + 1,
|
|
228
|
+
indexOfPage: (p) => p - 1,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const ranges = matchingPageRanges(search, totalPages);
|
|
233
|
+
let count = 0;
|
|
234
|
+
for (const [s, e] of ranges) {
|
|
235
|
+
count += e - s + 1;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
count,
|
|
240
|
+
pageAtIndex: (i) => {
|
|
241
|
+
let offset = 0;
|
|
242
|
+
for (const [start, end] of ranges) {
|
|
243
|
+
const size = end - start + 1;
|
|
244
|
+
if (i < offset + size) {
|
|
245
|
+
return start + (i - offset);
|
|
246
|
+
}
|
|
247
|
+
offset += size;
|
|
248
|
+
}
|
|
249
|
+
return -1;
|
|
250
|
+
},
|
|
251
|
+
indexOfPage: (p) => {
|
|
252
|
+
let offset = 0;
|
|
253
|
+
for (const [start, end] of ranges) {
|
|
254
|
+
if (p >= start && p <= end) {
|
|
255
|
+
return offset + (p - start);
|
|
256
|
+
}
|
|
257
|
+
offset += end - start + 1;
|
|
258
|
+
}
|
|
259
|
+
return -1;
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
192
264
|
export const PageSelector = ({
|
|
193
265
|
currentPage,
|
|
194
266
|
totalPages,
|
|
@@ -199,19 +271,31 @@ export const PageSelector = ({
|
|
|
199
271
|
onPageChange: (page: number) => void;
|
|
200
272
|
}) => {
|
|
201
273
|
const [open, setOpen] = React.useState(false);
|
|
274
|
+
const [search, setSearch] = React.useState("");
|
|
202
275
|
|
|
203
|
-
const
|
|
204
|
-
() =>
|
|
205
|
-
[
|
|
276
|
+
const mapping = React.useMemo(
|
|
277
|
+
() => createPageMapping(search, totalPages),
|
|
278
|
+
[search, totalPages],
|
|
206
279
|
);
|
|
207
280
|
|
|
208
281
|
const handleSelect = (page: number) => {
|
|
209
282
|
onPageChange(page - 1);
|
|
283
|
+
setSearch("");
|
|
210
284
|
setOpen(false);
|
|
211
285
|
};
|
|
212
286
|
|
|
287
|
+
const listHeight = Math.min(mapping.count * PAGE_ITEM_HEIGHT, 240);
|
|
288
|
+
|
|
213
289
|
return (
|
|
214
|
-
<Popover
|
|
290
|
+
<Popover
|
|
291
|
+
open={totalPages > 1 ? open : false}
|
|
292
|
+
onOpenChange={(next) => {
|
|
293
|
+
setOpen(next);
|
|
294
|
+
if (!next) {
|
|
295
|
+
setSearch("");
|
|
296
|
+
}
|
|
297
|
+
}}
|
|
298
|
+
>
|
|
215
299
|
<PopoverTrigger asChild={true} disabled={totalPages <= 1}>
|
|
216
300
|
<button
|
|
217
301
|
type="button"
|
|
@@ -229,18 +313,15 @@ export const PageSelector = ({
|
|
|
229
313
|
</button>
|
|
230
314
|
</PopoverTrigger>
|
|
231
315
|
<PopoverContent className="w-36 p-0" align="center" sideOffset={6}>
|
|
232
|
-
<Command
|
|
233
|
-
shouldFilter={true}
|
|
234
|
-
filter={(value, search) => {
|
|
235
|
-
return value.startsWith(search) ? 1 : 0;
|
|
236
|
-
}}
|
|
237
|
-
>
|
|
316
|
+
<Command shouldFilter={false} value={String(currentPage)}>
|
|
238
317
|
<CommandInput
|
|
239
318
|
placeholder={`Page (1–${totalPages})`}
|
|
240
319
|
rootClassName="px-2 h-8"
|
|
241
320
|
className="text-xs h-8"
|
|
242
321
|
autoFocus={true}
|
|
243
322
|
icon={null}
|
|
323
|
+
value={search}
|
|
324
|
+
onValueChange={setSearch}
|
|
244
325
|
onKeyDown={(e) => {
|
|
245
326
|
// Allow navigation/editing keys, block non-numeric input
|
|
246
327
|
const allowed = [
|
|
@@ -248,6 +329,8 @@ export const PageSelector = ({
|
|
|
248
329
|
"Delete",
|
|
249
330
|
"ArrowLeft",
|
|
250
331
|
"ArrowRight",
|
|
332
|
+
"ArrowUp",
|
|
333
|
+
"ArrowDown",
|
|
251
334
|
"Tab",
|
|
252
335
|
"Enter",
|
|
253
336
|
"Escape",
|
|
@@ -257,27 +340,19 @@ export const PageSelector = ({
|
|
|
257
340
|
}
|
|
258
341
|
}}
|
|
259
342
|
/>
|
|
260
|
-
<CommandList className="max-h-60">
|
|
261
|
-
{
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
onMouseDown={Events.preventFocus}
|
|
273
|
-
>
|
|
274
|
-
{item.page}
|
|
275
|
-
</CommandItem>
|
|
276
|
-
),
|
|
343
|
+
<CommandList className="max-h-60 overflow-hidden">
|
|
344
|
+
{mapping.count === 0 ? (
|
|
345
|
+
<CommandEmpty className="py-2 text-center text-xs text-muted-foreground">
|
|
346
|
+
No matching page
|
|
347
|
+
</CommandEmpty>
|
|
348
|
+
) : (
|
|
349
|
+
<VirtualizedPageList
|
|
350
|
+
mapping={mapping}
|
|
351
|
+
currentPage={currentPage}
|
|
352
|
+
listHeight={listHeight}
|
|
353
|
+
onSelect={handleSelect}
|
|
354
|
+
/>
|
|
277
355
|
)}
|
|
278
|
-
<CommandEmpty className="py-2 text-center text-xs text-muted-foreground">
|
|
279
|
-
No matching page
|
|
280
|
-
</CommandEmpty>
|
|
281
356
|
</CommandList>
|
|
282
357
|
</Command>
|
|
283
358
|
</PopoverContent>
|
|
@@ -285,57 +360,95 @@ export const PageSelector = ({
|
|
|
285
360
|
);
|
|
286
361
|
};
|
|
287
362
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const
|
|
300
|
-
for (let i = 0; i < count; i++) {
|
|
301
|
-
items.push({ type: "page", page: start + i });
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
addPages(1, 10);
|
|
306
|
-
items.push({ type: "ellipsis", key: "e1" });
|
|
307
|
-
|
|
308
|
-
if (currentPage > 10 && currentPage <= middle - 5) {
|
|
309
|
-
items.push(
|
|
310
|
-
{ type: "page", page: currentPage },
|
|
311
|
-
{ type: "ellipsis", key: "e1b" },
|
|
312
|
-
);
|
|
313
|
-
}
|
|
363
|
+
const VirtualizedPageList = ({
|
|
364
|
+
mapping,
|
|
365
|
+
currentPage,
|
|
366
|
+
listHeight,
|
|
367
|
+
onSelect,
|
|
368
|
+
}: {
|
|
369
|
+
mapping: PageMapping;
|
|
370
|
+
currentPage: number;
|
|
371
|
+
listHeight: number;
|
|
372
|
+
onSelect: (page: number) => void;
|
|
373
|
+
}) => {
|
|
374
|
+
const parentRef = React.useRef<HTMLDivElement>(null);
|
|
314
375
|
|
|
315
|
-
|
|
316
|
-
items.push({ type: "ellipsis", key: "e2" });
|
|
376
|
+
const currentIndex = mapping.indexOfPage(currentPage);
|
|
317
377
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
378
|
+
const virtualizer = useVirtualizer({
|
|
379
|
+
count: mapping.count,
|
|
380
|
+
getScrollElement: () => parentRef.current,
|
|
381
|
+
estimateSize: () => PAGE_ITEM_HEIGHT,
|
|
382
|
+
overscan: 10,
|
|
383
|
+
initialOffset:
|
|
384
|
+
currentIndex > 0
|
|
385
|
+
? Math.max(0, currentIndex * PAGE_ITEM_HEIGHT - listHeight / 2)
|
|
386
|
+
: 0,
|
|
387
|
+
});
|
|
324
388
|
|
|
325
|
-
|
|
389
|
+
// Scroll to top when filtered results change (user is searching)
|
|
390
|
+
const prevCount = React.useRef(mapping.count);
|
|
391
|
+
React.useEffect(() => {
|
|
392
|
+
if (mapping.count !== prevCount.current) {
|
|
393
|
+
virtualizer.scrollToIndex(0);
|
|
394
|
+
prevCount.current = mapping.count;
|
|
395
|
+
}
|
|
396
|
+
}, [mapping.count, virtualizer]);
|
|
326
397
|
|
|
327
|
-
return
|
|
328
|
-
}
|
|
398
|
+
return (
|
|
399
|
+
<div ref={parentRef} style={{ height: listHeight, overflow: "auto" }}>
|
|
400
|
+
<div
|
|
401
|
+
style={{
|
|
402
|
+
height: virtualizer.getTotalSize(),
|
|
403
|
+
width: "100%",
|
|
404
|
+
position: "relative",
|
|
405
|
+
}}
|
|
406
|
+
>
|
|
407
|
+
{virtualizer.getVirtualItems().map((virtualItem) => {
|
|
408
|
+
const page = mapping.pageAtIndex(virtualItem.index);
|
|
409
|
+
return (
|
|
410
|
+
<CommandItem
|
|
411
|
+
key={page}
|
|
412
|
+
value={String(page)}
|
|
413
|
+
data-testid="page-option"
|
|
414
|
+
aria-selected={page === currentPage}
|
|
415
|
+
className={cn(
|
|
416
|
+
"text-xs cursor-pointer",
|
|
417
|
+
page === currentPage && "font-semibold bg-accent",
|
|
418
|
+
)}
|
|
419
|
+
style={{
|
|
420
|
+
position: "absolute",
|
|
421
|
+
top: 0,
|
|
422
|
+
left: 0,
|
|
423
|
+
width: "100%",
|
|
424
|
+
height: virtualItem.size,
|
|
425
|
+
transform: `translateY(${virtualItem.start}px)`,
|
|
426
|
+
}}
|
|
427
|
+
onSelect={() => onSelect(page)}
|
|
428
|
+
onMouseDown={Events.preventFocus}
|
|
429
|
+
>
|
|
430
|
+
{page}
|
|
431
|
+
</CommandItem>
|
|
432
|
+
);
|
|
433
|
+
})}
|
|
434
|
+
</div>
|
|
435
|
+
</div>
|
|
436
|
+
);
|
|
437
|
+
};
|
|
329
438
|
|
|
330
439
|
export function prettifyRowCount(rowCount: number, locale: string): string {
|
|
331
440
|
return `${prettyNumber(rowCount, locale)} ${new PluralWord("row").pluralize(rowCount)}`;
|
|
332
441
|
}
|
|
333
442
|
|
|
334
|
-
export const prettifyRowColumnCount = (
|
|
335
|
-
numRows
|
|
336
|
-
totalColumns
|
|
337
|
-
locale
|
|
338
|
-
|
|
443
|
+
export const prettifyRowColumnCount = ({
|
|
444
|
+
numRows,
|
|
445
|
+
totalColumns,
|
|
446
|
+
locale,
|
|
447
|
+
}: {
|
|
448
|
+
numRows: number | "too_many";
|
|
449
|
+
totalColumns: number;
|
|
450
|
+
locale: string;
|
|
451
|
+
}): string => {
|
|
339
452
|
const rowsLabel =
|
|
340
453
|
numRows === "too_many" ? "Unknown" : prettifyRowCount(numRows, locale);
|
|
341
454
|
const columnsLabel = `${prettyNumber(totalColumns, locale)} ${new PluralWord("column").pluralize(totalColumns)}`;
|
|
@@ -105,7 +105,3 @@ export function extractTimezone(dtype: string | undefined): string | undefined {
|
|
|
105
105
|
const match = /^datetime(?:64)?\[[^,]+,([^,]+)]$/.exec(dtype);
|
|
106
106
|
return match?.[1]?.trim();
|
|
107
107
|
}
|
|
108
|
-
|
|
109
|
-
export type PageRange =
|
|
110
|
-
| { type: "page"; page: number }
|
|
111
|
-
| { type: "ellipsis"; key: string };
|
|
@@ -263,7 +263,7 @@ const MimeBundleOutputRenderer: React.FC<{
|
|
|
263
263
|
const { mode } = useAtomValue(viewStateAtom);
|
|
264
264
|
const appView = mode === "present" || mode === "read";
|
|
265
265
|
|
|
266
|
-
// Extract metadata if present (e.g.,
|
|
266
|
+
// Extract metadata if present (e.g., to maintain a constant display size regardless of DPI/PPI)
|
|
267
267
|
const metadata = mimebundle[METADATA_KEY];
|
|
268
268
|
|
|
269
269
|
// Filter out metadata from the mime entries and type narrow
|
|
@@ -381,6 +381,18 @@ export function useNotebookActions() {
|
|
|
381
381
|
});
|
|
382
382
|
},
|
|
383
383
|
},
|
|
384
|
+
{
|
|
385
|
+
icon: <MarimoPlusIcon size={14} strokeWidth={1.5} />,
|
|
386
|
+
label: "Create molab notebook",
|
|
387
|
+
handle: async () => {
|
|
388
|
+
const code = await readCode();
|
|
389
|
+
const url = createShareableLink({
|
|
390
|
+
code: code.contents,
|
|
391
|
+
baseUrl: `${Constants.molab}/new`,
|
|
392
|
+
});
|
|
393
|
+
window.open(url, "_blank");
|
|
394
|
+
},
|
|
395
|
+
},
|
|
384
396
|
],
|
|
385
397
|
},
|
|
386
398
|
|
|
@@ -305,4 +305,46 @@ describe("applyTransactionChanges edge cases", () => {
|
|
|
305
305
|
"
|
|
306
306
|
`);
|
|
307
307
|
});
|
|
308
|
+
|
|
309
|
+
it("set-code updates the mounted editor view's document", () => {
|
|
310
|
+
// Existing tests only check cellData.code — this covers the editor
|
|
311
|
+
// view side, so regressions in the reducer's imperative sync (or in
|
|
312
|
+
// the CellEditor useEffect that backs it up) don't go unnoticed.
|
|
313
|
+
setup('x = "BEFORE"');
|
|
314
|
+
const [a] = state.cellIds.inOrderIds;
|
|
315
|
+
const editorView = state.cellHandles[a].current?.editorViewOrNull;
|
|
316
|
+
expect(editorView?.state.doc.toString()).toBe('x = "BEFORE"');
|
|
317
|
+
|
|
318
|
+
apply([{ type: "set-code", cellId: a, code: 'x = "AFTER"' }]);
|
|
319
|
+
|
|
320
|
+
expect(state.cellData[a].code).toBe('x = "AFTER"');
|
|
321
|
+
expect(editorView?.state.doc.toString()).toBe('x = "AFTER"');
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it("create-cell then set-code on same cell updates editor", () => {
|
|
325
|
+
// Mirrors the code_mode flow that exposed marimo-pair#27: create_cell
|
|
326
|
+
// in one batch, edit_cell in a second batch, each arriving as a
|
|
327
|
+
// separate transaction.
|
|
328
|
+
setup();
|
|
329
|
+
apply([
|
|
330
|
+
{
|
|
331
|
+
type: "create-cell",
|
|
332
|
+
cellId: cellId("repro"),
|
|
333
|
+
code: 'x = "BEFORE"',
|
|
334
|
+
name: "repro_bug",
|
|
335
|
+
config: {},
|
|
336
|
+
},
|
|
337
|
+
]);
|
|
338
|
+
const editorView =
|
|
339
|
+
state.cellHandles[cellId("repro")].current?.editorViewOrNull;
|
|
340
|
+
expect(editorView?.state.doc.toString()).toBe('x = "BEFORE"');
|
|
341
|
+
|
|
342
|
+
apply([
|
|
343
|
+
{ type: "set-code", cellId: cellId("repro"), code: 'x = "AFTER"' },
|
|
344
|
+
{ type: "reorder-cells", cellIds: [cellId("repro")] },
|
|
345
|
+
]);
|
|
346
|
+
|
|
347
|
+
expect(state.cellData[cellId("repro")].code).toBe('x = "AFTER"');
|
|
348
|
+
expect(editorView?.state.doc.toString()).toBe('x = "AFTER"');
|
|
349
|
+
});
|
|
308
350
|
});
|
|
@@ -5,6 +5,11 @@ import { cellId } from "@/__tests__/branded";
|
|
|
5
5
|
import type { CellMessage } from "../../kernel/messages";
|
|
6
6
|
import { formatLogTimestamp, getCellLogsForMessage } from "../logs";
|
|
7
7
|
|
|
8
|
+
// Stable mock reference so every (re)import of use-toast sees the same spy,
|
|
9
|
+
// even after vi.resetModules() clears the module cache between tests.
|
|
10
|
+
const { toastMock } = vi.hoisted(() => ({ toastMock: vi.fn() }));
|
|
11
|
+
vi.mock("@/components/ui/use-toast", () => ({ toast: toastMock }));
|
|
12
|
+
|
|
8
13
|
describe("getCellLogsForMessage", () => {
|
|
9
14
|
beforeEach(() => {
|
|
10
15
|
// Mock console.log to avoid cluttering test output
|
|
@@ -324,6 +329,102 @@ describe("getCellLogsForMessage", () => {
|
|
|
324
329
|
});
|
|
325
330
|
});
|
|
326
331
|
|
|
332
|
+
describe("getCellLogsForMessage - internal error toast", () => {
|
|
333
|
+
// Re-imported per test after vi.resetModules() so the module-level
|
|
334
|
+
// `didAlreadyToastError` flag starts fresh and all jotai atom references
|
|
335
|
+
// (initialModeAtom, etc.) match the versions used by the reset logs.ts.
|
|
336
|
+
let getLogs: typeof import("../logs").getCellLogsForMessage;
|
|
337
|
+
let store: typeof import("@/core/state/jotai").store;
|
|
338
|
+
let initialModeAtom: typeof import("@/core/mode").initialModeAtom;
|
|
339
|
+
|
|
340
|
+
beforeEach(async () => {
|
|
341
|
+
vi.spyOn(console, "log").mockImplementation(() => {
|
|
342
|
+
// no-op
|
|
343
|
+
});
|
|
344
|
+
vi.resetModules();
|
|
345
|
+
({ getCellLogsForMessage: getLogs } = await import("../logs"));
|
|
346
|
+
({ store } = await import("@/core/state/jotai"));
|
|
347
|
+
({ initialModeAtom } = await import("@/core/mode"));
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
afterEach(() => {
|
|
351
|
+
vi.restoreAllMocks();
|
|
352
|
+
vi.clearAllMocks();
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
const makeErrorCellMessage = (id: CellMessage["cell_id"]): CellMessage => ({
|
|
356
|
+
cell_id: id,
|
|
357
|
+
console: [],
|
|
358
|
+
output: {
|
|
359
|
+
mimetype: "application/vnd.marimo+error",
|
|
360
|
+
data: [
|
|
361
|
+
{
|
|
362
|
+
type: "exception",
|
|
363
|
+
exception_type: "ValueError",
|
|
364
|
+
msg: "something exploded",
|
|
365
|
+
traceback: ["File foo.py, line 1", "ValueError: something exploded"],
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
channel: "marimo-error",
|
|
369
|
+
timestamp: 0,
|
|
370
|
+
} as unknown as CellMessage["output"],
|
|
371
|
+
status: "idle",
|
|
372
|
+
stale_inputs: null,
|
|
373
|
+
timestamp: 0,
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
test("shows toast for internal errors in app (read) mode", () => {
|
|
377
|
+
store.set(initialModeAtom, "read");
|
|
378
|
+
|
|
379
|
+
getLogs(makeErrorCellMessage(cellId("cell-err-1")));
|
|
380
|
+
|
|
381
|
+
expect(toastMock).toHaveBeenCalledTimes(1);
|
|
382
|
+
expect(toastMock).toHaveBeenCalledWith(
|
|
383
|
+
expect.objectContaining({
|
|
384
|
+
title: "An internal error occurred",
|
|
385
|
+
variant: "danger",
|
|
386
|
+
}),
|
|
387
|
+
);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
test("does not show toast for internal errors in edit mode", () => {
|
|
391
|
+
store.set(initialModeAtom, "edit");
|
|
392
|
+
|
|
393
|
+
getLogs(makeErrorCellMessage(cellId("cell-err-2")));
|
|
394
|
+
|
|
395
|
+
expect(toastMock).not.toHaveBeenCalled();
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
test("edit-mode errors do not consume the once-per-session toast slot", () => {
|
|
399
|
+
// Errors received while in edit mode should be silently skipped...
|
|
400
|
+
store.set(initialModeAtom, "edit");
|
|
401
|
+
getLogs(makeErrorCellMessage(cellId("cell-err-3")));
|
|
402
|
+
expect(toastMock).not.toHaveBeenCalled();
|
|
403
|
+
|
|
404
|
+
// ...and a subsequent error in app mode should still toast.
|
|
405
|
+
store.set(initialModeAtom, "read");
|
|
406
|
+
getLogs(makeErrorCellMessage(cellId("cell-err-4")));
|
|
407
|
+
expect(toastMock).toHaveBeenCalledTimes(1);
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
test("toast only fires once across multiple app-mode errors", () => {
|
|
411
|
+
store.set(initialModeAtom, "read");
|
|
412
|
+
|
|
413
|
+
getLogs(makeErrorCellMessage(cellId("cell-err-5")));
|
|
414
|
+
getLogs(makeErrorCellMessage(cellId("cell-err-6")));
|
|
415
|
+
|
|
416
|
+
expect(toastMock).toHaveBeenCalledTimes(1);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
test("suppresses toast when initial mode has not been set", () => {
|
|
420
|
+
// Leave initialModeAtom at its default (undefined); getInitialAppMode
|
|
421
|
+
// will throw and the logic should swallow it without toasting.
|
|
422
|
+
getLogs(makeErrorCellMessage(cellId("cell-err-7")));
|
|
423
|
+
|
|
424
|
+
expect(toastMock).not.toHaveBeenCalled();
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
|
|
327
428
|
describe("formatLogTimestamp", () => {
|
|
328
429
|
test("formats unix timestamp correctly", () => {
|
|
329
430
|
// January 1, 2024, 12:00:00 PM UTC
|
package/src/core/cells/logs.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { Strings } from "@/utils/strings";
|
|
|
7
7
|
import type { CellMessage, OutputMessage } from "../kernel/messages";
|
|
8
8
|
import { isErrorMime } from "../mime";
|
|
9
9
|
import type { CellId } from "./ids";
|
|
10
|
+
import { initialModeAtom } from "../mode";
|
|
10
11
|
import { store } from "../state/jotai";
|
|
11
12
|
import { tracebackModalAtom } from "../errors/traceback-atom";
|
|
12
13
|
import React from "react";
|
|
@@ -83,7 +84,14 @@ export function getCellLogsForMessage(cell: CellMessage): CellLog[] {
|
|
|
83
84
|
error.type === "internal",
|
|
84
85
|
);
|
|
85
86
|
|
|
86
|
-
|
|
87
|
+
// Only show the toast in app mode: edit mode already surfaces errors in
|
|
88
|
+
// the cell UI, so toasting there would be noisy and duplicative. Read the
|
|
89
|
+
// atom directly so an unset initial mode (e.g. in tests/islands) simply
|
|
90
|
+
// returns undefined instead of throwing and masking real errors.
|
|
91
|
+
const isAppMode = store.get(initialModeAtom) === "read";
|
|
92
|
+
|
|
93
|
+
// Only show toast once, and only in app mode
|
|
94
|
+
if (exceptionErrors.length > 0 && !didAlreadyToastError && isAppMode) {
|
|
87
95
|
didAlreadyToastError = true;
|
|
88
96
|
|
|
89
97
|
// Find first error with a traceback
|
|
@@ -9,9 +9,7 @@ exports[`snapshot all duplicate keymaps > default keymaps 2`] = `
|
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
"key": "ArrowDown",
|
|
12
|
-
"preventDefault": true,
|
|
13
12
|
"run": "run",
|
|
14
|
-
"stopPropagation": true,
|
|
15
13
|
},
|
|
16
14
|
{
|
|
17
15
|
"key": "ArrowDown",
|
|
@@ -27,9 +25,7 @@ exports[`snapshot all duplicate keymaps > default keymaps 2`] = `
|
|
|
27
25
|
},
|
|
28
26
|
{
|
|
29
27
|
"key": "ArrowUp",
|
|
30
|
-
"preventDefault": true,
|
|
31
28
|
"run": "run",
|
|
32
|
-
"stopPropagation": true,
|
|
33
29
|
},
|
|
34
30
|
{
|
|
35
31
|
"key": "ArrowUp",
|
|
@@ -118,15 +114,12 @@ exports[`snapshot all duplicate keymaps > vim keymaps 2`] = `
|
|
|
118
114
|
},
|
|
119
115
|
{
|
|
120
116
|
"key": "ArrowDown",
|
|
121
|
-
"preventDefault": true,
|
|
122
117
|
"run": "run",
|
|
123
|
-
"stopPropagation": true,
|
|
124
118
|
},
|
|
125
119
|
{
|
|
126
120
|
"key": "ArrowDown",
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
"shift": "selectLineDown",
|
|
121
|
+
"run": "<no name>",
|
|
122
|
+
"shift": "<no name>",
|
|
130
123
|
},
|
|
131
124
|
],
|
|
132
125
|
"ArrowUp": [
|
|
@@ -136,15 +129,12 @@ exports[`snapshot all duplicate keymaps > vim keymaps 2`] = `
|
|
|
136
129
|
},
|
|
137
130
|
{
|
|
138
131
|
"key": "ArrowUp",
|
|
139
|
-
"preventDefault": true,
|
|
140
132
|
"run": "run",
|
|
141
|
-
"stopPropagation": true,
|
|
142
133
|
},
|
|
143
134
|
{
|
|
144
135
|
"key": "ArrowUp",
|
|
145
|
-
"
|
|
146
|
-
"
|
|
147
|
-
"shift": "selectLineUp",
|
|
136
|
+
"run": "<no name>",
|
|
137
|
+
"shift": "<no name>",
|
|
148
138
|
},
|
|
149
139
|
],
|
|
150
140
|
"Backspace": [
|
|
@@ -169,8 +169,6 @@ function cellKeymaps({
|
|
|
169
169
|
},
|
|
170
170
|
{
|
|
171
171
|
key: "ArrowUp",
|
|
172
|
-
preventDefault: true,
|
|
173
|
-
stopPropagation: true,
|
|
174
172
|
run: (ev) => {
|
|
175
173
|
// Skip if we are in the middle of an autocompletion
|
|
176
174
|
const hasAutocomplete = completionStatus(ev.state);
|
|
@@ -188,8 +186,6 @@ function cellKeymaps({
|
|
|
188
186
|
},
|
|
189
187
|
{
|
|
190
188
|
key: "ArrowDown",
|
|
191
|
-
preventDefault: true,
|
|
192
|
-
stopPropagation: true,
|
|
193
189
|
run: (ev) => {
|
|
194
190
|
// Skip if we are in the middle of an autocompletion
|
|
195
191
|
const hasAutocomplete = completionStatus(ev.state);
|