Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/lexical/src/convert/markdown/convertToMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from './utils';

export function $convertToMarkdownString(): string {
const output = [];
const output: string[] = [];
const children = $getRoot().getChildren();

for (const child of children) {
Expand Down Expand Up @@ -56,7 +56,7 @@ function exportTopLevelElementOrDecorator(node: LexicalNode): string | null {
}

function exportChildren(node: ElementNode): string {
const output = [];
const output: string[] = [];
const children = node.getChildren();

for (const child of children) {
Expand Down
16 changes: 14 additions & 2 deletions packages/lexical/src/nodes/JupyterOutputNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
Kernel,
} from '@datalayer/jupyter-react';
import { createNoKernelWarning } from './jupyterUtils';
import { isJupyterOutputNodeOrphaned } from './JupyterOutputNodeUtils';

export type SerializedJupyterOutputNode = Spread<
{
Expand Down Expand Up @@ -191,7 +192,10 @@ export class JupyterOutputNode extends DecoratorNode<JSX.Element> {

/** @override */
isIsolated(): boolean {
return false;
// Treat orphaned output nodes as isolated blocks for editing purposes
// Return true only for orphaned nodes so they are handled as isolated blocks
// Normal output nodes with valid parents remain non-isolated
return isJupyterOutputNodeOrphaned(this);
}

/** @override */
Expand Down Expand Up @@ -223,7 +227,15 @@ export class JupyterOutputNode extends DecoratorNode<JSX.Element> {

/** @override */
remove(_preserveEmptyParent?: boolean): void {
// Do not delete JupyterOutputNode.
// Check if this output node is orphaned (parent input node was deleted)
if (isJupyterOutputNodeOrphaned(this)) {
// Allow deletion of orphaned output nodes
// Explicitly set preserveEmptyParent to false for orphaned nodes,
// since their parent has already been deleted and we do not want to preserve an
// empty parent.
super.remove(false);
}
// Otherwise, do not delete (output nodes with valid parents are protected)
}

removeForce(): void {
Expand Down
27 changes: 27 additions & 0 deletions packages/lexical/src/nodes/JupyterOutputNodeUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2021-2023 Datalayer, Inc.
*
* MIT License
*/

import { INPUT_UUID_TO_CODE_KEY } from '../plugins/JupyterInputOutputPlugin';
import type { JupyterOutputNode } from './JupyterOutputNode';

/**
* Check if a JupyterOutputNode is orphaned (its parent input node was deleted).
*
* An output node is considered orphaned if:
* 1. Its parent input node UUID is not in the INPUT_UUID_TO_CODE_KEY map, OR
* 2. The output node has no parent in the Lexical tree
*
* @param outputNode - The JupyterOutputNode to check
* @returns true if the output node is orphaned, false otherwise
*/
export function isJupyterOutputNodeOrphaned(
outputNode: JupyterOutputNode,
): boolean {
const inputNodeKey = INPUT_UUID_TO_CODE_KEY.get(
outputNode.getJupyterInputNodeUuid(),
);
return !inputNodeKey || !outputNode.getParent();
}
Loading