Skip to content

Commit a33c4fd

Browse files
committed
stable html: fix drag to reorder
1 parent bb5f139 commit a33c4fd

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

src/packages/frontend/components/sortable-list.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ being virtualized with react-virtuoso.
1212

1313
import { CSSProperties, ReactNode, useState } from "react";
1414
import { Icon } from "./icon";
15-
1615
import { DndContext, DragOverlay } from "@dnd-kit/core";
1716
import {
1817
SortableContext,

src/packages/frontend/jupyter/cell-list.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,15 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
419419
delayRendering, // seems not used anywhere!
420420
isFirst,
421421
isLast,
422+
isDragging,
422423
}: {
423424
id: string;
424425
isScrolling?: boolean;
425426
index?: number;
426427
delayRendering?: number;
427428
isFirst?: boolean;
428429
isLast?: boolean;
430+
isDragging?: boolean;
429431
}) {
430432
const cell = cells.get(id);
431433
if (cell == null) return null;
@@ -475,6 +477,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
475477
isLast={isLast}
476478
dragHandle={dragHandle}
477479
read_only={read_only}
480+
isDragging={isDragging}
478481
/>
479482
</div>
480483
);
@@ -691,14 +694,15 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
691694
disabled={actions == null}
692695
items={cell_list.toJS()}
693696
Item={({ id }) => (
697+
/* This is what is displayed when dragging the given cell. */
694698
<div
695699
style={{
696700
background: "white",
697701
boxShadow: "8px 8px 4px 4px #ccc",
698702
fontSize: `${font_size}px`,
699703
}}
700704
>
701-
{renderCell({ id })}
705+
{renderCell({ id, isDragging: true })}
702706
</div>
703707
)}
704708
onDragStart={(id) => {

src/packages/frontend/jupyter/cell-output.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface CellOutputProps {
3232
style?: React.CSSProperties;
3333
divRef?;
3434
llmTools?: LLMTools;
35+
isDragging?: boolean;
3536
}
3637

3738
export function CellOutput({
@@ -48,6 +49,7 @@ export function CellOutput({
4849
divRef,
4950
style,
5051
llmTools,
52+
isDragging,
5153
}: CellOutputProps) {
5254
const minHeight = complete ? "60vh" : undefined;
5355

@@ -94,6 +96,7 @@ export function CellOutput({
9496
name={name}
9597
trust={trust}
9698
llmTools={llmTools}
99+
isDragging={isDragging}
97100
/>
98101
</div>
99102
);
@@ -109,6 +112,7 @@ interface OutputColumnProps {
109112
name?: string;
110113
trust?: boolean;
111114
llmTools?;
115+
isDragging?: boolean;
112116
}
113117

114118
function OutputColumn({
@@ -121,7 +125,14 @@ function OutputColumn({
121125
name,
122126
trust,
123127
llmTools,
128+
isDragging,
124129
}: OutputColumnProps) {
130+
if (isDragging) {
131+
// stable html + dragging breaks badly since you end up with two copies
132+
// of the same thing, etc. Also, not carrying the output makes seeing
133+
// what is going on more manageable.
134+
return null;
135+
}
125136
if (cell.get("collapsed")) {
126137
return <CollapsedOutput actions={actions} id={id} />;
127138
}

src/packages/frontend/jupyter/cell.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ interface Props {
6060
isLast?: boolean;
6161
dragHandle?: JSX.Element;
6262
read_only?: boolean;
63+
isDragging?: boolean;
6364
}
6465

6566
function areEqual(props: Props, nextProps: Props): boolean {
@@ -88,7 +89,8 @@ function areEqual(props: Props, nextProps: Props): boolean {
8889
(nextProps.complete !== props.complete && // only worry about complete when editing this cell
8990
(nextProps.is_current || props.is_current)) ||
9091
nextProps.dragHandle !== props.dragHandle ||
91-
nextProps.read_only !== props.read_only
92+
nextProps.read_only !== props.read_only ||
93+
nextProps.isDragging !== props.isDragging
9294
);
9395
}
9496

@@ -164,6 +166,7 @@ export const Cell: React.FC<Props> = React.memo((props: Props) => {
164166
trust={props.trust}
165167
complete={props.is_current && props.complete != null}
166168
llmTools={props.llmTools}
169+
isDragging={props.isDragging}
167170
/>
168171
);
169172
}

src/packages/frontend/jupyter/output-messages/message.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,7 @@ interface CellOutputMessageProps {
6363
export const CellOutputMessage: React.FC<CellOutputMessageProps> = React.memo(
6464
(props: CellOutputMessageProps) => {
6565
const C: any = messageComponent(props.message);
66-
return (
67-
<C
68-
message={props.message}
69-
project_id={props.project_id}
70-
directory={props.directory}
71-
actions={props.actions}
72-
name={props.name}
73-
trust={props.trust}
74-
id={props.id}
75-
index={props.index}
76-
/>
77-
);
66+
return <C {...props} />;
7867
},
7968
);
8069

0 commit comments

Comments
 (0)