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
2 changes: 0 additions & 2 deletions packages/lexical/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
*
* MIT License
*/

module.exports = require('@jupyterlab/testutils/lib/babel.config');
29 changes: 0 additions & 29 deletions packages/lexical/src/components/JupyterCellComponent.tsx

This file was deleted.

44 changes: 0 additions & 44 deletions packages/lexical/src/components/JupyterOutputComponent.tsx

This file was deleted.

1 change: 0 additions & 1 deletion packages/lexical/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export * from './DropDown';
export * from './EquationEditor';
export * from './FileInput';
export * from './ImageResizer';
export * from './JupyterOutputComponent';
export * from './KatexEquationAlterer';
export * from './KatexEquationAlterer';
export * from './KatexRenderer';
Expand Down
4 changes: 2 additions & 2 deletions packages/lexical/src/convert/LexicalToNbformat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@jupyterlab/nbformat';
import EquationNode, { $isEquationNode } from './../nodes/EquationNode';
import { $isYouTubeNode } from './../nodes/YouTubeNode';
import { $isJupyterCodeNode } from './../nodes/JupyterCodeNode';
import { $isJupyterInputNode } from './../nodes/JupyterInputNode';
import { exportTopLevelElements } from './markdown/MarkdownExport';
import { transformersByType } from './markdown/utils';
import { TRANSFORMERS } from './markdown/index';
Expand Down Expand Up @@ -49,7 +49,7 @@ export const lexicalToNbformat = (nodes: LexicalNode[]) => {
cells: [],
};
nodes.map(node => {
if ($isJupyterCodeNode(node)) {
if ($isJupyterInputNode(node)) {
nb.cells.push(newCodeCell(node.getTextContent()));
} else if (
$isParagraphNode(node) &&
Expand Down
8 changes: 4 additions & 4 deletions packages/lexical/src/convert/NbformatToLexical.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import { LexicalEditor, INSERT_PARAGRAPH_COMMAND } from 'lexical';
import { INotebookContent, IOutput } from '@jupyterlab/nbformat';
// import { INSERT_JUPYTER_CELL_OUTPUT_COMMAND } from "../plugins/JupyterCellOutputPlugin";
import { INSERT_JUPYTER_CELL_COMMAND } from '../plugins/JupyterCellPlugin';
// import { INSERT_JUPYTER_CELL_COMMAND } from '../plugins/JupyterCellPlugin';
import { INSERT_JUPYTER_INPUT_OUTPUT_COMMAND } from '../plugins/JupyterInputOutputPlugin';
import { $convertFromMarkdownString, TRANSFORMERS } from './markdown';

export const nbformatToLexical = (
Expand All @@ -28,11 +28,11 @@ export const nbformatToLexical = (
}
if (cell.cell_type === 'code') {
const outputs = cell.outputs as IOutput[];
editor.dispatchCommand(INSERT_JUPYTER_CELL_COMMAND, {
editor.dispatchCommand(INSERT_JUPYTER_INPUT_OUTPUT_COMMAND, {
code,
outputs,
loading: 'Loading...',
autoStart: false,
// autoStart: false,
});
}
editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined);
Expand Down
10 changes: 5 additions & 5 deletions packages/lexical/src/convert/markdown/MarkdownImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import type {
import type { LexicalNode, RootNode, TextNode } from 'lexical';

import {
JupyterCodeNode,
$createJupyterCodeNode,
} from './../../nodes/JupyterCodeNode';
JupyterInputNode,
$createJupyterInputNode,
} from './../../nodes/JupyterInputNode';
import { $isListItemNode, $isListNode } from '@lexical/list';
import { $isQuoteNode } from '@lexical/rich-text';
import { $findMatchingParent } from '@lexical/utils';
Expand Down Expand Up @@ -167,7 +167,7 @@ function importCodeBlock(
lines: Array<string>,
startLineIndex: number,
rootNode: RootNode,
): [JupyterCodeNode | null, number] {
): [JupyterInputNode | null, number] {
const openMatch = lines[startLineIndex].match(CODE_BLOCK_REG_EXP);

if (openMatch) {
Expand All @@ -178,7 +178,7 @@ function importCodeBlock(
const closeMatch = lines[endLineIndex].match(CODE_BLOCK_REG_EXP);

if (closeMatch) {
const codeBlockNode = $createJupyterCodeNode(openMatch[1]);
const codeBlockNode = $createJupyterInputNode(openMatch[1]);
const textNode = $createTextNode(
lines.slice(startLineIndex + 1, endLineIndex).join('\n'),
);
Expand Down
4 changes: 2 additions & 2 deletions packages/lexical/src/convert/markdown/MarkdownShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
} from '.';
import type { ElementNode, LexicalEditor, TextNode } from 'lexical';

import { $isJupyterCodeNode } from './../../nodes/JupyterCodeNode';
import { $isJupyterInputNode } from './../../nodes/JupyterInputNode';
import {
$createRangeSelection,
$getSelection,
Expand Down Expand Up @@ -417,7 +417,7 @@ export function registerMarkdownShortcuts(

const parentNode = anchorNode.getParent();

if (parentNode === null || $isJupyterCodeNode(parentNode)) {
if (parentNode === null || $isJupyterInputNode(parentNode)) {
return;
}

Expand Down
14 changes: 7 additions & 7 deletions packages/lexical/src/convert/markdown/MarkdownTransformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import type {
} from 'lexical';

import {
$createJupyterCodeNode,
$isJupyterCodeNode,
JupyterCodeNode,
} from './../../nodes/JupyterCodeNode';
$createJupyterInputNode,
$isJupyterInputNode,
JupyterInputNode,
} from './../../nodes/JupyterInputNode';
import { $createLinkNode, $isLinkNode, LinkNode } from '@lexical/link';
import {
$createListItemNode,
Expand Down Expand Up @@ -212,9 +212,9 @@ export const QUOTE: ElementTransformer = {
};

export const CODE: ElementTransformer = {
dependencies: [JupyterCodeNode],
dependencies: [JupyterInputNode],
export: (node: LexicalNode) => {
if (!$isJupyterCodeNode(node)) {
if (!$isJupyterInputNode(node)) {
return null;
}
const textContent = node.getTextContent();
Expand All @@ -228,7 +228,7 @@ export const CODE: ElementTransformer = {
},
regExp: /^```(\w{1,10})?\s/,
replace: replaceWithBlock(match => {
return $createJupyterCodeNode(match ? match[1] : undefined);
return $createJupyterInputNode(match ? match[1] : undefined);
}),
type: 'element',
};
Expand Down
4 changes: 2 additions & 2 deletions packages/lexical/src/convert/markdown/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
} from '.';
import type { ElementNode, LexicalNode, TextFormatType } from 'lexical';

import { $isJupyterCodeNode } from './../../nodes/JupyterCodeNode';
import { $isJupyterInputNode } from './../../nodes/JupyterInputNode';
import { $isListItemNode, $isListNode } from '@lexical/list';
import { $isHeadingNode, $isQuoteNode } from '@lexical/rich-text';

Expand Down Expand Up @@ -379,7 +379,7 @@ function blockQuoteExport(
}

function codeBlockExport(node: LexicalNode) {
if (!$isJupyterCodeNode(node)) {
if (!$isJupyterInputNode(node)) {
return null;
}

Expand Down
28 changes: 17 additions & 11 deletions packages/lexical/src/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import { MarkNode } from '@lexical/mark';
import { AutoLinkNode, LinkNode } from '@lexical/link';
import { CodeNode } from '@lexical/code';
import { INotebookContent } from '@jupyterlab/nbformat';
import { useJupyter } from '@datalayer/jupyter-react';
import {
JupyterCellOutputPlugin,
JupyterInputOutputPlugin,
EquationNode,
HorizontalRulePlugin,
ListMaxIndentLevelPlugin,
Expand All @@ -39,16 +40,16 @@ import {
YouTubePlugin,
ImageNode,
YouTubeNode,
JupyterCodeHighlightNode,
JupyterCodeNode,
JupyterInputHighlightNode,
JupyterInputNode,
JupyterOutputNode,
JupyterCellNode,
// JupyterCellNode,
// JupyterCellPlugin,
CodeActionMenuPlugin,
AutoEmbedPlugin,
NbformatContentPlugin,
TableOfContentsPlugin,
MarkdownPlugin,
JupyterCellPlugin,
CommentPlugin,
FloatingTextFormatToolbarPlugin,
} from './..';
Expand All @@ -58,6 +59,7 @@ import { TreeViewPlugin, ToolbarPlugin } from '../plugins';
import DraggableBlockPlugin from '../plugins/DraggableBlockPlugin';

import './../../style/index.css';
import { CounterNode } from '../nodes/CounterNode';

type Props = {
notebook?: INotebookContent;
Expand All @@ -81,9 +83,9 @@ const initialConfig = {
HeadingNode,
HorizontalRuleNode,
ImageNode,
JupyterCellNode,
JupyterCodeHighlightNode,
JupyterCodeNode,
// JupyterCellNode,
JupyterInputHighlightNode,
JupyterInputNode,
JupyterOutputNode,
LinkNode,
ListItemNode,
Expand All @@ -94,6 +96,7 @@ const initialConfig = {
TableNode,
TableRowNode,
YouTubeNode,
CounterNode,
],
};

Expand All @@ -103,12 +106,13 @@ const EditorContextPlugin = () => {
useEffect(() => {
setEditor(editor);
// return () => setEditor(undefined);
}, [editor]);
}, [editor, setEditor]);
return null;
};

export function Editor(props: Props) {
const { notebook } = props;
const { defaultKernel } = useJupyter();
const [floatingAnchorElem, setFloatingAnchorElem] =
useState<HTMLDivElement | null>(null);

Expand Down Expand Up @@ -149,8 +153,10 @@ export function Editor(props: Props) {
<AutoLinkPlugin />
<ListMaxIndentLevelPlugin maxDepth={7} />
<MarkdownPlugin />
<JupyterCellPlugin />
<JupyterCellOutputPlugin />
{/* <JupyterCellPlugin /> */}
{defaultKernel && (
<JupyterInputOutputPlugin kernel={defaultKernel} />
)}
<ComponentPickerMenuPlugin />
<EquationsPlugin />
<ImagesPlugin />
Expand Down
7 changes: 4 additions & 3 deletions packages/lexical/src/examples/AppNbformat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
CellSidebar,
CellSidebarExtension,
} from '@datalayer/jupyter-react';
import { Box, UnderlineNav, Button } from '@primer/react';
import { Box } from '@datalayer/primer-addons';
import { UnderlineNav, Button } from '@primer/react';
import { ThreeBarsIcon } from '@primer/octicons-react';
import { JSONTree } from 'react-json-tree';
import { INotebookContent } from '@jupyterlab/nbformat';
Expand Down Expand Up @@ -168,12 +169,12 @@ export function AppNbformat() {
</div>
</div>
<br />
<a href="https://datalayer.io" target="_blank" rel="noreferrer">
<a href="https://datalayer.ai" target="_blank" rel="noreferrer">
<ThreeBarsIcon />
</a>
<h2>
copyright ©{' '}
<a href="https://datalayer.io" target="_blank" rel="noreferrer">
<a href="https://datalayer.ai" target="_blank" rel="noreferrer">
2022-2024 Datalayer, Inc.
</a>
</h2>
Expand Down
Loading