@marimo-team/islands 0.23.10-dev25 → 0.23.10-dev27
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/{code-visibility-CXkMXcdB.js → code-visibility-DI2QSiFC.js} +1646 -1179
- package/dist/main.js +7312 -7424
- package/dist/{reveal-component-dIolR_34.js → reveal-component-BA7HaWOX.js} +410 -333
- package/package.json +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/editor/cell/code/language-toggle.tsx +7 -1
- 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/slides/__tests__/reveal-component.test.ts +425 -0
- package/src/components/slides/reveal-component.tsx +283 -61
- package/src/components/slides/slide-cell-view.tsx +26 -2
- package/src/components/slides/slide-form.tsx +26 -4
- package/src/components/ui/combobox.tsx +51 -32
- 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/plugins/impl/MultiselectPlugin.tsx +19 -142
- package/src/plugins/impl/SearchableSelect.tsx +16 -97
- package/src/plugins/impl/__tests__/DropdownPlugin.test.tsx +5 -2
- package/src/plugins/impl/__tests__/MultiSelectPlugin.test.ts +1 -1
- package/src/plugins/impl/multiselectFilterFn.tsx +0 -22
- /package/src/components/{data-table → ui}/value-chips.tsx +0 -0
package/package.json
CHANGED
|
@@ -7,6 +7,8 @@ import { useMemo, useState } from "react";
|
|
|
7
7
|
import { useAsyncData } from "@/hooks/useAsyncData";
|
|
8
8
|
import { ErrorBanner } from "@/plugins/impl/common/error-banner";
|
|
9
9
|
import type { CalculateTopKRows } from "@/plugins/impl/DataTablePlugin";
|
|
10
|
+
import type { Option } from "@/components/ui/select-core";
|
|
11
|
+
import { useSelectList } from "@/components/ui/select-core";
|
|
10
12
|
import { Logger } from "@/utils/Logger";
|
|
11
13
|
import { Sets } from "@/utils/sets";
|
|
12
14
|
import { smartMatch } from "@/utils/smartMatch";
|
|
@@ -23,7 +25,7 @@ import {
|
|
|
23
25
|
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
|
|
24
26
|
import { SentinelCell } from "./sentinel-cell";
|
|
25
27
|
import { detectSentinel, stringifyUnknownValue } from "./utils";
|
|
26
|
-
import { CompactChipRow } from "
|
|
28
|
+
import { CompactChipRow } from "@/components/ui/value-chips";
|
|
27
29
|
|
|
28
30
|
const TOP_K_ROWS = 30;
|
|
29
31
|
|
|
@@ -101,8 +103,6 @@ export const FilterByValuesList = <TData, TValue>({
|
|
|
101
103
|
onChange,
|
|
102
104
|
creatable = false,
|
|
103
105
|
}: FilterByValuesListProps<TData, TValue>) => {
|
|
104
|
-
const [query, setQuery] = useState<string>("");
|
|
105
|
-
|
|
106
106
|
const { data, isPending, error } = useAsyncData(async () => {
|
|
107
107
|
if (!calculateTopKRows) {
|
|
108
108
|
return null;
|
|
@@ -111,27 +111,49 @@ export const FilterByValuesList = <TData, TValue>({
|
|
|
111
111
|
return res.data;
|
|
112
112
|
}, [calculateTopKRows, column.id]);
|
|
113
113
|
|
|
114
|
-
const
|
|
114
|
+
const options = useMemo<Array<Option<unknown>>>(() => {
|
|
115
115
|
if (!data) {
|
|
116
116
|
return [];
|
|
117
117
|
}
|
|
118
118
|
try {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
smartMatch(query, str) ||
|
|
127
|
-
str.toLowerCase().includes(query.toLowerCase())
|
|
128
|
-
);
|
|
129
|
-
});
|
|
119
|
+
return data
|
|
120
|
+
.filter(([value]) => value !== undefined)
|
|
121
|
+
.map(([value, count]) => ({
|
|
122
|
+
value,
|
|
123
|
+
label: String(value),
|
|
124
|
+
data: { count },
|
|
125
|
+
}));
|
|
130
126
|
} catch (error_) {
|
|
131
|
-
Logger.error("Error
|
|
127
|
+
Logger.error("Error building filter options", error_);
|
|
132
128
|
return [];
|
|
133
129
|
}
|
|
134
|
-
}, [data
|
|
130
|
+
}, [data]);
|
|
131
|
+
|
|
132
|
+
const list = useSelectList<unknown>({
|
|
133
|
+
options,
|
|
134
|
+
value: [...chosenValues],
|
|
135
|
+
onChange: (next) => onChange(next as unknown[]),
|
|
136
|
+
multiple: true,
|
|
137
|
+
filterFn: (label, q) =>
|
|
138
|
+
smartMatch(q, label) || label.toLowerCase().includes(q.toLowerCase())
|
|
139
|
+
? 1
|
|
140
|
+
: 0,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const query = list.searchQuery;
|
|
144
|
+
const setQuery = list.setSearchQuery;
|
|
145
|
+
|
|
146
|
+
const filteredData = useMemo<Array<[unknown, number | undefined]>>(
|
|
147
|
+
() =>
|
|
148
|
+
list.visibleOptions.map(
|
|
149
|
+
(o) =>
|
|
150
|
+
[o.value, (o.data as { count: number }).count] as [
|
|
151
|
+
unknown,
|
|
152
|
+
number | undefined,
|
|
153
|
+
],
|
|
154
|
+
),
|
|
155
|
+
[list.visibleOptions],
|
|
156
|
+
);
|
|
135
157
|
|
|
136
158
|
// Surface chosen values that aren't in the top-K so they stay visible/uncheckable.
|
|
137
159
|
// Count is undefined for these rows; the cell renders an em-dash.
|
|
@@ -21,7 +21,7 @@ import { AddFilterButton } from "./add-filter-button";
|
|
|
21
21
|
import { FilterPillEditor } from "./filter-pill-editor";
|
|
22
22
|
import { type ColumnFilterValue, formatValue, type Snapshot } from "./filters";
|
|
23
23
|
import { extractTimezone } from "./types";
|
|
24
|
-
import { ChipWithComma, CompactChipRow } from "
|
|
24
|
+
import { ChipWithComma, CompactChipRow } from "@/components/ui/value-chips";
|
|
25
25
|
|
|
26
26
|
interface Props<TData> {
|
|
27
27
|
filters: ColumnFiltersState | undefined;
|
|
@@ -17,6 +17,11 @@ interface LanguageTogglesProps {
|
|
|
17
17
|
code: string;
|
|
18
18
|
currentLanguageAdapter: LanguageAdapter["type"] | undefined;
|
|
19
19
|
onAfterToggle: () => void;
|
|
20
|
+
/**
|
|
21
|
+
* Classes for the wrapper element. Defaults to the absolutely-positioned,
|
|
22
|
+
* hover-revealed placement used inside the notebook cell editor.
|
|
23
|
+
*/
|
|
24
|
+
className?: string;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
export const LanguageToggles: React.FC<LanguageTogglesProps> = ({
|
|
@@ -24,6 +29,7 @@ export const LanguageToggles: React.FC<LanguageTogglesProps> = ({
|
|
|
24
29
|
code,
|
|
25
30
|
currentLanguageAdapter,
|
|
26
31
|
onAfterToggle,
|
|
32
|
+
className = "absolute right-3 top-2 z-20 flex hover-action gap-1",
|
|
27
33
|
}) => {
|
|
28
34
|
const canUseMarkdown = useMemo(
|
|
29
35
|
() => LanguageAdapters.markdown.isSupported(code) || code.trim() === "",
|
|
@@ -35,7 +41,7 @@ export const LanguageToggles: React.FC<LanguageTogglesProps> = ({
|
|
|
35
41
|
);
|
|
36
42
|
|
|
37
43
|
return (
|
|
38
|
-
<div className=
|
|
44
|
+
<div className={className}>
|
|
39
45
|
<LanguageToggle
|
|
40
46
|
editorView={editorView}
|
|
41
47
|
currentLanguageAdapter={currentLanguageAdapter}
|
|
@@ -248,6 +248,26 @@ const BACKWARDS_COMPAT_SNAPSHOTS: BackwardsCompatCase[] = [
|
|
|
248
248
|
],
|
|
249
249
|
},
|
|
250
250
|
},
|
|
251
|
+
{
|
|
252
|
+
// `showCode` was added to SlideConfig. The validator must know about it (so
|
|
253
|
+
// it isn't silently stripped), the deserializer must carry it through, and
|
|
254
|
+
// serialize → deserialize must round-trip both values.
|
|
255
|
+
label: "showCode round-trips through validate + (de)serialize",
|
|
256
|
+
input: {
|
|
257
|
+
cells: [
|
|
258
|
+
{ type: "slide", showCode: true },
|
|
259
|
+
{ type: "fragment", showCode: false },
|
|
260
|
+
],
|
|
261
|
+
},
|
|
262
|
+
expected: {
|
|
263
|
+
deck: {},
|
|
264
|
+
cellIds: ["a", "b"],
|
|
265
|
+
cellEntries: [
|
|
266
|
+
["a", { type: "slide", showCode: true }],
|
|
267
|
+
["b", { type: "fragment", showCode: false }],
|
|
268
|
+
],
|
|
269
|
+
},
|
|
270
|
+
},
|
|
251
271
|
];
|
|
252
272
|
|
|
253
273
|
describe("SlidesLayoutPlugin backwards compatibility", () => {
|
|
@@ -9,6 +9,7 @@ export type SlideType = z.infer<typeof SlideTypeSchema>;
|
|
|
9
9
|
const SlideConfigSchema = z.looseObject({
|
|
10
10
|
type: SlideTypeSchema.optional(),
|
|
11
11
|
speakerNotes: z.string().optional(),
|
|
12
|
+
showCode: z.boolean().optional(),
|
|
12
13
|
});
|
|
13
14
|
export type SlideConfig = z.infer<typeof SlideConfigSchema>;
|
|
14
15
|
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { act, renderHook } from "@testing-library/react";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { cellId } from "@/__tests__/branded";
|
|
6
|
+
import type { CellId } from "@/core/cells/ids";
|
|
7
|
+
import type { RuntimeCell } from "@/core/cells/types";
|
|
8
|
+
import type { SlideConfig } from "../../editor/renderers/slides-layout/types";
|
|
9
|
+
import {
|
|
10
|
+
deckSlideType,
|
|
11
|
+
parkedRendersSource,
|
|
12
|
+
shouldShowCode,
|
|
13
|
+
useParkedPreview,
|
|
14
|
+
} from "../reveal-component";
|
|
15
|
+
|
|
16
|
+
const A = cellId("a");
|
|
17
|
+
const B = cellId("b");
|
|
18
|
+
|
|
19
|
+
const cells = (
|
|
20
|
+
...entries: Array<[CellId, SlideConfig]>
|
|
21
|
+
): ReadonlyMap<CellId, SlideConfig> => new Map(entries);
|
|
22
|
+
|
|
23
|
+
// The hook only reads `cell.id`, so a minimal stub is enough. Cast is confined
|
|
24
|
+
// to this test helper (see `@/__tests__/branded` for the same rationale).
|
|
25
|
+
const cell = (id: CellId): RuntimeCell => ({ id }) as RuntimeCell;
|
|
26
|
+
|
|
27
|
+
describe("shouldShowCode", () => {
|
|
28
|
+
it("is off when the code toggle is unavailable, regardless of config/override", () => {
|
|
29
|
+
expect(
|
|
30
|
+
shouldShowCode({
|
|
31
|
+
cells: cells([A, { showCode: true }]),
|
|
32
|
+
cellId: A,
|
|
33
|
+
showCodeOverrides: new Set([A]),
|
|
34
|
+
codeToggleEnabled: false,
|
|
35
|
+
}),
|
|
36
|
+
).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("is off when there is no active cell", () => {
|
|
40
|
+
expect(
|
|
41
|
+
shouldShowCode({
|
|
42
|
+
cells: cells([A, { showCode: true }]),
|
|
43
|
+
cellId: undefined,
|
|
44
|
+
showCodeOverrides: new Set(),
|
|
45
|
+
codeToggleEnabled: true,
|
|
46
|
+
}),
|
|
47
|
+
).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("follows the persisted config when there is no override", () => {
|
|
51
|
+
expect(
|
|
52
|
+
shouldShowCode({
|
|
53
|
+
cells: cells([A, { showCode: true }]),
|
|
54
|
+
cellId: A,
|
|
55
|
+
showCodeOverrides: new Set(),
|
|
56
|
+
codeToggleEnabled: true,
|
|
57
|
+
}),
|
|
58
|
+
).toBe(true);
|
|
59
|
+
// Missing config entry defaults to off.
|
|
60
|
+
expect(
|
|
61
|
+
shouldShowCode({
|
|
62
|
+
cells: cells(),
|
|
63
|
+
cellId: A,
|
|
64
|
+
showCodeOverrides: new Set(),
|
|
65
|
+
codeToggleEnabled: true,
|
|
66
|
+
}),
|
|
67
|
+
).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("shows code when either the config or the override is set (logical OR)", () => {
|
|
71
|
+
// Peek: config unset, override present -> shown.
|
|
72
|
+
expect(
|
|
73
|
+
shouldShowCode({
|
|
74
|
+
cells: cells(),
|
|
75
|
+
cellId: A,
|
|
76
|
+
showCodeOverrides: new Set([A]),
|
|
77
|
+
codeToggleEnabled: true,
|
|
78
|
+
}),
|
|
79
|
+
).toBe(true);
|
|
80
|
+
// Configured + override present -> still shown; the override never hides.
|
|
81
|
+
expect(
|
|
82
|
+
shouldShowCode({
|
|
83
|
+
cells: cells([A, { showCode: true }]),
|
|
84
|
+
cellId: A,
|
|
85
|
+
showCodeOverrides: new Set([A]),
|
|
86
|
+
codeToggleEnabled: true,
|
|
87
|
+
}),
|
|
88
|
+
).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("deckSlideType", () => {
|
|
93
|
+
const NONE_IDS: ReadonlySet<CellId> = new Set();
|
|
94
|
+
|
|
95
|
+
it("uses the configured type for a normal cell", () => {
|
|
96
|
+
expect(
|
|
97
|
+
deckSlideType({
|
|
98
|
+
cell: cell(A),
|
|
99
|
+
noOutputIds: NONE_IDS,
|
|
100
|
+
heldEditCellId: null,
|
|
101
|
+
slideConfigs: cells([A, { type: "fragment" }]),
|
|
102
|
+
}),
|
|
103
|
+
).toBe("fragment");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("defaults to a top-level slide when no type is configured", () => {
|
|
107
|
+
expect(
|
|
108
|
+
deckSlideType({
|
|
109
|
+
cell: cell(A),
|
|
110
|
+
noOutputIds: NONE_IDS,
|
|
111
|
+
heldEditCellId: null,
|
|
112
|
+
slideConfigs: cells(),
|
|
113
|
+
}),
|
|
114
|
+
).toBe("slide");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("drops output-less cells from the deck", () => {
|
|
118
|
+
expect(
|
|
119
|
+
deckSlideType({
|
|
120
|
+
cell: cell(A),
|
|
121
|
+
noOutputIds: new Set([A]),
|
|
122
|
+
heldEditCellId: null,
|
|
123
|
+
// Even an explicit type is overridden by the skip.
|
|
124
|
+
slideConfigs: cells([A, { type: "sub-slide" }]),
|
|
125
|
+
}),
|
|
126
|
+
).toBe("skip");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("drops the held-edit cell so it isn't mounted twice", () => {
|
|
130
|
+
expect(
|
|
131
|
+
deckSlideType({
|
|
132
|
+
cell: cell(A),
|
|
133
|
+
noOutputIds: NONE_IDS,
|
|
134
|
+
heldEditCellId: A,
|
|
135
|
+
slideConfigs: cells([A, { type: "slide" }]),
|
|
136
|
+
}),
|
|
137
|
+
).toBe("skip");
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe("parkedRendersSource", () => {
|
|
142
|
+
it("follows `showCode` for a cell that has output", () => {
|
|
143
|
+
expect(
|
|
144
|
+
parkedRendersSource({
|
|
145
|
+
isNoOutputPreview: false,
|
|
146
|
+
isEditable: false,
|
|
147
|
+
showCode: true,
|
|
148
|
+
}),
|
|
149
|
+
).toBe(true);
|
|
150
|
+
expect(
|
|
151
|
+
parkedRendersSource({
|
|
152
|
+
isNoOutputPreview: false,
|
|
153
|
+
isEditable: true,
|
|
154
|
+
showCode: false,
|
|
155
|
+
}),
|
|
156
|
+
).toBe(false);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("falls back to source for an editable no-output cell even when showCode is off", () => {
|
|
160
|
+
expect(
|
|
161
|
+
parkedRendersSource({
|
|
162
|
+
isNoOutputPreview: true,
|
|
163
|
+
isEditable: true,
|
|
164
|
+
showCode: false,
|
|
165
|
+
}),
|
|
166
|
+
).toBe(true);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("renders output for a read-only no-output cell with showCode off", () => {
|
|
170
|
+
expect(
|
|
171
|
+
parkedRendersSource({
|
|
172
|
+
isNoOutputPreview: true,
|
|
173
|
+
isEditable: false,
|
|
174
|
+
showCode: false,
|
|
175
|
+
}),
|
|
176
|
+
).toBe(false);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe("useParkedPreview", () => {
|
|
181
|
+
const NO_CONFIG = cells();
|
|
182
|
+
const NONE = new Set<CellId>();
|
|
183
|
+
|
|
184
|
+
it("is inert for a rendered cell with output", () => {
|
|
185
|
+
const { result } = renderHook(() =>
|
|
186
|
+
useParkedPreview({
|
|
187
|
+
activeCell: cell(A),
|
|
188
|
+
slideConfigs: NO_CONFIG,
|
|
189
|
+
noOutputIds: NONE,
|
|
190
|
+
}),
|
|
191
|
+
);
|
|
192
|
+
expect(result.current).toEqual({
|
|
193
|
+
parkedPreviewCell: null,
|
|
194
|
+
isHeldEdit: false,
|
|
195
|
+
isNoOutputPreview: false,
|
|
196
|
+
heldEditCellId: null,
|
|
197
|
+
heldShowsCode: true,
|
|
198
|
+
toggleHeldShowsCode: expect.any(Function),
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("is inert when there is no active cell", () => {
|
|
203
|
+
const { result } = renderHook(() =>
|
|
204
|
+
useParkedPreview({
|
|
205
|
+
activeCell: undefined,
|
|
206
|
+
slideConfigs: NO_CONFIG,
|
|
207
|
+
noOutputIds: NONE,
|
|
208
|
+
}),
|
|
209
|
+
);
|
|
210
|
+
expect(result.current).toEqual({
|
|
211
|
+
parkedPreviewCell: null,
|
|
212
|
+
isHeldEdit: false,
|
|
213
|
+
isNoOutputPreview: false,
|
|
214
|
+
heldEditCellId: null,
|
|
215
|
+
heldShowsCode: true,
|
|
216
|
+
toggleHeldShowsCode: expect.any(Function),
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("parks a skipped cell without flagging it as a no-output preview", () => {
|
|
221
|
+
const { result } = renderHook(() =>
|
|
222
|
+
useParkedPreview({
|
|
223
|
+
activeCell: cell(A),
|
|
224
|
+
slideConfigs: cells([A, { type: "skip" }]),
|
|
225
|
+
noOutputIds: NONE,
|
|
226
|
+
}),
|
|
227
|
+
);
|
|
228
|
+
expect(result.current).toEqual({
|
|
229
|
+
parkedPreviewCell: cell(A),
|
|
230
|
+
isHeldEdit: false,
|
|
231
|
+
isNoOutputPreview: false,
|
|
232
|
+
heldEditCellId: null,
|
|
233
|
+
heldShowsCode: true,
|
|
234
|
+
toggleHeldShowsCode: expect.any(Function),
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("parks an output-less cell as a no-output preview", () => {
|
|
239
|
+
const { result } = renderHook(() =>
|
|
240
|
+
useParkedPreview({
|
|
241
|
+
activeCell: cell(A),
|
|
242
|
+
slideConfigs: NO_CONFIG,
|
|
243
|
+
noOutputIds: new Set([A]),
|
|
244
|
+
}),
|
|
245
|
+
);
|
|
246
|
+
expect(result.current).toEqual({
|
|
247
|
+
parkedPreviewCell: cell(A),
|
|
248
|
+
isHeldEdit: false,
|
|
249
|
+
isNoOutputPreview: true,
|
|
250
|
+
heldEditCellId: null,
|
|
251
|
+
heldShowsCode: true,
|
|
252
|
+
toggleHeldShowsCode: expect.any(Function),
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("holds the cell in the overlay once it gains output", () => {
|
|
257
|
+
const { result, rerender } = renderHook(
|
|
258
|
+
(props: Parameters<typeof useParkedPreview>[0]) =>
|
|
259
|
+
useParkedPreview(props),
|
|
260
|
+
{
|
|
261
|
+
initialProps: {
|
|
262
|
+
activeCell: cell(A),
|
|
263
|
+
slideConfigs: NO_CONFIG,
|
|
264
|
+
noOutputIds: new Set([A]),
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
);
|
|
268
|
+
expect(result.current.isNoOutputPreview).toBe(true);
|
|
269
|
+
expect(result.current.isHeldEdit).toBe(false);
|
|
270
|
+
|
|
271
|
+
// Same cell, now with output: keep it parked so the editor isn't remounted.
|
|
272
|
+
rerender({
|
|
273
|
+
activeCell: cell(A),
|
|
274
|
+
slideConfigs: NO_CONFIG,
|
|
275
|
+
noOutputIds: NONE,
|
|
276
|
+
});
|
|
277
|
+
expect(result.current).toEqual({
|
|
278
|
+
parkedPreviewCell: cell(A),
|
|
279
|
+
isHeldEdit: true,
|
|
280
|
+
isNoOutputPreview: false,
|
|
281
|
+
heldEditCellId: A,
|
|
282
|
+
heldShowsCode: true,
|
|
283
|
+
toggleHeldShowsCode: expect.any(Function),
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("releases the hold when a different cell becomes active", () => {
|
|
288
|
+
const { result, rerender } = renderHook(
|
|
289
|
+
(props: Parameters<typeof useParkedPreview>[0]) =>
|
|
290
|
+
useParkedPreview(props),
|
|
291
|
+
{
|
|
292
|
+
initialProps: {
|
|
293
|
+
activeCell: cell(A),
|
|
294
|
+
slideConfigs: NO_CONFIG,
|
|
295
|
+
noOutputIds: new Set([A]),
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
);
|
|
299
|
+
// Arm the hold, then let A gain output (held).
|
|
300
|
+
rerender({
|
|
301
|
+
activeCell: cell(A),
|
|
302
|
+
slideConfigs: NO_CONFIG,
|
|
303
|
+
noOutputIds: NONE,
|
|
304
|
+
});
|
|
305
|
+
expect(result.current.isHeldEdit).toBe(true);
|
|
306
|
+
|
|
307
|
+
// Navigate to a rendered B: the hold on A is released.
|
|
308
|
+
rerender({
|
|
309
|
+
activeCell: cell(B),
|
|
310
|
+
slideConfigs: NO_CONFIG,
|
|
311
|
+
noOutputIds: NONE,
|
|
312
|
+
});
|
|
313
|
+
expect(result.current).toEqual({
|
|
314
|
+
parkedPreviewCell: null,
|
|
315
|
+
isHeldEdit: false,
|
|
316
|
+
isNoOutputPreview: false,
|
|
317
|
+
heldEditCellId: null,
|
|
318
|
+
heldShowsCode: true,
|
|
319
|
+
toggleHeldShowsCode: expect.any(Function),
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("releases a skipped cell into the deck as soon as it is un-skipped", () => {
|
|
324
|
+
const { result, rerender } = renderHook(
|
|
325
|
+
(props: Parameters<typeof useParkedPreview>[0]) =>
|
|
326
|
+
useParkedPreview(props),
|
|
327
|
+
{
|
|
328
|
+
initialProps: {
|
|
329
|
+
activeCell: cell(A),
|
|
330
|
+
slideConfigs: cells([A, { type: "skip" }]),
|
|
331
|
+
noOutputIds: NONE,
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
);
|
|
335
|
+
expect(result.current.parkedPreviewCell).toEqual(cell(A));
|
|
336
|
+
|
|
337
|
+
// Un-skip the still-active cell: it has output, so it must rejoin the deck
|
|
338
|
+
// immediately rather than staying held in the overlay until navigation.
|
|
339
|
+
rerender({
|
|
340
|
+
activeCell: cell(A),
|
|
341
|
+
slideConfigs: NO_CONFIG,
|
|
342
|
+
noOutputIds: NONE,
|
|
343
|
+
});
|
|
344
|
+
expect(result.current).toEqual({
|
|
345
|
+
parkedPreviewCell: null,
|
|
346
|
+
isHeldEdit: false,
|
|
347
|
+
isNoOutputPreview: false,
|
|
348
|
+
heldEditCellId: null,
|
|
349
|
+
heldShowsCode: true,
|
|
350
|
+
toggleHeldShowsCode: expect.any(Function),
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it("shows the held editor by default and toggles it off without navigating", () => {
|
|
355
|
+
const { result, rerender } = renderHook(
|
|
356
|
+
(props: Parameters<typeof useParkedPreview>[0]) =>
|
|
357
|
+
useParkedPreview(props),
|
|
358
|
+
{
|
|
359
|
+
initialProps: {
|
|
360
|
+
activeCell: cell(A),
|
|
361
|
+
slideConfigs: NO_CONFIG,
|
|
362
|
+
noOutputIds: new Set([A]),
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
);
|
|
366
|
+
// A gains output: held, with its editor shown by default.
|
|
367
|
+
rerender({
|
|
368
|
+
activeCell: cell(A),
|
|
369
|
+
slideConfigs: NO_CONFIG,
|
|
370
|
+
noOutputIds: NONE,
|
|
371
|
+
});
|
|
372
|
+
expect(result.current.isHeldEdit).toBe(true);
|
|
373
|
+
expect(result.current.heldShowsCode).toBe(true);
|
|
374
|
+
|
|
375
|
+
// The `C` toggle hides the editor in place, no navigation required.
|
|
376
|
+
act(() => {
|
|
377
|
+
result.current.toggleHeldShowsCode();
|
|
378
|
+
});
|
|
379
|
+
expect(result.current.heldShowsCode).toBe(false);
|
|
380
|
+
|
|
381
|
+
// Toggling again brings it back.
|
|
382
|
+
act(() => {
|
|
383
|
+
result.current.toggleHeldShowsCode();
|
|
384
|
+
});
|
|
385
|
+
expect(result.current.heldShowsCode).toBe(true);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it("resets held code visibility when a new cell takes the held slot", () => {
|
|
389
|
+
const { result, rerender } = renderHook(
|
|
390
|
+
(props: Parameters<typeof useParkedPreview>[0]) =>
|
|
391
|
+
useParkedPreview(props),
|
|
392
|
+
{
|
|
393
|
+
initialProps: {
|
|
394
|
+
activeCell: cell(A),
|
|
395
|
+
slideConfigs: NO_CONFIG,
|
|
396
|
+
noOutputIds: new Set([A]),
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
);
|
|
400
|
+
rerender({
|
|
401
|
+
activeCell: cell(A),
|
|
402
|
+
slideConfigs: NO_CONFIG,
|
|
403
|
+
noOutputIds: NONE,
|
|
404
|
+
});
|
|
405
|
+
act(() => {
|
|
406
|
+
result.current.toggleHeldShowsCode();
|
|
407
|
+
});
|
|
408
|
+
expect(result.current.heldShowsCode).toBe(false);
|
|
409
|
+
|
|
410
|
+
// Move to a fresh output-less cell B, then let it gain output (held).
|
|
411
|
+
rerender({
|
|
412
|
+
activeCell: cell(B),
|
|
413
|
+
slideConfigs: NO_CONFIG,
|
|
414
|
+
noOutputIds: new Set([B]),
|
|
415
|
+
});
|
|
416
|
+
rerender({
|
|
417
|
+
activeCell: cell(B),
|
|
418
|
+
slideConfigs: NO_CONFIG,
|
|
419
|
+
noOutputIds: NONE,
|
|
420
|
+
});
|
|
421
|
+
expect(result.current.heldEditCellId).toBe(B);
|
|
422
|
+
// The new cell starts with its editor visible again.
|
|
423
|
+
expect(result.current.heldShowsCode).toBe(true);
|
|
424
|
+
});
|
|
425
|
+
});
|