@marimo-team/islands 0.23.10-dev9 → 0.23.10
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/{ConnectedDataExplorerComponent-CyV83R2m.js → ConnectedDataExplorerComponent-Z3RP7Vmm.js} +31 -31
- package/dist/{ErrorBoundary-rULOrC_p.js → ErrorBoundary-DpbaKVv7.js} +1 -1
- package/dist/{any-language-editor-CiES2a2h.js → any-language-editor-CAgFD4Kd.js} +20 -20
- package/dist/assets/__vite-browser-external-eshhtsgZ.js +1 -0
- package/dist/assets/worker-CC0Oul9k.js +73 -0
- package/dist/{chat-ui-K84W5ecY.js → chat-ui-C4-GMW9y.js} +77 -77
- package/dist/{check-DTbrK0zt.js → check-BCaJeT-J.js} +1 -1
- package/dist/{chunk-5FQGJX7Z-BNjes6Yx.js → chunk-5FQGJX7Z-BbqSm5gU.js} +1227 -1222
- package/dist/{code-block-37QAKDTI-m92Yc8pv.js → code-block-37QAKDTI-O6IH6wAi.js} +1 -1
- package/dist/{code-visibility-v6ucEVUg.js → code-visibility-DrFozVlm.js} +1943 -1223
- package/dist/{copy-5jQ_kGE1.js → copy-UqRYxiOg.js} +1 -1
- package/dist/dist-7QfXoMdB.js +5 -0
- package/dist/{dist-DgnE8F-r.js → dist-A2846XWO.js} +1 -1
- package/dist/dist-BEXXyZig.js +5 -0
- package/dist/{dist-B3pZ0Ab6.js → dist-BR_gyG9L.js} +3 -3
- package/dist/{dist-CcXxepx6.js → dist-BSAt6RhH.js} +27 -27
- package/dist/{dist-Bde4a2kU.js → dist-BY018Paw.js} +8 -8
- package/dist/dist-BYj57OV4.js +5 -0
- package/dist/{dist-CUCNs1ja.js → dist-BaoDKvdy.js} +2 -2
- package/dist/{dist-Cy1WxgBD.js → dist-Bf7SHuNp.js} +5 -5
- package/dist/{dist-Bz_sYWbr.js → dist-Bk75fBZA.js} +2 -2
- package/dist/dist-BlSvQzNr.js +5 -0
- package/dist/{dist-C5VC_yzu.js → dist-BzEzfugY.js} +1 -1
- package/dist/dist-CCBlxAgS.js +8 -0
- package/dist/dist-CIDTVIUf.js +5 -0
- package/dist/{dist-CLUtPrdy.js → dist-CIYBwstr.js} +1 -1
- package/dist/{dist-BotSqB48.js → dist-C_Y3oV3C.js} +12 -12
- package/dist/{dist-BTfv03uy.js → dist-CcWX6tmx.js} +2 -2
- package/dist/{dist-BhM8gdSO.js → dist-CoXAujgg.js} +4 -4
- package/dist/{dist-4j4c7bjm.js → dist-CpxNdDkw.js} +3 -3
- package/dist/dist-CqQyhAM8.js +8 -0
- package/dist/dist-CwRu2Xzh.js +5 -0
- package/dist/{dist-BcuoonNH.js → dist-CxJDU6Bh.js} +9 -9
- package/dist/{dist-DxvORzUR.js → dist-D-W5ny5a.js} +8 -8
- package/dist/dist-D8CDTVgf.js +6 -0
- package/dist/dist-D8DNB0nO.js +8 -0
- package/dist/dist-DL6N_q-A.js +5 -0
- package/dist/{dist-BbbIBDiQ.js → dist-DMjWuVs8.js} +1 -1
- package/dist/dist-DOFbNV_b.js +8 -0
- package/dist/dist-DPrYzMY0.js +6 -0
- package/dist/{dist-h2c8sZvT.js → dist-DZORgqKY.js} +1 -1
- package/dist/{dist-B3P2fFpz.js → dist-DZo4nSS0.js} +14 -14
- package/dist/{dist-D4CewLk6.js → dist-Dax--nl9.js} +1 -1
- package/dist/{dist-DRfcqpxJ.js → dist-DgGbNavJ.js} +2 -2
- package/dist/{dist-C1BYNeCR.js → dist-Dk6PV_d3.js} +10 -10
- package/dist/{dist-fQ0ViXGs.js → dist-Dv_Y15yk.js} +107 -107
- package/dist/{dist-Bfwsv11D.js → dist-DyyjKEYf.js} +2 -2
- package/dist/{dist-p2qyWijU.js → dist-GZXUmt0b.js} +2 -2
- package/dist/{dist-CLJWPTX2.js → dist-LTU8Hdvn.js} +3 -3
- package/dist/{dist-DqAWR3CS.js → dist-M9Vag9Y0.js} +20 -20
- package/dist/{dist-DNdhYsgW.js → dist-U4F-tbMs.js} +79 -62
- package/dist/{dist-RqXTaiir.js → dist-abid3KgM.js} +11 -11
- package/dist/dist-cdmMjgsn.js +5 -0
- package/dist/dist-hT4QzYX-.js +1247 -0
- package/dist/{dist-luvabDEB.js → dist-t9Kf7xqC.js} +2 -2
- package/dist/{error-banner-5bz0L9hS.js → error-banner-CJXYJ6Sb.js} +11 -6
- package/dist/esm-BaH2eg5-.js +1171 -0
- package/dist/{esm-Duie8iU-.js → esm-ga2Bf3O2.js} +43 -43
- package/dist/{extends-CkydH1Q5.js → extends-D_hDsj6R.js} +4 -4
- package/dist/files/wasm-intro.py +11 -8
- package/dist/{formats-DHxc-FdY.js → formats-C4wO47tk.js} +1 -1
- package/dist/{glide-data-editor-CgIxTzAP.js → glide-data-editor-BPkCPs7L.js} +255 -255
- package/dist/{html-to-image-B93KtAVY.js → html-to-image-BwfcJJxA.js} +2412 -2282
- package/dist/{input-_2sjvfne.js → input-OdWHkobi.js} +263 -245
- package/dist/{label-LWtdw5i8.js → label-CC4ytI1X.js} +1 -1
- package/dist/main.js +7630 -7558
- package/dist/{mermaid-4DMBBIKO-DIdL224_.js → mermaid-4DMBBIKO-Eg3D4FVz.js} +1 -1
- package/dist/{mermaid-lXOw5Py9.js → mermaid-BotvIKg9.js} +4 -4
- package/dist/{process-output-BOXi9fnS.js → process-output-DsloEDna.js} +3 -3
- package/dist/{reveal-component-gRcjQbNL.js → reveal-component-3YQBHWuD.js} +698 -620
- package/dist/{spec-B96zNUEA.js → spec-X7FwLJni.js} +4 -4
- package/dist/{strings-Bu3vlb6W.js → strings-J57tzLr3.js} +47 -46
- package/dist/style.css +1 -1
- package/dist/{toDate-x-WRDCH7.js → toDate-d8RCRrRd.js} +2 -2
- package/dist/{tooltip-C5FYOpQc.js → tooltip-DpcyNkQ2.js} +2 -2
- package/dist/{types-CVvp1fKr.js → types-ChtMFmZ2.js} +1 -1
- package/dist/{useAsyncData-iRgKDT5s.js → useAsyncData-PonK__yh.js} +1 -1
- package/dist/{useDateFormatter-BA4FCquG.js → useDateFormatter-QB-3MpYr.js} +2 -2
- package/dist/{useDeepCompareMemoize-CkQ57VS2.js → useDeepCompareMemoize-D3NGWke6.js} +1 -1
- package/dist/{useLifecycle-BBO9PIph.js → useLifecycle-00mO3OSS.js} +2 -2
- package/dist/{useTheme-DHIrRQOe.js → useTheme-DEhDzATN.js} +1 -1
- package/dist/{vega-component-Dq-SH463.js → vega-component-DGPUhbDs.js} +8 -8
- package/dist/{zod-CoBiJ5v4.js → zod-aLSua2NL.js} +24 -23
- package/package.json +4 -3
- package/src/__tests__/setup.ts +16 -0
- package/src/components/chat/chat-display.tsx +2 -2
- package/src/components/data-table/TableBottomBar.tsx +1 -15
- package/src/components/data-table/TableTopBar.tsx +8 -13
- package/src/components/data-table/__tests__/TableBottomBar.test.tsx +6 -12
- package/src/components/data-table/__tests__/column-visibility-dropdown.test.tsx +227 -0
- package/src/components/data-table/column-visibility-dropdown.tsx +204 -0
- package/src/components/data-table/data-table.tsx +1 -1
- package/src/components/data-table/filter-by-values-picker.tsx +39 -17
- package/src/components/data-table/filter-pills.tsx +1 -1
- package/src/components/datasources/__tests__/filter-empty.test.ts +183 -0
- package/src/components/datasources/datasources.tsx +92 -3
- package/src/components/editor/cell/code/cell-editor.tsx +70 -32
- package/src/components/editor/cell/code/code-placeholder.css +18 -0
- package/src/components/editor/cell/code/code-placeholder.tsx +47 -0
- package/src/components/editor/cell/code/language-toggle.tsx +7 -1
- package/src/components/editor/chrome/wrapper/app-chrome.tsx +97 -52
- package/src/components/editor/chrome/wrapper/lazy-panels.ts +91 -0
- package/src/components/editor/chrome/wrapper/sidebar.tsx +2 -0
- package/src/components/editor/connections/storage/__tests__/__snapshots__/as-code.test.ts.snap +9 -2
- package/src/components/editor/connections/storage/__tests__/as-code.test.ts +62 -27
- package/src/components/editor/connections/storage/add-storage-form.tsx +5 -1
- package/src/components/editor/connections/storage/as-code.ts +20 -6
- package/src/components/editor/documentation.css +35 -0
- package/src/components/editor/file-tree/file-explorer.tsx +8 -18
- package/src/components/editor/file-tree/tree-actions.tsx +46 -1
- package/src/components/editor/notebook-cell.tsx +3 -3
- package/src/components/editor/renderers/slides-layout/__tests__/plugin.test.ts +20 -0
- package/src/components/editor/renderers/slides-layout/types.ts +1 -0
- package/src/components/markdown/__tests__/markdown-renderer.test.tsx +43 -0
- package/src/components/markdown/markdown-renderer.tsx +24 -1
- package/src/components/slides/__tests__/minimap-actions.test.tsx +166 -0
- package/src/components/slides/__tests__/reveal-component.test.ts +425 -0
- package/src/components/slides/minimap.tsx +127 -10
- package/src/components/slides/reveal-component.tsx +287 -61
- package/src/components/slides/slide-cell-view.tsx +26 -2
- package/src/components/slides/slide-form.tsx +26 -4
- package/src/components/storage/__tests__/storage-inspector.test.ts +180 -0
- package/src/components/storage/storage-inspector.tsx +535 -81
- package/src/components/ui/combobox.tsx +51 -32
- package/src/components/ui/number-field.tsx +5 -1
- package/src/components/ui/reorderable-list.tsx +13 -0
- package/src/components/ui/select-core/__tests__/use-select-list.test.ts +294 -0
- package/src/components/ui/select-core/__tests__/utils.test.ts +222 -0
- package/src/components/ui/select-core/index.ts +16 -0
- package/src/components/ui/select-core/option-row.tsx +33 -0
- package/src/components/ui/select-core/render-slot.ts +20 -0
- package/src/components/ui/select-core/select-list.tsx +248 -0
- package/src/components/ui/select-core/types.ts +44 -0
- package/src/components/ui/select-core/use-select-list.ts +347 -0
- package/src/components/ui/select-core/utils.ts +121 -0
- package/src/components/ui/toast.tsx +1 -0
- package/src/core/cells/__tests__/document-changes.test.ts +2 -2
- package/src/core/cells/__tests__/focus.test.ts +45 -2
- package/src/core/cells/focus.ts +1 -1
- package/src/core/cells/scrollCellIntoView.ts +4 -0
- package/src/core/cells/utils.ts +1 -1
- package/src/core/codemirror/__tests__/editor-mount-scheduler.test.ts +143 -0
- package/src/core/codemirror/copilot/getCodes.ts +3 -1
- package/src/core/codemirror/editor-mount-scheduler.ts +101 -0
- package/src/core/codemirror/language/languages/python.ts +2 -0
- package/src/core/codemirror/language/languages/sql/utils.ts +3 -1
- package/src/core/codemirror/lsp/__tests__/markdown-renderer.test.ts +41 -0
- package/src/core/codemirror/lsp/markdown-renderer.ts +59 -0
- package/src/core/datasets/data-source-connections.ts +2 -0
- package/src/core/errors/errors.ts +1 -1
- package/src/core/storage/__tests__/state.test.ts +49 -0
- package/src/core/storage/__tests__/useStorageEntries.test.tsx +199 -3
- package/src/core/storage/state.ts +124 -13
- package/src/core/storage/types.ts +6 -0
- package/src/core/wasm/worker/bootstrap.ts +12 -4
- package/src/plugins/core/__test__/registerReactComponent.test.ts +96 -0
- package/src/plugins/core/registerReactComponent.tsx +42 -10
- package/src/plugins/impl/MultiselectPlugin.tsx +19 -142
- package/src/plugins/impl/SearchableSelect.tsx +16 -97
- package/src/plugins/impl/SliderPlugin.tsx +132 -18
- package/src/plugins/impl/__tests__/DropdownPlugin.test.tsx +5 -2
- package/src/plugins/impl/__tests__/MultiSelectPlugin.test.ts +1 -1
- package/src/plugins/impl/__tests__/SliderPlugin.test.tsx +278 -8
- package/src/utils/__tests__/numbers.test.ts +20 -0
- package/src/utils/errors.ts +9 -0
- package/src/utils/lazy.ts +6 -1
- package/src/utils/numbers.ts +27 -0
- package/src/utils/schedule-task.ts +71 -0
- package/dist/assets/__vite-browser-external-Ci2ZQfXU.js +0 -1
- package/dist/assets/worker-ip3AI_sN.js +0 -73
- package/dist/dist-0Fif7jnk.js +0 -5
- package/dist/dist-B5h_9sHB.js +0 -6
- package/dist/dist-B9M6R5ye.js +0 -5
- package/dist/dist-BCt3tnck.js +0 -8
- package/dist/dist-BUIJwMwn.js +0 -8
- package/dist/dist-BpquMd3k.js +0 -5
- package/dist/dist-BzJsqYfz.js +0 -5
- package/dist/dist-CA5ELXAf.js +0 -6
- package/dist/dist-CLBRs6Uv.js +0 -5
- package/dist/dist-CStVCMbq.js +0 -5
- package/dist/dist-CZRIEY3Y.js +0 -8
- package/dist/dist-CuUHbFD0.js +0 -5
- package/dist/dist-DV7Iabxb.js +0 -8
- package/dist/dist-DhHh0jLg.js +0 -1247
- package/dist/dist-DuEeHMvL.js +0 -5
- package/dist/esm-CCuYCd3R.js +0 -1171
- package/src/plugins/impl/multiselectFilterFn.tsx +0 -22
- /package/src/components/{data-table → ui}/value-chips.tsx +0 -0
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import { useMemo, useState } from "react";
|
|
3
|
+
import { assertNever } from "@/utils/assertNever";
|
|
4
|
+
import type { BulkAction, Option } from "./types";
|
|
5
|
+
import {
|
|
6
|
+
deselectMatching,
|
|
7
|
+
getBulkActions,
|
|
8
|
+
getVisibleOptions,
|
|
9
|
+
multiselectFilterFn,
|
|
10
|
+
selectMatching,
|
|
11
|
+
} from "./utils";
|
|
12
|
+
|
|
13
|
+
/** cmdk-style relevance score for `(label, query)`; any positive score matches. */
|
|
14
|
+
type FilterFn = (label: string, query: string) => number;
|
|
15
|
+
|
|
16
|
+
interface UseSelectListParams<V> {
|
|
17
|
+
options: Array<Option<V>>;
|
|
18
|
+
/** Current selection: an array when `multiple`, otherwise a single value or null. */
|
|
19
|
+
value: V[] | V | null;
|
|
20
|
+
onChange: (next: V[] | V | null) => void;
|
|
21
|
+
/** Multi-select when true; single-select (replace-on-pick) when false. */
|
|
22
|
+
multiple: boolean;
|
|
23
|
+
/** Cap on multi-select size. At the cap, picking another drops the oldest. */
|
|
24
|
+
maxSelections?: number;
|
|
25
|
+
/** Single-select only: re-picking the current value clears it to null. */
|
|
26
|
+
allowSelectNone?: boolean;
|
|
27
|
+
/** Match predicate over `(label, query)`; defaults to the strict word match. */
|
|
28
|
+
filterFn?: FilterFn;
|
|
29
|
+
/** Float the (frozen) selection to the top of the idle menu. */
|
|
30
|
+
pinSelected?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface UseSelectListResult<V> {
|
|
34
|
+
searchQuery: string;
|
|
35
|
+
setSearchQuery: (query: string) => void;
|
|
36
|
+
open: boolean;
|
|
37
|
+
setOpen: (open: boolean) => void;
|
|
38
|
+
/** Filtered, and (when `pinSelected` and idle) selected-first ordered. */
|
|
39
|
+
visibleOptions: Array<Option<V>>;
|
|
40
|
+
/** Count of pinned options at the head of `visibleOptions` (0 unless pinned + idle). */
|
|
41
|
+
pinnedCount: number;
|
|
42
|
+
isChecked: (value: V) => boolean;
|
|
43
|
+
toggle: (value: V) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Renderable bulk rows for the current search/cap state, in display order.
|
|
46
|
+
* Empty for single-select. Each entry carries its data (`enabled` or `items`)
|
|
47
|
+
* and a `run` closure that applies it.
|
|
48
|
+
*/
|
|
49
|
+
bulkActions: Array<BulkAction<V>>;
|
|
50
|
+
/** Map a value back to its option label; falls back to `String(value)`. */
|
|
51
|
+
labelOf: (value: V) => string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function asArray<V>(value: V[] | V | null): V[] {
|
|
55
|
+
if (value == null) {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
return Array.isArray(value) ? value : [value];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface SearchParams<V> {
|
|
62
|
+
options: Array<Option<V>>;
|
|
63
|
+
filterFn: FilterFn;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Search query and the options that currently match it. */
|
|
67
|
+
function useSearch<V>({ options, filterFn }: SearchParams<V>): {
|
|
68
|
+
searchQuery: string;
|
|
69
|
+
setSearchQuery: (query: string) => void;
|
|
70
|
+
filteredOptions: Array<Option<V>>;
|
|
71
|
+
} {
|
|
72
|
+
const [searchQuery, setSearchQuery] = useState("");
|
|
73
|
+
const filteredOptions = useMemo(() => {
|
|
74
|
+
if (!searchQuery) {
|
|
75
|
+
return options;
|
|
76
|
+
}
|
|
77
|
+
return options.filter((o) => filterFn(o.label, searchQuery) > 0);
|
|
78
|
+
}, [options, searchQuery, filterFn]);
|
|
79
|
+
return { searchQuery, setSearchQuery, filteredOptions };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface PinningParams<V> {
|
|
83
|
+
value: V[] | V | null;
|
|
84
|
+
pinSelected: boolean;
|
|
85
|
+
options: Array<Option<V>>;
|
|
86
|
+
searchQuery: string;
|
|
87
|
+
filteredOptions: Array<Option<V>>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Open state plus the frozen selection snapshot that orders the idle menu. The
|
|
92
|
+
* snapshot is retaken (`repin`) when the menu opens or the search clears, so a row
|
|
93
|
+
* toggled mid-session keeps its place instead of jumping to the top under the cursor.
|
|
94
|
+
*/
|
|
95
|
+
function usePinning<V>({
|
|
96
|
+
value,
|
|
97
|
+
pinSelected,
|
|
98
|
+
options,
|
|
99
|
+
searchQuery,
|
|
100
|
+
filteredOptions,
|
|
101
|
+
}: PinningParams<V>): {
|
|
102
|
+
open: boolean;
|
|
103
|
+
setOpen: (open: boolean) => void;
|
|
104
|
+
repin: () => void;
|
|
105
|
+
visibleOptions: Array<Option<V>>;
|
|
106
|
+
pinnedCount: number;
|
|
107
|
+
} {
|
|
108
|
+
const [open, setOpenState] = useState(false);
|
|
109
|
+
const [pinnedSelection, setPinnedSelection] = useState<Set<V>>(
|
|
110
|
+
() => new Set(asArray(value)),
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const repin = (): void => setPinnedSelection(new Set(asArray(value)));
|
|
114
|
+
|
|
115
|
+
const setOpen = (nextOpen: boolean): void => {
|
|
116
|
+
setOpenState(nextOpen);
|
|
117
|
+
if (nextOpen) {
|
|
118
|
+
repin();
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const { visibleOptions, pinnedCount } = useMemo(() => {
|
|
123
|
+
if (searchQuery || !pinSelected) {
|
|
124
|
+
return { visibleOptions: filteredOptions, pinnedCount: 0 };
|
|
125
|
+
}
|
|
126
|
+
return getVisibleOptions(options, pinnedSelection);
|
|
127
|
+
}, [searchQuery, pinSelected, filteredOptions, options, pinnedSelection]);
|
|
128
|
+
|
|
129
|
+
return { open, setOpen, repin, visibleOptions, pinnedCount };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface ToggleParams<V> {
|
|
133
|
+
value: V[] | V | null;
|
|
134
|
+
onChange: (next: V[] | V | null) => void;
|
|
135
|
+
multiple: boolean;
|
|
136
|
+
maxSelections: number | undefined;
|
|
137
|
+
allowSelectNone: boolean | undefined;
|
|
138
|
+
selected: ReadonlySet<V>;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Membership test and the cap/cardinality-aware single-item toggle. */
|
|
142
|
+
function useToggle<V>({
|
|
143
|
+
value,
|
|
144
|
+
onChange,
|
|
145
|
+
multiple,
|
|
146
|
+
maxSelections,
|
|
147
|
+
allowSelectNone,
|
|
148
|
+
selected,
|
|
149
|
+
}: ToggleParams<V>): {
|
|
150
|
+
isChecked: (value: V) => boolean;
|
|
151
|
+
toggle: (value: V) => void;
|
|
152
|
+
} {
|
|
153
|
+
const isChecked = (candidate: V): boolean => selected.has(candidate);
|
|
154
|
+
|
|
155
|
+
const toggle = (candidate: V): void => {
|
|
156
|
+
if (!multiple) {
|
|
157
|
+
if (allowSelectNone && value === candidate) {
|
|
158
|
+
onChange(null);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
onChange(candidate);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const current = asArray(value);
|
|
166
|
+
if (selected.has(candidate)) {
|
|
167
|
+
onChange(current.filter((v) => v !== candidate));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
let next = [...current, candidate];
|
|
172
|
+
if (maxSelections != null && next.length > maxSelections) {
|
|
173
|
+
next = next.slice(-maxSelections);
|
|
174
|
+
}
|
|
175
|
+
onChange(next);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
return { isChecked, toggle };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
interface BulkParams<V> {
|
|
182
|
+
value: V[] | V | null;
|
|
183
|
+
onChange: (next: V[] | V | null) => void;
|
|
184
|
+
multiple: boolean;
|
|
185
|
+
options: Array<Option<V>>;
|
|
186
|
+
filteredOptions: Array<Option<V>>;
|
|
187
|
+
searchQuery: string;
|
|
188
|
+
maxSelections: number | undefined;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Bulk-row specs paired with run closures; inert for single-select. */
|
|
192
|
+
function useBulk<V>({
|
|
193
|
+
value,
|
|
194
|
+
onChange,
|
|
195
|
+
multiple,
|
|
196
|
+
options,
|
|
197
|
+
filteredOptions,
|
|
198
|
+
searchQuery,
|
|
199
|
+
maxSelections,
|
|
200
|
+
}: BulkParams<V>): { bulkActions: Array<BulkAction<V>> } {
|
|
201
|
+
const bulkActions = useMemo<Array<BulkAction<V>>>(() => {
|
|
202
|
+
if (!multiple) {
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
const specs = getBulkActions({
|
|
206
|
+
options,
|
|
207
|
+
filteredOptions,
|
|
208
|
+
value: asArray(value),
|
|
209
|
+
searchQuery,
|
|
210
|
+
maxSelections,
|
|
211
|
+
});
|
|
212
|
+
return specs.map((spec): BulkAction<V> => {
|
|
213
|
+
switch (spec.kind) {
|
|
214
|
+
case "select-all":
|
|
215
|
+
return {
|
|
216
|
+
...spec,
|
|
217
|
+
run: () =>
|
|
218
|
+
onChange(
|
|
219
|
+
selectMatching(
|
|
220
|
+
asArray(value),
|
|
221
|
+
options.filter((o) => !o.disabled).map((o) => o.value),
|
|
222
|
+
),
|
|
223
|
+
),
|
|
224
|
+
};
|
|
225
|
+
case "deselect-all":
|
|
226
|
+
return { ...spec, run: () => onChange([]) };
|
|
227
|
+
case "select-matching":
|
|
228
|
+
return {
|
|
229
|
+
...spec,
|
|
230
|
+
run: () =>
|
|
231
|
+
onChange(
|
|
232
|
+
selectMatching(
|
|
233
|
+
asArray(value),
|
|
234
|
+
spec.items.map((o) => o.value),
|
|
235
|
+
),
|
|
236
|
+
),
|
|
237
|
+
};
|
|
238
|
+
case "deselect-matching":
|
|
239
|
+
return {
|
|
240
|
+
...spec,
|
|
241
|
+
run: () =>
|
|
242
|
+
onChange(
|
|
243
|
+
deselectMatching(
|
|
244
|
+
asArray(value),
|
|
245
|
+
spec.items.map((o) => o.value),
|
|
246
|
+
),
|
|
247
|
+
),
|
|
248
|
+
};
|
|
249
|
+
default:
|
|
250
|
+
return assertNever(spec);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}, [
|
|
254
|
+
multiple,
|
|
255
|
+
options,
|
|
256
|
+
filteredOptions,
|
|
257
|
+
value,
|
|
258
|
+
searchQuery,
|
|
259
|
+
maxSelections,
|
|
260
|
+
onChange,
|
|
261
|
+
]);
|
|
262
|
+
|
|
263
|
+
return { bulkActions };
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Headless state for a searchable select list, shared across the multiselect,
|
|
268
|
+
* dropdown, and top-K filter facades. Composes four focused concerns — search,
|
|
269
|
+
* pinning/freeze, membership/toggle, and bulk actions — behind one entry point.
|
|
270
|
+
* Pinning and bulk rows are opt-in so the single-select and top-K facades share
|
|
271
|
+
* only what they need.
|
|
272
|
+
*/
|
|
273
|
+
export function useSelectList<V>({
|
|
274
|
+
options,
|
|
275
|
+
value,
|
|
276
|
+
onChange,
|
|
277
|
+
multiple,
|
|
278
|
+
maxSelections,
|
|
279
|
+
allowSelectNone,
|
|
280
|
+
filterFn = multiselectFilterFn,
|
|
281
|
+
pinSelected = false,
|
|
282
|
+
}: UseSelectListParams<V>): UseSelectListResult<V> {
|
|
283
|
+
const selected = useMemo(() => new Set(asArray(value)), [value]);
|
|
284
|
+
|
|
285
|
+
const labelByValue = useMemo(() => {
|
|
286
|
+
const map = new Map<V, string>();
|
|
287
|
+
for (const option of options) {
|
|
288
|
+
map.set(option.value, option.label);
|
|
289
|
+
}
|
|
290
|
+
return map;
|
|
291
|
+
}, [options]);
|
|
292
|
+
const labelOf = (candidate: V): string =>
|
|
293
|
+
labelByValue.get(candidate) ?? String(candidate);
|
|
294
|
+
|
|
295
|
+
const {
|
|
296
|
+
searchQuery,
|
|
297
|
+
setSearchQuery: setSearchQueryState,
|
|
298
|
+
filteredOptions,
|
|
299
|
+
} = useSearch({ options, filterFn });
|
|
300
|
+
|
|
301
|
+
const { open, setOpen, repin, visibleOptions, pinnedCount } = usePinning({
|
|
302
|
+
value,
|
|
303
|
+
pinSelected,
|
|
304
|
+
options,
|
|
305
|
+
searchQuery,
|
|
306
|
+
filteredOptions,
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
const { isChecked, toggle } = useToggle({
|
|
310
|
+
value,
|
|
311
|
+
onChange,
|
|
312
|
+
multiple,
|
|
313
|
+
maxSelections,
|
|
314
|
+
allowSelectNone,
|
|
315
|
+
selected,
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
const { bulkActions } = useBulk({
|
|
319
|
+
value,
|
|
320
|
+
onChange,
|
|
321
|
+
multiple,
|
|
322
|
+
options,
|
|
323
|
+
filteredOptions,
|
|
324
|
+
searchQuery,
|
|
325
|
+
maxSelections,
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
const setSearchQuery = (query: string): void => {
|
|
329
|
+
setSearchQueryState(query);
|
|
330
|
+
if (query === "") {
|
|
331
|
+
repin();
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
return {
|
|
336
|
+
searchQuery,
|
|
337
|
+
setSearchQuery,
|
|
338
|
+
open,
|
|
339
|
+
setOpen,
|
|
340
|
+
visibleOptions,
|
|
341
|
+
pinnedCount,
|
|
342
|
+
isChecked,
|
|
343
|
+
toggle,
|
|
344
|
+
bulkActions,
|
|
345
|
+
labelOf,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import type { BulkActionSpec, Option } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Override cmdk's relevance-sorting filter with a stricter membership test: an
|
|
6
|
+
* option matches only when every whitespace-separated query word appears in it
|
|
7
|
+
* (case-insensitive), in any order. More lenient than exact match, stricter than
|
|
8
|
+
* fuzzy.
|
|
9
|
+
*
|
|
10
|
+
* Examples:
|
|
11
|
+
* - "foo bar" matches "foo bar"
|
|
12
|
+
* - "bar foo" matches "foo bar"
|
|
13
|
+
* - "foob" does not match "foo bar"
|
|
14
|
+
*/
|
|
15
|
+
export function multiselectFilterFn(option: string, value: string): number {
|
|
16
|
+
const words = value.split(/\s+/);
|
|
17
|
+
const match = words.every((word) =>
|
|
18
|
+
option.toLowerCase().includes(word.toLowerCase()),
|
|
19
|
+
);
|
|
20
|
+
return match ? 1 : 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Union: append the not-yet-selected members of `toAdd`, preserving order. */
|
|
24
|
+
export function selectMatching<V>(selected: V[], toAdd: V[]): V[] {
|
|
25
|
+
const set = new Set(selected);
|
|
26
|
+
return [...set, ...toAdd.filter((v) => !set.has(v))];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Difference: drop every member of `toRemove` from `selected`. */
|
|
30
|
+
export function deselectMatching<V>(selected: V[], toRemove: V[]): V[] {
|
|
31
|
+
const set = new Set(toRemove);
|
|
32
|
+
return selected.filter((v) => !set.has(v));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Order options for the idle (no active search) menu: pinned selections first in
|
|
37
|
+
* pin insertion order (so a freshly added selection appears after earlier ones),
|
|
38
|
+
* then everything else in option order. `pinnedSelection` is a frozen snapshot
|
|
39
|
+
* taken when the menu opens, so toggling an item does not reorder the list under
|
|
40
|
+
* the cursor. Returns the count of pinned options alongside the list so callers
|
|
41
|
+
* don't have to re-scan to find where the pinned block ends.
|
|
42
|
+
*/
|
|
43
|
+
export function getVisibleOptions<V>(
|
|
44
|
+
options: Array<Option<V>>,
|
|
45
|
+
pinnedSelection: ReadonlySet<V>,
|
|
46
|
+
): { visibleOptions: Array<Option<V>>; pinnedCount: number } {
|
|
47
|
+
const byValue = new Map(options.map((o) => [o.value, o] as const));
|
|
48
|
+
const pinned: Array<Option<V>> = [];
|
|
49
|
+
for (const value of pinnedSelection) {
|
|
50
|
+
const option = byValue.get(value);
|
|
51
|
+
if (option) {
|
|
52
|
+
pinned.push(option);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const rest = options.filter((o) => !pinnedSelection.has(o.value));
|
|
56
|
+
return { visibleOptions: [...pinned, ...rest], pinnedCount: pinned.length };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Decide which bulk rows the menu shows for the current search/cap state.
|
|
61
|
+
*
|
|
62
|
+
* When searching, the select-side spec carries the unselected matches and the
|
|
63
|
+
* deselect-side spec carries the selected matches (each omitted when empty).
|
|
64
|
+
* When idle, the spec is just `select-all` / `deselect-all` with an `enabled`
|
|
65
|
+
* flag for the disabled-but-visible state. `maxSelections` hides the select-
|
|
66
|
+
* side everywhere (a bulk select could exceed the cap); `maxSelections === 1`
|
|
67
|
+
* suppresses bulk rows entirely. Returns `[]` when bulk rows shouldn't show.
|
|
68
|
+
*
|
|
69
|
+
* Specs come in select-then-deselect order so the facade can render them as-is.
|
|
70
|
+
*/
|
|
71
|
+
export function getBulkActions<V>(params: {
|
|
72
|
+
options: Array<Option<V>>;
|
|
73
|
+
filteredOptions: Array<Option<V>>;
|
|
74
|
+
value: V[];
|
|
75
|
+
searchQuery: string;
|
|
76
|
+
maxSelections: number | undefined;
|
|
77
|
+
}): Array<BulkActionSpec<V>> {
|
|
78
|
+
const { options, filteredOptions, value, searchQuery, maxSelections } =
|
|
79
|
+
params;
|
|
80
|
+
|
|
81
|
+
if (options.length <= 2 || maxSelections === 1) {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const capped = maxSelections != null;
|
|
86
|
+
const specs: Array<BulkActionSpec<V>> = [];
|
|
87
|
+
|
|
88
|
+
if (searchQuery !== "") {
|
|
89
|
+
if (filteredOptions.length === 0) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
const selected = new Set(value);
|
|
93
|
+
const selectedMatches: Array<Option<V>> = [];
|
|
94
|
+
const unselectedMatches: Array<Option<V>> = [];
|
|
95
|
+
for (const option of filteredOptions) {
|
|
96
|
+
if (selected.has(option.value)) {
|
|
97
|
+
selectedMatches.push(option);
|
|
98
|
+
} else if (!option.disabled) {
|
|
99
|
+
// Disabled rows can't be picked individually, so bulk select skips them too.
|
|
100
|
+
unselectedMatches.push(option);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (!capped && unselectedMatches.length > 0) {
|
|
104
|
+
specs.push({ kind: "select-matching", items: unselectedMatches });
|
|
105
|
+
}
|
|
106
|
+
if (selectedMatches.length > 0) {
|
|
107
|
+
specs.push({ kind: "deselect-matching", items: selectedMatches });
|
|
108
|
+
}
|
|
109
|
+
return specs;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!capped) {
|
|
113
|
+
const selected = new Set(value);
|
|
114
|
+
specs.push({
|
|
115
|
+
kind: "select-all",
|
|
116
|
+
enabled: options.some((o) => !o.disabled && !selected.has(o.value)),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
specs.push({ kind: "deselect-all", enabled: value.length > 0 });
|
|
120
|
+
return specs;
|
|
121
|
+
}
|
|
@@ -17,6 +17,7 @@ const ToastViewport = React.forwardRef<
|
|
|
17
17
|
ref={ref}
|
|
18
18
|
className={cn(
|
|
19
19
|
"fixed top-0 z-100 flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:w-fit md:max-w-[420px]",
|
|
20
|
+
"print:hidden",
|
|
20
21
|
className,
|
|
21
22
|
)}
|
|
22
23
|
{...props}
|
|
@@ -430,7 +430,7 @@ describe("toDocumentChanges", () => {
|
|
|
430
430
|
const [a] = state.cellIds.inOrderIds;
|
|
431
431
|
|
|
432
432
|
// Position cursor at end of "line1" (position 5)
|
|
433
|
-
const view = state.cellHandles[a].current!.editorView
|
|
433
|
+
const view = state.cellHandles[a].current!.editorView!;
|
|
434
434
|
view.dispatch({ selection: { anchor: 5 } });
|
|
435
435
|
|
|
436
436
|
const { changes } = resolve(state, {
|
|
@@ -466,7 +466,7 @@ describe("toDocumentChanges", () => {
|
|
|
466
466
|
const [a] = state.cellIds.inOrderIds;
|
|
467
467
|
|
|
468
468
|
// Split the cell first
|
|
469
|
-
const view = state.cellHandles[a].current!.editorView
|
|
469
|
+
const view = state.cellHandles[a].current!.editorView!;
|
|
470
470
|
view.dispatch({ selection: { anchor: 5 } });
|
|
471
471
|
const snapshot = view.state.doc.toString();
|
|
472
472
|
state = dispatch(state, {
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
+
import type { EditorView } from "@codemirror/view";
|
|
4
|
+
import { createStore } from "jotai";
|
|
3
5
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
6
|
+
import { MockNotebook } from "@/__mocks__/notebook";
|
|
4
7
|
import { cellId } from "@/__tests__/branded";
|
|
8
|
+
import type { CellHandle } from "@/components/editor/notebook-cell";
|
|
9
|
+
import { notebookAtom } from "../cells";
|
|
5
10
|
import type { CellFocusState } from "../focus";
|
|
6
|
-
import { exportedForTesting } from "../focus";
|
|
11
|
+
import { exportedForTesting, lastFocusedCellAtom } from "../focus";
|
|
7
12
|
|
|
8
|
-
const { initialState, reducer, createActions } =
|
|
13
|
+
const { initialState, reducer, createActions, cellFocusAtom } =
|
|
14
|
+
exportedForTesting;
|
|
9
15
|
|
|
10
16
|
const CellIds = {
|
|
11
17
|
a: cellId("a"),
|
|
@@ -270,3 +276,40 @@ describe("cell focus reducer", () => {
|
|
|
270
276
|
});
|
|
271
277
|
});
|
|
272
278
|
});
|
|
279
|
+
|
|
280
|
+
describe("lastFocusedCellAtom", () => {
|
|
281
|
+
it("returns null getEditorView when CodeMirror is not mounted", () => {
|
|
282
|
+
const store = createStore();
|
|
283
|
+
const markdownCellId = cellId("markdown");
|
|
284
|
+
|
|
285
|
+
const unmountedEditorHandle: CellHandle = {
|
|
286
|
+
get editorView(): EditorView {
|
|
287
|
+
throw new ReferenceError("Attempting to dereference null object.");
|
|
288
|
+
},
|
|
289
|
+
editorViewOrNull: null,
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
const notebook = MockNotebook.notebookState({
|
|
293
|
+
cellData: {
|
|
294
|
+
[markdownCellId]: {
|
|
295
|
+
config: { hide_code: true },
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
notebook.cellHandles[markdownCellId] = {
|
|
300
|
+
current: unmountedEditorHandle,
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
store.set(notebookAtom, notebook);
|
|
304
|
+
store.set(cellFocusAtom, {
|
|
305
|
+
focusedCellId: markdownCellId,
|
|
306
|
+
lastFocusedCellId: markdownCellId,
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
const lastFocusedCell = store.get(lastFocusedCellAtom);
|
|
310
|
+
|
|
311
|
+
expect(lastFocusedCell).not.toBeNull();
|
|
312
|
+
expect(lastFocusedCell?.cellId).toBe(markdownCellId);
|
|
313
|
+
expect(lastFocusedCell?.getEditorView()).toBeNull();
|
|
314
|
+
});
|
|
315
|
+
});
|
package/src/core/cells/focus.ts
CHANGED
|
@@ -106,7 +106,7 @@ function cellFocusDetails(cellId: CellId, notebookState: NotebookState) {
|
|
|
106
106
|
if (!data || !handle) {
|
|
107
107
|
return null;
|
|
108
108
|
}
|
|
109
|
-
const getEditorView = () => handle.
|
|
109
|
+
const getEditorView = () => handle.editorViewOrNull;
|
|
110
110
|
|
|
111
111
|
return {
|
|
112
112
|
cellId,
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import type { CellHandle } from "@/components/editor/notebook-cell";
|
|
8
8
|
import { retryWithTimeout } from "@/utils/timeout";
|
|
9
9
|
import { Logger } from "../../utils/Logger";
|
|
10
|
+
import { editorMountScheduler } from "../codemirror/editor-mount-scheduler";
|
|
10
11
|
import { scrollActiveLineIntoView } from "../codemirror/extensions";
|
|
11
12
|
import { goToVariableDefinition } from "../codemirror/go-to-definition/commands";
|
|
12
13
|
import { getCellEditorView } from "./cells";
|
|
@@ -48,6 +49,9 @@ export function focusAndScrollCellIntoView({
|
|
|
48
49
|
// https://github.com/marimo-team/marimo/issues/2940
|
|
49
50
|
tryFocus(element);
|
|
50
51
|
} else {
|
|
52
|
+
// Build this cell's editor now if it is still queued, so focus can land in
|
|
53
|
+
// it instead of the placeholder.
|
|
54
|
+
editorMountScheduler.promote(cellId);
|
|
51
55
|
const editor = cell.current?.editorView;
|
|
52
56
|
if (!editor) {
|
|
53
57
|
Logger.warn("scrollCellIntoView: editor not found", cellId);
|
package/src/core/cells/utils.ts
CHANGED
|
@@ -29,7 +29,7 @@ export function notebookCells(state: NotebookState) {
|
|
|
29
29
|
export function notebookCellEditorViews({ cellHandles }: NotebookState) {
|
|
30
30
|
const views: Record<CellId, EditorView> = {};
|
|
31
31
|
for (const [cell, ref] of Objects.entries(cellHandles)) {
|
|
32
|
-
if (!ref.current) {
|
|
32
|
+
if (!ref.current?.editorView) {
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
35
35
|
views[cell] = ref.current.editorView;
|