@marimo-team/islands 0.23.15-dev2 → 0.23.15-dev20
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/{chat-ui-DinOvbWu.js → chat-ui-FiwuOgQU.js} +3094 -3094
- package/dist/{code-visibility-B-sydhvS.js → code-visibility-DNwczZr1.js} +925 -842
- package/dist/{html-to-image-_wGfk8V-.js → html-to-image-JXL8cvmt.js} +2218 -2205
- package/dist/main.js +1066 -1073
- package/dist/{process-output-Mh4UrjwM.js → process-output-CnDIXtM-.js} +1 -1
- package/dist/{reveal-component-MK2nUbwt.js → reveal-component-Cb5uzhCh.js} +614 -602
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/chat/__tests__/chat-utils.test.ts +244 -1
- package/src/components/chat/__tests__/message-queue.test.tsx +121 -0
- package/src/components/chat/chat-panel.tsx +196 -67
- package/src/components/chat/chat-utils.ts +111 -2
- package/src/components/editor/SortableCell.tsx +6 -2
- package/src/components/editor/__tests__/output-persistence.test.tsx +241 -0
- package/src/components/editor/cell/cell-context-menu.tsx +7 -0
- package/src/components/editor/chrome/panels/packages-panel.tsx +11 -1
- package/src/components/editor/columns/__tests__/cell-column.test.tsx +105 -0
- package/src/components/editor/columns/cell-column.tsx +34 -4
- package/src/components/editor/columns/sortable-column.tsx +24 -4
- package/src/components/editor/notebook-cell.tsx +203 -106
- package/src/components/editor/renderers/__tests__/cells-renderer.test.tsx +66 -0
- package/src/components/editor/renderers/cell-array.tsx +26 -13
- package/src/components/editor/renderers/cells-renderer.tsx +8 -2
- package/src/components/editor/renderers/slides-layout/__tests__/plugin.test.ts +29 -0
- package/src/components/editor/renderers/slides-layout/types.ts +4 -0
- package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +19 -19
- package/src/components/slides/reveal-component.tsx +33 -4
- package/src/components/slides/slide-form.tsx +72 -0
- package/src/core/cells/__tests__/utils.test.ts +59 -0
- package/src/core/cells/utils.ts +51 -0
- package/src/css/app/Cell.css +10 -0
- package/src/hooks/__tests__/useHotkey.test.tsx +88 -0
- package/src/hooks/useHotkey.ts +29 -4
- package/src/plugins/impl/anywidget/__tests__/host.test.ts +6 -9
- package/src/plugins/impl/anywidget/__tests__/widget-binding.test.ts +22 -61
- package/src/plugins/impl/anywidget/model-proxy.ts +0 -13
- package/src/plugins/impl/anywidget/widget-binding.ts +4 -34
- package/src/plugins/impl/matplotlib/__tests__/matplotlib-renderer.test.ts +71 -3
- package/src/plugins/impl/matplotlib/matplotlib-renderer.ts +1 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import { createStore, Provider } from "jotai";
|
|
4
|
+
import { beforeAll, describe, expect, it } from "vitest";
|
|
5
|
+
import { SetupMocks } from "@/__mocks__/common";
|
|
6
|
+
import { MockNotebook } from "@/__mocks__/notebook";
|
|
7
|
+
import { MockRequestClient } from "@/__mocks__/requests";
|
|
8
|
+
import { cellId } from "@/__tests__/branded";
|
|
9
|
+
import { TooltipProvider } from "@/components/ui/tooltip";
|
|
10
|
+
import { notebookAtom } from "@/core/cells/cells";
|
|
11
|
+
import type { CellRuntimeState } from "@/core/cells/types";
|
|
12
|
+
import { createCellRuntimeState } from "@/core/cells/types";
|
|
13
|
+
import { defaultUserConfig } from "@/core/config/config-schema";
|
|
14
|
+
import type { AppMode } from "@/core/mode";
|
|
15
|
+
import { requestClientAtom } from "@/core/network/requests";
|
|
16
|
+
import { Cell } from "../notebook-cell";
|
|
17
|
+
|
|
18
|
+
const cid = cellId("test");
|
|
19
|
+
|
|
20
|
+
function createTestWrapper() {
|
|
21
|
+
const store = createStore();
|
|
22
|
+
store.set(requestClientAtom, MockRequestClient.create());
|
|
23
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
24
|
+
<Provider store={store}>{children}</Provider>
|
|
25
|
+
);
|
|
26
|
+
return { wrapper, store };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function seedNotebook(
|
|
30
|
+
store: ReturnType<typeof createStore>,
|
|
31
|
+
runtimeOverrides: Partial<CellRuntimeState> = {},
|
|
32
|
+
) {
|
|
33
|
+
const notebook = MockNotebook.notebookState({
|
|
34
|
+
cellData: {
|
|
35
|
+
[cid]: {
|
|
36
|
+
code: "1 + 1",
|
|
37
|
+
name: "test_cell",
|
|
38
|
+
edited: false,
|
|
39
|
+
serializedEditorState: null,
|
|
40
|
+
config: {
|
|
41
|
+
disabled: false,
|
|
42
|
+
hide_code: false,
|
|
43
|
+
column: null,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
notebook.cellRuntime[cid] = createCellRuntimeState({
|
|
49
|
+
status: "idle",
|
|
50
|
+
output: {
|
|
51
|
+
channel: "output",
|
|
52
|
+
mimetype: "text/html",
|
|
53
|
+
data: "<span>persist me</span>",
|
|
54
|
+
timestamp: 0,
|
|
55
|
+
},
|
|
56
|
+
...runtimeOverrides,
|
|
57
|
+
});
|
|
58
|
+
store.set(notebookAtom, notebook);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function renderCell(mode: AppMode) {
|
|
62
|
+
return (
|
|
63
|
+
<TooltipProvider>
|
|
64
|
+
<Cell
|
|
65
|
+
cellId={cid}
|
|
66
|
+
mode={mode}
|
|
67
|
+
canDelete={true}
|
|
68
|
+
userConfig={defaultUserConfig()}
|
|
69
|
+
isCollapsed={false}
|
|
70
|
+
collapseCount={0}
|
|
71
|
+
canMoveX={false}
|
|
72
|
+
theme="light"
|
|
73
|
+
showPlaceholder={false}
|
|
74
|
+
/>
|
|
75
|
+
</TooltipProvider>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
beforeAll(() => {
|
|
80
|
+
SetupMocks.resizeObserver();
|
|
81
|
+
global.HTMLDivElement.prototype.scrollIntoView = () => {
|
|
82
|
+
// do nothing
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe("output persistence across mode changes", () => {
|
|
87
|
+
it("preserves the output DOM node when toggling edit <-> present", () => {
|
|
88
|
+
const { store, wrapper } = createTestWrapper();
|
|
89
|
+
seedNotebook(store);
|
|
90
|
+
|
|
91
|
+
const { container, rerender } = render(renderCell("edit"), { wrapper });
|
|
92
|
+
|
|
93
|
+
const outputNode = container.querySelector<HTMLElement>(
|
|
94
|
+
'[data-cell-role="output"]',
|
|
95
|
+
);
|
|
96
|
+
expect(outputNode).toBeTruthy();
|
|
97
|
+
// A property survives only if the exact DOM node instance survives.
|
|
98
|
+
(outputNode as HTMLElement & { __sentinel?: string }).__sentinel = "alive";
|
|
99
|
+
|
|
100
|
+
rerender(renderCell("present"));
|
|
101
|
+
const presentNode = container.querySelector<HTMLElement>(
|
|
102
|
+
'[data-cell-role="output"]',
|
|
103
|
+
);
|
|
104
|
+
expect(presentNode).toBe(outputNode);
|
|
105
|
+
expect(presentNode?.isConnected).toBe(true);
|
|
106
|
+
expect(
|
|
107
|
+
(presentNode as HTMLElement & { __sentinel?: string }).__sentinel,
|
|
108
|
+
).toBe("alive");
|
|
109
|
+
|
|
110
|
+
// Edit chrome is hidden but stays mounted while presenting
|
|
111
|
+
const tray = container.querySelector<HTMLElement>(
|
|
112
|
+
"[data-testid='cell-tray']",
|
|
113
|
+
);
|
|
114
|
+
expect(tray).toBeTruthy();
|
|
115
|
+
expect(tray?.hidden).toBe(true);
|
|
116
|
+
// Present styling is applied
|
|
117
|
+
expect(
|
|
118
|
+
container
|
|
119
|
+
.querySelector(`[data-cell-id="${cid}"]`)
|
|
120
|
+
?.classList.contains("published"),
|
|
121
|
+
).toBe(true);
|
|
122
|
+
|
|
123
|
+
rerender(renderCell("edit"));
|
|
124
|
+
expect(container.querySelector('[data-cell-role="output"]')).toBe(
|
|
125
|
+
outputNode,
|
|
126
|
+
);
|
|
127
|
+
expect(
|
|
128
|
+
container.querySelector<HTMLElement>("[data-testid='cell-tray']")?.hidden,
|
|
129
|
+
).toBe(false);
|
|
130
|
+
expect(
|
|
131
|
+
container
|
|
132
|
+
.querySelector(`[data-cell-id="${cid}"]`)
|
|
133
|
+
?.classList.contains("published"),
|
|
134
|
+
).toBe(false);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("hides all edit chrome while presenting", () => {
|
|
138
|
+
const { store, wrapper } = createTestWrapper();
|
|
139
|
+
seedNotebook(store);
|
|
140
|
+
|
|
141
|
+
const { container, rerender } = render(renderCell("edit"), { wrapper });
|
|
142
|
+
|
|
143
|
+
// Returns true when the element is not visible: either gone from the DOM or
|
|
144
|
+
// inside a `hidden` ancestor. Edit chrome may unmount while presenting (only
|
|
145
|
+
// the cell *output* is contractually kept mounted — see the DOM-node test
|
|
146
|
+
// above); either way it must not be visible.
|
|
147
|
+
const isHidden = (testId: string) => {
|
|
148
|
+
const el = container.querySelector(`[data-testid='${testId}']`);
|
|
149
|
+
return el === null || el.closest("[hidden]") !== null;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// Everything visible in edit mode
|
|
153
|
+
const editChrome = [
|
|
154
|
+
"cell-tray",
|
|
155
|
+
"drag-button",
|
|
156
|
+
"cell-actions-button",
|
|
157
|
+
"delete-button",
|
|
158
|
+
"create-cell-button",
|
|
159
|
+
"console-output-area",
|
|
160
|
+
];
|
|
161
|
+
for (const testId of editChrome) {
|
|
162
|
+
expect({ testId, hidden: isHidden(testId) }).toEqual({
|
|
163
|
+
testId,
|
|
164
|
+
hidden: false,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
rerender(renderCell("present"));
|
|
169
|
+
for (const testId of editChrome) {
|
|
170
|
+
expect({ testId, hidden: isHidden(testId) }).toEqual({
|
|
171
|
+
testId,
|
|
172
|
+
hidden: true,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
rerender(renderCell("edit"));
|
|
177
|
+
for (const testId of editChrome) {
|
|
178
|
+
expect({ testId, hidden: isHidden(testId) }).toEqual({
|
|
179
|
+
testId,
|
|
180
|
+
hidden: false,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("does not dim edited-but-not-run outputs as stale while presenting", () => {
|
|
186
|
+
const { store, wrapper } = createTestWrapper();
|
|
187
|
+
seedNotebook(store);
|
|
188
|
+
// Mark the cell as edited without re-running it
|
|
189
|
+
const notebook = store.get(notebookAtom);
|
|
190
|
+
notebook.cellData[cid] = { ...notebook.cellData[cid], edited: true };
|
|
191
|
+
store.set(notebookAtom, { ...notebook });
|
|
192
|
+
|
|
193
|
+
const { container, rerender } = render(renderCell("edit"), { wrapper });
|
|
194
|
+
expect(container.querySelector(".marimo-output-stale")).toBeTruthy();
|
|
195
|
+
|
|
196
|
+
// The read view never dims pending edits; present mode matches it
|
|
197
|
+
rerender(renderCell("present"));
|
|
198
|
+
expect(container.querySelector(".marimo-output-stale")).toBeFalsy();
|
|
199
|
+
|
|
200
|
+
rerender(renderCell("edit"));
|
|
201
|
+
expect(container.querySelector(".marimo-output-stale")).toBeTruthy();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("hides errored cells while presenting without unmounting them", () => {
|
|
205
|
+
const { store, wrapper } = createTestWrapper();
|
|
206
|
+
seedNotebook(store, {
|
|
207
|
+
errored: true,
|
|
208
|
+
output: {
|
|
209
|
+
channel: "marimo-error",
|
|
210
|
+
mimetype: "application/vnd.marimo+error",
|
|
211
|
+
data: [{ type: "exception", exception_type: "ValueError", msg: "!" }],
|
|
212
|
+
timestamp: 0,
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
const { container, rerender } = render(renderCell("edit"), { wrapper });
|
|
217
|
+
|
|
218
|
+
const outputNode = container.querySelector<HTMLElement>(
|
|
219
|
+
'[data-cell-role="output"]',
|
|
220
|
+
);
|
|
221
|
+
expect(outputNode).toBeTruthy();
|
|
222
|
+
|
|
223
|
+
const getSortableWrapper = () =>
|
|
224
|
+
container.querySelector<HTMLElement>(`[data-cell-id="${cid}"]`)
|
|
225
|
+
?.parentElement;
|
|
226
|
+
expect(getSortableWrapper()?.hidden).toBe(false);
|
|
227
|
+
|
|
228
|
+
rerender(renderCell("present"));
|
|
229
|
+
// Still mounted, but hidden
|
|
230
|
+
expect(container.querySelector('[data-cell-role="output"]')).toBe(
|
|
231
|
+
outputNode,
|
|
232
|
+
);
|
|
233
|
+
expect(getSortableWrapper()?.hidden).toBe(true);
|
|
234
|
+
|
|
235
|
+
rerender(renderCell("edit"));
|
|
236
|
+
expect(container.querySelector('[data-cell-role="output"]')).toBe(
|
|
237
|
+
outputNode,
|
|
238
|
+
);
|
|
239
|
+
expect(getSortableWrapper()?.hidden).toBe(false);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
@@ -39,12 +39,18 @@ interface Props extends Pick<
|
|
|
39
39
|
"cellId" | "getEditorView"
|
|
40
40
|
> {
|
|
41
41
|
children: React.ReactNode;
|
|
42
|
+
/**
|
|
43
|
+
* If true, the custom context menu is disabled and the native one is used
|
|
44
|
+
* (e.g. while presenting).
|
|
45
|
+
*/
|
|
46
|
+
disabled?: boolean;
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
export const CellActionsContextMenu = ({
|
|
45
50
|
children,
|
|
46
51
|
cellId,
|
|
47
52
|
getEditorView,
|
|
53
|
+
disabled,
|
|
48
54
|
}: Props) => {
|
|
49
55
|
const cellData = useCellData(cellId);
|
|
50
56
|
const cellRuntime = useCellRuntime(cellId);
|
|
@@ -187,6 +193,7 @@ export const CellActionsContextMenu = ({
|
|
|
187
193
|
return (
|
|
188
194
|
<ContextMenu>
|
|
189
195
|
<ContextMenuTrigger
|
|
196
|
+
disabled={disabled}
|
|
190
197
|
onContextMenu={(evt) => {
|
|
191
198
|
if (evt.target instanceof HTMLImageElement) {
|
|
192
199
|
setImageRightClicked(evt.target);
|
|
@@ -303,6 +303,16 @@ const PackagesList: React.FC<{
|
|
|
303
303
|
onSuccess: () => void;
|
|
304
304
|
packages: { name: string; version: string }[];
|
|
305
305
|
}> = ({ onSuccess, packages }) => {
|
|
306
|
+
// Sort case-insensitively so packages are strictly alphabetical
|
|
307
|
+
// regardless of capitalization (package managers sort inconsistently).
|
|
308
|
+
const sortedPackages = React.useMemo(
|
|
309
|
+
() =>
|
|
310
|
+
packages.toSorted((a, b) =>
|
|
311
|
+
a.name.localeCompare(b.name, undefined, { sensitivity: "base" }),
|
|
312
|
+
),
|
|
313
|
+
[packages],
|
|
314
|
+
);
|
|
315
|
+
|
|
306
316
|
if (packages.length === 0) {
|
|
307
317
|
return (
|
|
308
318
|
<PanelEmptyState
|
|
@@ -323,7 +333,7 @@ const PackagesList: React.FC<{
|
|
|
323
333
|
</TableRow>
|
|
324
334
|
</TableHeader>
|
|
325
335
|
<TableBody>
|
|
326
|
-
{
|
|
336
|
+
{sortedPackages.map((item) => (
|
|
327
337
|
<TableRow
|
|
328
338
|
key={item.name}
|
|
329
339
|
className="group"
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import { createStore, Provider } from "jotai";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { TooltipProvider } from "@/components/ui/tooltip";
|
|
6
|
+
import type { CellColumnId } from "@/utils/id-tree";
|
|
7
|
+
import { Column } from "../cell-column";
|
|
8
|
+
|
|
9
|
+
const columnId = "col-1" as CellColumnId;
|
|
10
|
+
|
|
11
|
+
function renderColumn({
|
|
12
|
+
width,
|
|
13
|
+
presenting,
|
|
14
|
+
}: {
|
|
15
|
+
width: "compact" | "columns";
|
|
16
|
+
presenting: boolean;
|
|
17
|
+
}) {
|
|
18
|
+
const store = createStore();
|
|
19
|
+
return render(
|
|
20
|
+
<Provider store={store}>
|
|
21
|
+
<TooltipProvider>
|
|
22
|
+
<Column
|
|
23
|
+
columnId={columnId}
|
|
24
|
+
index={0}
|
|
25
|
+
width={width}
|
|
26
|
+
canDelete={false}
|
|
27
|
+
canMoveLeft={false}
|
|
28
|
+
canMoveRight={false}
|
|
29
|
+
presenting={presenting}
|
|
30
|
+
>
|
|
31
|
+
<div data-testid="column-children" />
|
|
32
|
+
</Column>
|
|
33
|
+
</TooltipProvider>
|
|
34
|
+
</Provider>,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe("Column (single-column notebook)", () => {
|
|
39
|
+
it("spaces cells with the --notebook-cell-gap variable", () => {
|
|
40
|
+
const { getByTestId } = renderColumn({
|
|
41
|
+
width: "compact",
|
|
42
|
+
presenting: false,
|
|
43
|
+
});
|
|
44
|
+
const column = getByTestId("cell-column");
|
|
45
|
+
expect(column.classList.contains("gap-(--notebook-cell-gap)")).toBe(true);
|
|
46
|
+
expect(column.classList.contains("[--notebook-cell-gap:0px]")).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("zeroes the cell gap while presenting", () => {
|
|
50
|
+
const { getByTestId } = renderColumn({
|
|
51
|
+
width: "compact",
|
|
52
|
+
presenting: true,
|
|
53
|
+
});
|
|
54
|
+
const column = getByTestId("cell-column");
|
|
55
|
+
expect(column.classList.contains("gap-(--notebook-cell-gap)")).toBe(true);
|
|
56
|
+
expect(column.classList.contains("[--notebook-cell-gap:0px]")).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("Column (multi-column notebook)", () => {
|
|
61
|
+
it("shows column chrome when not presenting", () => {
|
|
62
|
+
const { getByTestId, getAllByTestId } = renderColumn({
|
|
63
|
+
width: "columns",
|
|
64
|
+
presenting: false,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(getByTestId("column-header").hidden).toBe(false);
|
|
68
|
+
expect(getByTestId("column-frame").classList.contains("border")).toBe(true);
|
|
69
|
+
for (const handle of getAllByTestId("column-resize-handle")) {
|
|
70
|
+
expect(handle.hidden).toBe(false);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("hides column chrome while presenting, without unmounting it", () => {
|
|
75
|
+
const { getByTestId, getAllByTestId } = renderColumn({
|
|
76
|
+
width: "columns",
|
|
77
|
+
presenting: true,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Header (drag handle, move/delete/add buttons) is hidden but mounted
|
|
81
|
+
expect(getByTestId("column-header").hidden).toBe(true);
|
|
82
|
+
// No border around the column
|
|
83
|
+
expect(getByTestId("column-frame").classList.contains("border")).toBe(
|
|
84
|
+
false,
|
|
85
|
+
);
|
|
86
|
+
// Resize handles are hidden
|
|
87
|
+
const handles = getAllByTestId("column-resize-handle");
|
|
88
|
+
expect(handles.length).toBeGreaterThan(0);
|
|
89
|
+
for (const handle of handles) {
|
|
90
|
+
expect(handle.hidden).toBe(true);
|
|
91
|
+
}
|
|
92
|
+
// Cell gap is zeroed on the column root (cascades to descendants)
|
|
93
|
+
const columnRoot = getByTestId("column-frame").parentElement;
|
|
94
|
+
expect(columnRoot?.classList.contains("[--notebook-cell-gap:0px]")).toBe(
|
|
95
|
+
true,
|
|
96
|
+
);
|
|
97
|
+
// Editor geometry (saved widths, min-width, gutters) is replaced by the
|
|
98
|
+
// published content width
|
|
99
|
+
const inner = getByTestId("column-children").parentElement;
|
|
100
|
+
expect(inner?.classList.contains("min-w-[500px]")).toBe(false);
|
|
101
|
+
expect(inner?.classList.contains("w-(--content-width)")).toBe(true);
|
|
102
|
+
// Children stay mounted
|
|
103
|
+
expect(getByTestId("column-children")).toBeTruthy();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import React, { memo, useRef } from "react";
|
|
4
4
|
import type { AppConfig } from "@/core/config/config-schema";
|
|
5
5
|
import { useResizeHandle } from "@/hooks/useResizeHandle";
|
|
6
|
+
import { cn } from "@/utils/cn";
|
|
6
7
|
import type { CellColumnId } from "@/utils/id-tree";
|
|
7
8
|
import { SortableColumn } from "./sortable-column";
|
|
8
9
|
import { storageFn } from "./storage";
|
|
@@ -17,6 +18,11 @@ interface Props {
|
|
|
17
18
|
canDelete: boolean;
|
|
18
19
|
canMoveLeft: boolean;
|
|
19
20
|
canMoveRight: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* If true, column chrome (drag handles, resize handles, borders) is hidden
|
|
23
|
+
* while keeping the same component tree mounted.
|
|
24
|
+
*/
|
|
25
|
+
presenting?: boolean;
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
const { getColumnWidth, saveColumnWidth } = storageFn;
|
|
@@ -24,6 +30,10 @@ const { getColumnWidth, saveColumnWidth } = storageFn;
|
|
|
24
30
|
export const Column = memo((props: Props) => {
|
|
25
31
|
const columnRef = useRef<HTMLDivElement>(null);
|
|
26
32
|
|
|
33
|
+
// Published cells are not spaced apart. Set once on the column root; the
|
|
34
|
+
// CSS variable cascades to the gap-using descendants.
|
|
35
|
+
const zeroGapWhenPresenting = props.presenting && "[--notebook-cell-gap:0px]";
|
|
36
|
+
|
|
27
37
|
if (props.width === "columns") {
|
|
28
38
|
return (
|
|
29
39
|
<SortableColumn
|
|
@@ -33,14 +43,16 @@ export const Column = memo((props: Props) => {
|
|
|
33
43
|
columnId={props.columnId}
|
|
34
44
|
canMoveLeft={props.canMoveLeft}
|
|
35
45
|
canMoveRight={props.canMoveRight}
|
|
36
|
-
className="group/column"
|
|
46
|
+
className={cn("group/column", zeroGapWhenPresenting)}
|
|
37
47
|
footer={props.footer}
|
|
48
|
+
presenting={props.presenting}
|
|
38
49
|
>
|
|
39
50
|
<ResizableComponent
|
|
40
51
|
startingWidth={getColumnWidth(props.index)}
|
|
41
52
|
onResize={(width: number) => {
|
|
42
53
|
saveColumnWidth(props.index, width);
|
|
43
54
|
}}
|
|
55
|
+
presenting={props.presenting}
|
|
44
56
|
>
|
|
45
57
|
{props.children}
|
|
46
58
|
</ResizableComponent>
|
|
@@ -50,7 +62,13 @@ export const Column = memo((props: Props) => {
|
|
|
50
62
|
|
|
51
63
|
return (
|
|
52
64
|
<>
|
|
53
|
-
<div
|
|
65
|
+
<div
|
|
66
|
+
data-testid="cell-column"
|
|
67
|
+
className={cn(
|
|
68
|
+
"flex flex-col gap-(--notebook-cell-gap)",
|
|
69
|
+
zeroGapWhenPresenting,
|
|
70
|
+
)}
|
|
71
|
+
>
|
|
54
72
|
{props.children}
|
|
55
73
|
</div>
|
|
56
74
|
{props.footer}
|
|
@@ -64,12 +82,14 @@ interface ResizableComponentProps {
|
|
|
64
82
|
startingWidth: number | "contentWidth";
|
|
65
83
|
onResize?: (width: number) => void;
|
|
66
84
|
children: React.ReactNode;
|
|
85
|
+
presenting?: boolean;
|
|
67
86
|
}
|
|
68
87
|
|
|
69
88
|
const ResizableComponent = ({
|
|
70
89
|
startingWidth,
|
|
71
90
|
onResize,
|
|
72
91
|
children,
|
|
92
|
+
presenting,
|
|
73
93
|
}: ResizableComponentProps) => {
|
|
74
94
|
const { resizableDivRef, handleRefs, style } = useResizeHandle({
|
|
75
95
|
startingWidth,
|
|
@@ -80,11 +100,13 @@ const ResizableComponent = ({
|
|
|
80
100
|
return (
|
|
81
101
|
<div
|
|
82
102
|
ref={ref}
|
|
103
|
+
data-testid="column-resize-handle"
|
|
83
104
|
className={`w-[3px] cursor-col-resize transition-colors duration-200 z-100
|
|
84
105
|
relative before:content-[''] before:absolute before:inset-y-0 before:left-[-3px]
|
|
85
106
|
before:right-[-3px] before:w-[9px] before:z-[-1]
|
|
86
107
|
hover/column:bg-[var(--slate-3)] dark:hover/column:bg-[var(--slate-5)]
|
|
87
108
|
hover/column:hover:bg-primary/60 dark:hover/column:hover:bg-primary/60`}
|
|
109
|
+
hidden={presenting}
|
|
88
110
|
/>
|
|
89
111
|
);
|
|
90
112
|
};
|
|
@@ -94,8 +116,16 @@ const ResizableComponent = ({
|
|
|
94
116
|
{renderResizeHandler(handleRefs.left)}
|
|
95
117
|
<div
|
|
96
118
|
ref={resizableDivRef}
|
|
97
|
-
className=
|
|
98
|
-
|
|
119
|
+
className={cn(
|
|
120
|
+
"flex flex-col gap-(--notebook-cell-gap) box-content z-1",
|
|
121
|
+
// While presenting, use the published content width instead of the
|
|
122
|
+
// editor geometry (saved pixel width, 500px minimum, gutters),
|
|
123
|
+
// which overflows narrow screens.
|
|
124
|
+
presenting
|
|
125
|
+
? "w-(--content-width)"
|
|
126
|
+
: "min-h-[100px] px-11 pt-3 pb-6 min-w-[500px]",
|
|
127
|
+
)}
|
|
128
|
+
style={presenting ? undefined : style}
|
|
99
129
|
>
|
|
100
130
|
{children}
|
|
101
131
|
</div>
|
|
@@ -30,11 +30,24 @@ interface Props extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
30
30
|
canMoveLeft: boolean;
|
|
31
31
|
canMoveRight: boolean;
|
|
32
32
|
footer?: React.ReactNode;
|
|
33
|
+
/**
|
|
34
|
+
* If true, dragging is disabled and the column chrome is hidden
|
|
35
|
+
* (e.g. while presenting).
|
|
36
|
+
*/
|
|
37
|
+
presenting?: boolean;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
const SortableColumnInternal = React.forwardRef(
|
|
36
41
|
(
|
|
37
|
-
{
|
|
42
|
+
{
|
|
43
|
+
columnId,
|
|
44
|
+
canDelete,
|
|
45
|
+
canMoveLeft,
|
|
46
|
+
canMoveRight,
|
|
47
|
+
footer,
|
|
48
|
+
presenting,
|
|
49
|
+
...props
|
|
50
|
+
}: Props,
|
|
38
51
|
ref: React.Ref<HTMLDivElement>,
|
|
39
52
|
) => {
|
|
40
53
|
const {
|
|
@@ -45,7 +58,7 @@ const SortableColumnInternal = React.forwardRef(
|
|
|
45
58
|
transition,
|
|
46
59
|
isDragging,
|
|
47
60
|
isOver,
|
|
48
|
-
} = useSortable({ id: columnId });
|
|
61
|
+
} = useSortable({ id: columnId, disabled: presenting });
|
|
49
62
|
|
|
50
63
|
const style: React.CSSProperties = {
|
|
51
64
|
transform: transform
|
|
@@ -78,7 +91,11 @@ const SortableColumnInternal = React.forwardRef(
|
|
|
78
91
|
};
|
|
79
92
|
|
|
80
93
|
const dragHandle = (
|
|
81
|
-
<div
|
|
94
|
+
<div
|
|
95
|
+
data-testid="column-header"
|
|
96
|
+
className="px-2 pb-0 group flex items-center overflow-hidden border-b border-(--slate-7)"
|
|
97
|
+
hidden={presenting}
|
|
98
|
+
>
|
|
82
99
|
<Tooltip content="Move column left" side="top" delayDuration={300}>
|
|
83
100
|
<Button
|
|
84
101
|
variant="text"
|
|
@@ -161,7 +178,10 @@ const SortableColumnInternal = React.forwardRef(
|
|
|
161
178
|
isOver && "bg-accent/20", // Add a background color when dragging over
|
|
162
179
|
)}
|
|
163
180
|
>
|
|
164
|
-
<div
|
|
181
|
+
<div
|
|
182
|
+
data-testid="column-frame"
|
|
183
|
+
className={cn(!presenting && "border border-(--slate-7)")}
|
|
184
|
+
>
|
|
165
185
|
{dragHandle}
|
|
166
186
|
{props.children}
|
|
167
187
|
</div>
|