@datalayer/jupyter-lexical 0.0.1
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/LICENSE +21 -0
- package/README.md +7 -0
- package/lib/components/InsertEquationDialog.d.ts +6 -0
- package/lib/components/InsertEquationDialog.js +17 -0
- package/lib/components/InsertEquationDialog.js.map +1 -0
- package/lib/components/InsertImageDialog.d.ts +13 -0
- package/lib/components/InsertImageDialog.js +48 -0
- package/lib/components/InsertImageDialog.js.map +1 -0
- package/lib/components/JupyterCellComponent.d.ts +2 -0
- package/lib/components/JupyterCellComponent.js +12 -0
- package/lib/components/JupyterCellComponent.js.map +1 -0
- package/lib/components/JupyterOutputComponent.d.ts +13 -0
- package/lib/components/JupyterOutputComponent.js +8 -0
- package/lib/components/JupyterOutputComponent.js.map +1 -0
- package/lib/convert/LexicalToNbFormat.d.ts +4 -0
- package/lib/convert/LexicalToNbFormat.js +100 -0
- package/lib/convert/LexicalToNbFormat.js.map +1 -0
- package/lib/convert/NbFormatToLexical.d.ts +4 -0
- package/lib/convert/NbFormatToLexical.js +31 -0
- package/lib/convert/NbFormatToLexical.js.map +1 -0
- package/lib/convert/markdown/MarkdownExport.d.ts +11 -0
- package/lib/convert/markdown/MarkdownExport.js +129 -0
- package/lib/convert/markdown/MarkdownExport.js.map +1 -0
- package/lib/convert/markdown/MarkdownImport.d.ts +2 -0
- package/lib/convert/markdown/MarkdownImport.js +246 -0
- package/lib/convert/markdown/MarkdownImport.js.map +1 -0
- package/lib/convert/markdown/MarkdownShortcuts.d.ts +10 -0
- package/lib/convert/markdown/MarkdownShortcuts.js +254 -0
- package/lib/convert/markdown/MarkdownShortcuts.js.map +1 -0
- package/lib/convert/markdown/MarkdownTransformers.d.ts +39 -0
- package/lib/convert/markdown/MarkdownTransformers.js +242 -0
- package/lib/convert/markdown/MarkdownTransformers.js.map +1 -0
- package/lib/convert/markdown/convertToMarkdown.d.ts +1 -0
- package/lib/convert/markdown/convertToMarkdown.js +126 -0
- package/lib/convert/markdown/convertToMarkdown.js.map +1 -0
- package/lib/convert/markdown/index.d.ts +17 -0
- package/lib/convert/markdown/index.js +46 -0
- package/lib/convert/markdown/index.js.map +1 -0
- package/lib/convert/markdown/utils.d.ts +24 -0
- package/lib/convert/markdown/utils.js +303 -0
- package/lib/convert/markdown/utils.js.map +1 -0
- package/lib/convert/transformers/MarkdownTransformers.d.ts +13 -0
- package/lib/convert/transformers/MarkdownTransformers.js +178 -0
- package/lib/convert/transformers/MarkdownTransformers.js.map +1 -0
- package/lib/examples/App.d.ts +1 -0
- package/lib/examples/App.js +22 -0
- package/lib/examples/App.js.map +1 -0
- package/lib/examples/Editor.d.ts +9 -0
- package/lib/examples/Editor.js +81 -0
- package/lib/examples/Editor.js.map +1 -0
- package/lib/examples/Example.d.ts +1 -0
- package/lib/examples/Example.js +11 -0
- package/lib/examples/Example.js.map +1 -0
- package/lib/examples/content/Example.ipynb.json +98 -0
- package/lib/examples/content/Example.lexical.json +259 -0
- package/lib/examples/context/LexicalContext.d.ts +13 -0
- package/lib/examples/context/LexicalContext.js +22 -0
- package/lib/examples/context/LexicalContext.js.map +1 -0
- package/lib/examples/plugins/ToolbarPlugin.d.ts +2 -0
- package/lib/examples/plugins/ToolbarPlugin.js +448 -0
- package/lib/examples/plugins/ToolbarPlugin.js.map +1 -0
- package/lib/examples/plugins/TreeViewPlugin.d.ts +2 -0
- package/lib/examples/plugins/TreeViewPlugin.js +13 -0
- package/lib/examples/plugins/TreeViewPlugin.js.map +1 -0
- package/lib/examples/themes/Theme.d.ts +10 -0
- package/lib/examples/themes/Theme.js +94 -0
- package/lib/examples/themes/Theme.js.map +1 -0
- package/lib/hooks/useModal.d.ts +2 -0
- package/lib/hooks/useModal.js +39 -0
- package/lib/hooks/useModal.js.map +1 -0
- package/lib/images/yellow-flower-small.jpg +0 -0
- package/lib/index.d.ts +40 -0
- package/lib/index.js +55 -0
- package/lib/index.js.map +1 -0
- package/lib/jupyter/index.d.ts +0 -0
- package/lib/jupyter/index.js +6 -0
- package/lib/jupyter/index.js.map +1 -0
- package/lib/jupyter/lab/Example.d.ts +1 -0
- package/lib/jupyter/lab/Example.js +11 -0
- package/lib/jupyter/lab/Example.js.map +1 -0
- package/lib/jupyter/lab/__tests__/datalayer.spec.d.ts +0 -0
- package/lib/jupyter/lab/__tests__/datalayer.spec.js +11 -0
- package/lib/jupyter/lab/__tests__/datalayer.spec.js.map +1 -0
- package/lib/jupyter/lab/component/MockComponent.d.ts +2 -0
- package/lib/jupyter/lab/component/MockComponent.js +17 -0
- package/lib/jupyter/lab/component/MockComponent.js.map +1 -0
- package/lib/jupyter/lab/component/MockTab1.d.ts +2 -0
- package/lib/jupyter/lab/component/MockTab1.js +14 -0
- package/lib/jupyter/lab/component/MockTab1.js.map +1 -0
- package/lib/jupyter/lab/handler.d.ts +8 -0
- package/lib/jupyter/lab/handler.js +41 -0
- package/lib/jupyter/lab/handler.js.map +1 -0
- package/lib/jupyter/lab/index.d.ts +7 -0
- package/lib/jupyter/lab/index.js +73 -0
- package/lib/jupyter/lab/index.js.map +1 -0
- package/lib/jupyter/lab/widget.d.ts +6 -0
- package/lib/jupyter/lab/widget.js +18 -0
- package/lib/jupyter/lab/widget.js.map +1 -0
- package/lib/nodes/EquationNode.d.ts +31 -0
- package/lib/nodes/EquationNode.js +118 -0
- package/lib/nodes/EquationNode.js.map +1 -0
- package/lib/nodes/ImageNode.css +50 -0
- package/lib/nodes/ImageNode.d.ts +58 -0
- package/lib/nodes/ImageNode.js +275 -0
- package/lib/nodes/ImageNode.js.map +1 -0
- package/lib/nodes/JupyterCodeHighlightNode.d.ts +49 -0
- package/lib/nodes/JupyterCodeHighlightNode.js +165 -0
- package/lib/nodes/JupyterCodeHighlightNode.js.map +1 -0
- package/lib/nodes/JupyterCodeHighlighter.d.ts +28 -0
- package/lib/nodes/JupyterCodeHighlighter.js +522 -0
- package/lib/nodes/JupyterCodeHighlighter.js.map +1 -0
- package/lib/nodes/JupyterCodeNode.d.ts +50 -0
- package/lib/nodes/JupyterCodeNode.js +277 -0
- package/lib/nodes/JupyterCodeNode.js.map +1 -0
- package/lib/nodes/JupyterOutputNode.d.ts +58 -0
- package/lib/nodes/JupyterOutputNode.js +144 -0
- package/lib/nodes/JupyterOutputNode.js.map +1 -0
- package/lib/nodes/YouTubeNode.d.ts +28 -0
- package/lib/nodes/YouTubeNode.js +56 -0
- package/lib/nodes/YouTubeNode.js.map +1 -0
- package/lib/plugins/AutoEmbedPlugin.d.ts +17 -0
- package/lib/plugins/AutoEmbedPlugin.js +110 -0
- package/lib/plugins/AutoEmbedPlugin.js.map +1 -0
- package/lib/plugins/AutoLinkPlugin.d.ts +2 -0
- package/lib/plugins/AutoLinkPlugin.js +34 -0
- package/lib/plugins/AutoLinkPlugin.js.map +1 -0
- package/lib/plugins/CodeActionMenuPlugin.css +52 -0
- package/lib/plugins/CodeActionMenuPlugin.d.ts +12 -0
- package/lib/plugins/CodeActionMenuPlugin.js +108 -0
- package/lib/plugins/CodeActionMenuPlugin.js.map +1 -0
- package/lib/plugins/ComponentPickerMenuPlugin.d.ts +2 -0
- package/lib/plugins/ComponentPickerMenuPlugin.js +244 -0
- package/lib/plugins/ComponentPickerMenuPlugin.js.map +1 -0
- package/lib/plugins/EquationsPlugin.d.ts +21 -0
- package/lib/plugins/EquationsPlugin.js +48 -0
- package/lib/plugins/EquationsPlugin.js.map +1 -0
- package/lib/plugins/HorizontalRulePlugin.d.ts +2 -0
- package/lib/plugins/HorizontalRulePlugin.js +40 -0
- package/lib/plugins/HorizontalRulePlugin.js.map +1 -0
- package/lib/plugins/ImagesPlugin.d.ts +25 -0
- package/lib/plugins/ImagesPlugin.js +212 -0
- package/lib/plugins/ImagesPlugin.js.map +1 -0
- package/lib/plugins/JupyterPlugin.css +13 -0
- package/lib/plugins/JupyterPlugin.d.ts +16 -0
- package/lib/plugins/JupyterPlugin.js +169 -0
- package/lib/plugins/JupyterPlugin.js.map +1 -0
- package/lib/plugins/ListMaxIndentLevelPlugin.d.ts +4 -0
- package/lib/plugins/ListMaxIndentLevelPlugin.js +49 -0
- package/lib/plugins/ListMaxIndentLevelPlugin.js.map +1 -0
- package/lib/plugins/MardownPlugin.d.ts +2 -0
- package/lib/plugins/MardownPlugin.js +20 -0
- package/lib/plugins/MardownPlugin.js.map +1 -0
- package/lib/plugins/NbformatContentPlugin.d.ts +6 -0
- package/lib/plugins/NbformatContentPlugin.js +20 -0
- package/lib/plugins/NbformatContentPlugin.js.map +1 -0
- package/lib/plugins/TableOfContentsPlugin.css +87 -0
- package/lib/plugins/TableOfContentsPlugin.d.ts +3 -0
- package/lib/plugins/TableOfContentsPlugin.js +115 -0
- package/lib/plugins/TableOfContentsPlugin.js.map +1 -0
- package/lib/plugins/YouTubePlugin.d.ts +4 -0
- package/lib/plugins/YouTubePlugin.js +34 -0
- package/lib/plugins/YouTubePlugin.js.map +1 -0
- package/lib/ui/Button.css +40 -0
- package/lib/ui/Button.d.ts +18 -0
- package/lib/ui/Button.js +8 -0
- package/lib/ui/Button.js.map +1 -0
- package/lib/ui/ContentEditable.css +24 -0
- package/lib/ui/ContentEditable.d.ts +5 -0
- package/lib/ui/ContentEditable.js +20 -0
- package/lib/ui/ContentEditable.js.map +1 -0
- package/lib/ui/CopyButton.d.ts +7 -0
- package/lib/ui/CopyButton.js +47 -0
- package/lib/ui/CopyButton.js.map +1 -0
- package/lib/ui/Dialog.css +23 -0
- package/lib/ui/Dialog.d.ts +16 -0
- package/lib/ui/Dialog.js +21 -0
- package/lib/ui/Dialog.js.map +1 -0
- package/lib/ui/DropDown.d.ts +23 -0
- package/lib/ui/DropDown.js +119 -0
- package/lib/ui/DropDown.js.map +1 -0
- package/lib/ui/EquationEditor.css +42 -0
- package/lib/ui/EquationEditor.d.ts +18 -0
- package/lib/ui/EquationEditor.js +31 -0
- package/lib/ui/EquationEditor.js.map +1 -0
- package/lib/ui/FileInput.d.ts +15 -0
- package/lib/ui/FileInput.js +18 -0
- package/lib/ui/FileInput.js.map +1 -0
- package/lib/ui/ImageResizer.d.ts +16 -0
- package/lib/ui/ImageResizer.js +166 -0
- package/lib/ui/ImageResizer.js.map +1 -0
- package/lib/ui/Input.css +37 -0
- package/lib/ui/KatexEquationAlterer.css +45 -0
- package/lib/ui/KatexEquationAlterer.d.ts +7 -0
- package/lib/ui/KatexEquationAlterer.js +33 -0
- package/lib/ui/KatexEquationAlterer.js.map +1 -0
- package/lib/ui/KatexRenderer.d.ts +6 -0
- package/lib/ui/KatexRenderer.js +36 -0
- package/lib/ui/KatexRenderer.js.map +1 -0
- package/lib/ui/Modal.css +67 -0
- package/lib/ui/Modal.d.ts +15 -0
- package/lib/ui/Modal.js +58 -0
- package/lib/ui/Modal.js.map +1 -0
- package/lib/ui/Placeholder.css +29 -0
- package/lib/ui/Placeholder.d.ts +14 -0
- package/lib/ui/Placeholder.js +7 -0
- package/lib/ui/Placeholder.js.map +1 -0
- package/lib/ui/PrettierButton.css +20 -0
- package/lib/ui/PrettierButton.tsx_tmp +133 -0
- package/lib/ui/TextInput.d.ts +16 -0
- package/lib/ui/TextInput.js +20 -0
- package/lib/ui/TextInput.js.map +1 -0
- package/lib/utils/canUseDOM.d.ts +8 -0
- package/lib/utils/canUseDOM.js +16 -0
- package/lib/utils/canUseDOM.js.map +1 -0
- package/lib/utils/debouncer.d.ts +1 -0
- package/lib/utils/debouncer.js +24 -0
- package/lib/utils/debouncer.js.map +1 -0
- package/lib/utils/invariant.d.ts +8 -0
- package/lib/utils/invariant.js +23 -0
- package/lib/utils/invariant.js.map +1 -0
- package/lib/utils/join.d.ts +8 -0
- package/lib/utils/join.js +16 -0
- package/lib/utils/join.js.map +1 -0
- package/lib/utils/selection.d.ts +8 -0
- package/lib/utils/selection.js +14 -0
- package/lib/utils/selection.js.map +1 -0
- package/lib/utils/useLayoutEffect.d.ts +10 -0
- package/lib/utils/useLayoutEffect.js +19 -0
- package/lib/utils/useLayoutEffect.js.map +1 -0
- package/package.json +166 -0
- package/style/base.css +16 -0
- package/style/index.css +7 -0
- package/style/index.js +7 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
import type { DOMConversionMap, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedEditor, SerializedLexicalNode, Spread } from 'lexical';
|
|
10
|
+
import './ImageNode.css';
|
|
11
|
+
import { DecoratorNode } from 'lexical';
|
|
12
|
+
import './ImageNode.css';
|
|
13
|
+
export interface ImagePayload {
|
|
14
|
+
altText: string;
|
|
15
|
+
caption?: LexicalEditor;
|
|
16
|
+
height?: number;
|
|
17
|
+
key?: NodeKey;
|
|
18
|
+
maxWidth?: number;
|
|
19
|
+
showCaption?: boolean;
|
|
20
|
+
src: string;
|
|
21
|
+
width?: number;
|
|
22
|
+
}
|
|
23
|
+
export type SerializedImageNode = Spread<{
|
|
24
|
+
altText: string;
|
|
25
|
+
caption: SerializedEditor;
|
|
26
|
+
height?: number;
|
|
27
|
+
maxWidth: number;
|
|
28
|
+
showCaption: boolean;
|
|
29
|
+
src: string;
|
|
30
|
+
width?: number;
|
|
31
|
+
type: 'image';
|
|
32
|
+
version: 1;
|
|
33
|
+
}, SerializedLexicalNode>;
|
|
34
|
+
export declare class ImageNode extends DecoratorNode<JSX.Element> {
|
|
35
|
+
__src: string;
|
|
36
|
+
__altText: string;
|
|
37
|
+
__width: 'inherit' | number;
|
|
38
|
+
__height: 'inherit' | number;
|
|
39
|
+
__maxWidth: number;
|
|
40
|
+
__showCaption: boolean;
|
|
41
|
+
__caption: LexicalEditor;
|
|
42
|
+
static getType(): string;
|
|
43
|
+
static clone(node: ImageNode): ImageNode;
|
|
44
|
+
static importJSON(serializedNode: SerializedImageNode): ImageNode;
|
|
45
|
+
exportDOM(): DOMExportOutput;
|
|
46
|
+
static importDOM(): DOMConversionMap | null;
|
|
47
|
+
constructor(src: string, altText: string, maxWidth: number, width?: 'inherit' | number, height?: 'inherit' | number, showCaption?: boolean, caption?: LexicalEditor, key?: NodeKey);
|
|
48
|
+
exportJSON(): SerializedImageNode;
|
|
49
|
+
setWidthAndHeight(width: 'inherit' | number, height: 'inherit' | number): void;
|
|
50
|
+
setShowCaption(showCaption: boolean): void;
|
|
51
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
52
|
+
updateDOM(): false;
|
|
53
|
+
getSrc(): string;
|
|
54
|
+
getAltText(): string;
|
|
55
|
+
decorate(): JSX.Element;
|
|
56
|
+
}
|
|
57
|
+
export declare function $createImageNode({ altText, height, maxWidth, src, width, showCaption, caption, key, }: ImagePayload): ImageNode;
|
|
58
|
+
export declare function $isImageNode(node: LexicalNode | null | undefined): node is ImageNode;
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import './ImageNode.css';
|
|
3
|
+
import { AutoFocusPlugin } from '@lexical/react/LexicalAutoFocusPlugin';
|
|
4
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
5
|
+
import { HashtagPlugin } from '@lexical/react/LexicalHashtagPlugin';
|
|
6
|
+
import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
|
|
7
|
+
import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin';
|
|
8
|
+
import { LexicalNestedComposer } from '@lexical/react/LexicalNestedComposer';
|
|
9
|
+
import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
|
|
10
|
+
import { TablePlugin } from '@lexical/react/LexicalTablePlugin';
|
|
11
|
+
import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
|
|
12
|
+
import LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
|
|
13
|
+
import { mergeRegister } from '@lexical/utils';
|
|
14
|
+
import { $createNodeSelection, $getNodeByKey, $getSelection, $isNodeSelection, $setSelection, CLICK_COMMAND, COMMAND_PRIORITY_LOW, createEditor, DecoratorNode, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, SELECTION_CHANGE_COMMAND, } from 'lexical';
|
|
15
|
+
import { Suspense, useCallback, useEffect, useRef, useState } from 'react';
|
|
16
|
+
import ImagesPlugin from '../plugins/ImagesPlugin';
|
|
17
|
+
import ContentEditable from '../ui/ContentEditable';
|
|
18
|
+
import ImageResizer from '../ui/ImageResizer';
|
|
19
|
+
import Placeholder from '../ui/Placeholder';
|
|
20
|
+
import './ImageNode.css';
|
|
21
|
+
const imageCache = new Set();
|
|
22
|
+
function useSuspenseImage(src) {
|
|
23
|
+
if (!imageCache.has(src)) {
|
|
24
|
+
throw new Promise((resolve) => {
|
|
25
|
+
const img = new Image();
|
|
26
|
+
img.src = src;
|
|
27
|
+
img.onload = () => {
|
|
28
|
+
imageCache.add(src);
|
|
29
|
+
resolve(null);
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function convertImageElement(domNode) {
|
|
35
|
+
if (domNode instanceof HTMLImageElement) {
|
|
36
|
+
const { alt: altText, src } = domNode;
|
|
37
|
+
const node = $createImageNode({ altText, src });
|
|
38
|
+
return { node };
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
function LazyImage({ altText, className, imageRef, src, width, height, maxWidth, }) {
|
|
43
|
+
useSuspenseImage(src);
|
|
44
|
+
return (_jsx("img", { className: className || undefined, src: src, alt: altText, ref: imageRef, style: {
|
|
45
|
+
height,
|
|
46
|
+
maxWidth,
|
|
47
|
+
width,
|
|
48
|
+
}, draggable: "false" }));
|
|
49
|
+
}
|
|
50
|
+
function ImageComponent({ src, altText, nodeKey, width, height, maxWidth, resizable, showCaption, caption, }) {
|
|
51
|
+
const imageRef = useRef(null);
|
|
52
|
+
const buttonRef = useRef(null);
|
|
53
|
+
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
|
|
54
|
+
const [isResizing, setIsResizing] = useState(false);
|
|
55
|
+
const [editor] = useLexicalComposerContext();
|
|
56
|
+
const [selection, setSelection] = useState(null);
|
|
57
|
+
const activeEditorRef = useRef(null);
|
|
58
|
+
const onDelete = useCallback((payload) => {
|
|
59
|
+
if (isSelected && $isNodeSelection($getSelection())) {
|
|
60
|
+
const event = payload;
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
const node = $getNodeByKey(nodeKey);
|
|
63
|
+
if ($isImageNode(node)) {
|
|
64
|
+
node.remove();
|
|
65
|
+
}
|
|
66
|
+
setSelected(false);
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}, [isSelected, nodeKey, setSelected]);
|
|
70
|
+
const onEnter = useCallback((event) => {
|
|
71
|
+
const latestSelection = $getSelection();
|
|
72
|
+
const buttonElem = buttonRef.current;
|
|
73
|
+
if (isSelected &&
|
|
74
|
+
$isNodeSelection(latestSelection) &&
|
|
75
|
+
latestSelection.getNodes().length === 1) {
|
|
76
|
+
if (showCaption) {
|
|
77
|
+
// Move focus into nested editor
|
|
78
|
+
$setSelection(null);
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
caption.focus();
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
else if (buttonElem !== null &&
|
|
84
|
+
buttonElem !== document.activeElement) {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
buttonElem.focus();
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}, [caption, isSelected, showCaption]);
|
|
92
|
+
const onEscape = useCallback((event) => {
|
|
93
|
+
if (activeEditorRef.current === caption ||
|
|
94
|
+
buttonRef.current === event.target) {
|
|
95
|
+
$setSelection(null);
|
|
96
|
+
editor.update(() => {
|
|
97
|
+
const nodeSelection = $createNodeSelection();
|
|
98
|
+
nodeSelection.add(nodeKey);
|
|
99
|
+
const parentRootElement = editor.getRootElement();
|
|
100
|
+
if (parentRootElement !== null) {
|
|
101
|
+
parentRootElement.focus();
|
|
102
|
+
}
|
|
103
|
+
$setSelection(nodeSelection);
|
|
104
|
+
});
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}, [caption, editor, nodeKey]);
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
return mergeRegister(editor.registerUpdateListener(({ editorState }) => {
|
|
111
|
+
setSelection(editorState.read(() => $getSelection()));
|
|
112
|
+
}), editor.registerCommand(SELECTION_CHANGE_COMMAND, (_, activeEditor) => {
|
|
113
|
+
activeEditorRef.current = activeEditor;
|
|
114
|
+
return false;
|
|
115
|
+
}, COMMAND_PRIORITY_LOW), editor.registerCommand(CLICK_COMMAND, (payload) => {
|
|
116
|
+
const event = payload;
|
|
117
|
+
if (isResizing) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
if (event.target === imageRef.current) {
|
|
121
|
+
if (!event.shiftKey) {
|
|
122
|
+
clearSelection();
|
|
123
|
+
}
|
|
124
|
+
setSelected(!isSelected);
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
}, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_DELETE_COMMAND, onDelete, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_BACKSPACE_COMMAND, onDelete, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ENTER_COMMAND, onEnter, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ESCAPE_COMMAND, onEscape, COMMAND_PRIORITY_LOW));
|
|
129
|
+
}, [
|
|
130
|
+
clearSelection,
|
|
131
|
+
editor,
|
|
132
|
+
isResizing,
|
|
133
|
+
isSelected,
|
|
134
|
+
nodeKey,
|
|
135
|
+
onDelete,
|
|
136
|
+
onEnter,
|
|
137
|
+
onEscape,
|
|
138
|
+
setSelected,
|
|
139
|
+
]);
|
|
140
|
+
const setShowCaption = () => {
|
|
141
|
+
editor.update(() => {
|
|
142
|
+
const node = $getNodeByKey(nodeKey);
|
|
143
|
+
if ($isImageNode(node)) {
|
|
144
|
+
node.setShowCaption(true);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
const onResizeEnd = (nextWidth, nextHeight) => {
|
|
149
|
+
// Delay hiding the resize bars for click case
|
|
150
|
+
setTimeout(() => {
|
|
151
|
+
setIsResizing(false);
|
|
152
|
+
}, 200);
|
|
153
|
+
editor.update(() => {
|
|
154
|
+
const node = $getNodeByKey(nodeKey);
|
|
155
|
+
if ($isImageNode(node)) {
|
|
156
|
+
node.setWidthAndHeight(nextWidth, nextHeight);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
const onResizeStart = () => {
|
|
161
|
+
setIsResizing(true);
|
|
162
|
+
};
|
|
163
|
+
const draggable = isSelected && $isNodeSelection(selection);
|
|
164
|
+
const isFocused = isSelected || isResizing;
|
|
165
|
+
return (_jsx(Suspense, { fallback: null, children: _jsxs(_Fragment, { children: [_jsx("div", { draggable: draggable, children: _jsx(LazyImage, { className: isFocused
|
|
166
|
+
? `focused ${$isNodeSelection(selection) ? 'draggable' : ''}`
|
|
167
|
+
: null, src: src, altText: altText, imageRef: imageRef, width: width, height: height, maxWidth: maxWidth }) }), showCaption && (_jsx("div", { className: "image-caption-container", children: _jsxs(LexicalNestedComposer, { initialEditor: caption, children: [_jsx(AutoFocusPlugin, {}), _jsx(TablePlugin, {}), _jsx(ImagesPlugin, {}), _jsx(LinkPlugin, {}), _jsx(HashtagPlugin, {}), _jsx(HistoryPlugin, {}), _jsx(RichTextPlugin, { contentEditable: _jsx(ContentEditable, { className: "ImageNode__contentEditable" }), placeholder: _jsx(Placeholder, { className: "ImageNode__placeholder", children: "Enter a caption..." }), ErrorBoundary: LexicalErrorBoundary })] }) })), resizable && $isNodeSelection(selection) && isFocused && (_jsx(ImageResizer, { showCaption: showCaption, setShowCaption: setShowCaption, editor: editor, buttonRef: buttonRef, imageRef: imageRef, maxWidth: maxWidth, onResizeStart: onResizeStart, onResizeEnd: onResizeEnd }))] }) }));
|
|
168
|
+
}
|
|
169
|
+
export class ImageNode extends DecoratorNode {
|
|
170
|
+
__src;
|
|
171
|
+
__altText;
|
|
172
|
+
__width;
|
|
173
|
+
__height;
|
|
174
|
+
__maxWidth;
|
|
175
|
+
__showCaption;
|
|
176
|
+
__caption;
|
|
177
|
+
static getType() {
|
|
178
|
+
return 'image';
|
|
179
|
+
}
|
|
180
|
+
static clone(node) {
|
|
181
|
+
return new ImageNode(node.__src, node.__altText, node.__maxWidth, node.__width, node.__height, node.__showCaption, node.__caption, node.__key);
|
|
182
|
+
}
|
|
183
|
+
static importJSON(serializedNode) {
|
|
184
|
+
const { altText, height, width, maxWidth, caption, src, showCaption } = serializedNode;
|
|
185
|
+
const node = $createImageNode({
|
|
186
|
+
altText,
|
|
187
|
+
height,
|
|
188
|
+
maxWidth,
|
|
189
|
+
showCaption,
|
|
190
|
+
src,
|
|
191
|
+
width,
|
|
192
|
+
});
|
|
193
|
+
const nestedEditor = node.__caption;
|
|
194
|
+
const editorState = nestedEditor.parseEditorState(caption.editorState);
|
|
195
|
+
if (!editorState.isEmpty()) {
|
|
196
|
+
nestedEditor.setEditorState(editorState);
|
|
197
|
+
}
|
|
198
|
+
return node;
|
|
199
|
+
}
|
|
200
|
+
exportDOM() {
|
|
201
|
+
const element = document.createElement('img');
|
|
202
|
+
element.setAttribute('src', this.__src);
|
|
203
|
+
element.setAttribute('alt', this.__altText);
|
|
204
|
+
return { element };
|
|
205
|
+
}
|
|
206
|
+
static importDOM() {
|
|
207
|
+
return {
|
|
208
|
+
img: (node) => ({
|
|
209
|
+
conversion: convertImageElement,
|
|
210
|
+
priority: 0,
|
|
211
|
+
}),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
constructor(src, altText, maxWidth, width, height, showCaption, caption, key) {
|
|
215
|
+
super(key);
|
|
216
|
+
this.__src = src;
|
|
217
|
+
this.__altText = altText;
|
|
218
|
+
this.__maxWidth = maxWidth;
|
|
219
|
+
this.__width = width || 'inherit';
|
|
220
|
+
this.__height = height || 'inherit';
|
|
221
|
+
this.__showCaption = showCaption || false;
|
|
222
|
+
this.__caption = caption || createEditor();
|
|
223
|
+
}
|
|
224
|
+
exportJSON() {
|
|
225
|
+
return {
|
|
226
|
+
altText: this.getAltText(),
|
|
227
|
+
caption: this.__caption.toJSON(),
|
|
228
|
+
height: this.__height === 'inherit' ? 0 : this.__height,
|
|
229
|
+
maxWidth: this.__maxWidth,
|
|
230
|
+
showCaption: this.__showCaption,
|
|
231
|
+
src: this.getSrc(),
|
|
232
|
+
type: 'image',
|
|
233
|
+
version: 1,
|
|
234
|
+
width: this.__width === 'inherit' ? 0 : this.__width,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
setWidthAndHeight(width, height) {
|
|
238
|
+
const writable = this.getWritable();
|
|
239
|
+
writable.__width = width;
|
|
240
|
+
writable.__height = height;
|
|
241
|
+
}
|
|
242
|
+
setShowCaption(showCaption) {
|
|
243
|
+
const writable = this.getWritable();
|
|
244
|
+
writable.__showCaption = showCaption;
|
|
245
|
+
}
|
|
246
|
+
// View
|
|
247
|
+
createDOM(config) {
|
|
248
|
+
const span = document.createElement('span');
|
|
249
|
+
const theme = config.theme;
|
|
250
|
+
const className = theme.image;
|
|
251
|
+
if (className !== undefined) {
|
|
252
|
+
span.className = className;
|
|
253
|
+
}
|
|
254
|
+
return span;
|
|
255
|
+
}
|
|
256
|
+
updateDOM() {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
getSrc() {
|
|
260
|
+
return this.__src;
|
|
261
|
+
}
|
|
262
|
+
getAltText() {
|
|
263
|
+
return this.__altText;
|
|
264
|
+
}
|
|
265
|
+
decorate() {
|
|
266
|
+
return (_jsx(ImageComponent, { src: this.__src, altText: this.__altText, width: this.__width, height: this.__height, maxWidth: this.__maxWidth, nodeKey: this.getKey(), showCaption: this.__showCaption, caption: this.__caption, resizable: true }));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
export function $createImageNode({ altText, height, maxWidth = 500, src, width, showCaption, caption, key, }) {
|
|
270
|
+
return new ImageNode(src, altText, maxWidth, width, height, showCaption, caption, key);
|
|
271
|
+
}
|
|
272
|
+
export function $isImageNode(node) {
|
|
273
|
+
return node instanceof ImageNode;
|
|
274
|
+
}
|
|
275
|
+
//# sourceMappingURL=ImageNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImageNode.js","sourceRoot":"","sources":["../../src/nodes/ImageNode.tsx"],"names":[],"mappings":";AA8BA,OAAO,iBAAiB,CAAC;AAEzB,OAAO,EAAC,eAAe,EAAC,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAC,yBAAyB,EAAC,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAC,aAAa,EAAC,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAC,aAAa,EAAC,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAC,qBAAqB,EAAC,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAC,cAAc,EAAC,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAC,WAAW,EAAC,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAC,uBAAuB,EAAC,MAAM,wCAAwC,CAAC;AAC/E,OAAO,oBAAoB,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,qBAAqB,EACr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,QAAQ,GAAG,GAAG,EACd,GAAG,EACH,KAAK,EACL,WAAW,EACX,OAAO,EACP,GAAG,GACU;IACb,OAAO,IAAI,SAAS,CAClB,GAAG,EACH,OAAO,EACP,QAAQ,EACR,KAAK,EACL,MAAM,EACN,WAAW,EACX,OAAO,EACP,GAAG,CACJ,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,IAAoC;IAEpC,OAAO,IAAI,YAAY,SAAS,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { EditorConfig, LexicalNode, NodeKey, SerializedTextNode, Spread, TextNode } from 'lexical';
|
|
8
|
+
import 'prismjs/components/prism-clike';
|
|
9
|
+
import 'prismjs/components/prism-javascript';
|
|
10
|
+
import 'prismjs/components/prism-markup';
|
|
11
|
+
import 'prismjs/components/prism-markdown';
|
|
12
|
+
import 'prismjs/components/prism-c';
|
|
13
|
+
import 'prismjs/components/prism-css';
|
|
14
|
+
import 'prismjs/components/prism-objectivec';
|
|
15
|
+
import 'prismjs/components/prism-sql';
|
|
16
|
+
import 'prismjs/components/prism-python';
|
|
17
|
+
import 'prismjs/components/prism-rust';
|
|
18
|
+
import 'prismjs/components/prism-swift';
|
|
19
|
+
export declare const DEFAULT_CODE_LANGUAGE = "javascript";
|
|
20
|
+
type SerializedCodeHighlightNode = Spread<{
|
|
21
|
+
highlightType: string | null | undefined;
|
|
22
|
+
type: 'jupyter-code-highlight';
|
|
23
|
+
version: 1;
|
|
24
|
+
}, SerializedTextNode>;
|
|
25
|
+
export declare const CODE_LANGUAGE_FRIENDLY_NAME_MAP: Record<string, string>;
|
|
26
|
+
export declare const CODE_LANGUAGE_MAP: Record<string, string>;
|
|
27
|
+
export declare function normalizeCodeLang(lang: string): string;
|
|
28
|
+
export declare function getLanguageFriendlyName(lang: string): string;
|
|
29
|
+
export declare const getDefaultCodeLanguage: () => string;
|
|
30
|
+
export declare const getCodeLanguages: () => Array<string>;
|
|
31
|
+
/** @noInheritDoc */
|
|
32
|
+
export declare class JupyterCodeHighlightNode extends TextNode {
|
|
33
|
+
/** @internal */
|
|
34
|
+
__highlightType: string | null | undefined;
|
|
35
|
+
constructor(text: string, highlightType?: string | null | undefined, key?: NodeKey);
|
|
36
|
+
static getType(): string;
|
|
37
|
+
static clone(node: JupyterCodeHighlightNode): JupyterCodeHighlightNode;
|
|
38
|
+
getHighlightType(): string | null | undefined;
|
|
39
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
40
|
+
updateDOM(prevNode: JupyterCodeHighlightNode, dom: HTMLElement, config: EditorConfig): boolean;
|
|
41
|
+
static importJSON(serializedNode: SerializedCodeHighlightNode): JupyterCodeHighlightNode;
|
|
42
|
+
exportJSON(): SerializedCodeHighlightNode;
|
|
43
|
+
setFormat(format: number): this;
|
|
44
|
+
}
|
|
45
|
+
export declare function $createJupyterCodeHighlightNode(text: string, highlightType?: string | null | undefined): JupyterCodeHighlightNode;
|
|
46
|
+
export declare function $isJupyterCodeHighlightNode(node: LexicalNode | JupyterCodeHighlightNode | null | undefined): node is JupyterCodeHighlightNode;
|
|
47
|
+
export declare function getFirstJupyterCodeHighlightNodeOfLine(anchor: LexicalNode): JupyterCodeHighlightNode | null | undefined;
|
|
48
|
+
export declare function getLastJupyterCodeHighlightNodeOfLine(anchor: LexicalNode): JupyterCodeHighlightNode | null | undefined;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2023 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the MIT license found in the
|
|
10
|
+
* LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/
|
|
12
|
+
// eslint-disable-next-line simple-import-sort/imports
|
|
13
|
+
import { $isLineBreakNode, TextNode, } from 'lexical';
|
|
14
|
+
import * as Prism from 'prismjs';
|
|
15
|
+
import 'prismjs/components/prism-clike';
|
|
16
|
+
import 'prismjs/components/prism-javascript';
|
|
17
|
+
import 'prismjs/components/prism-markup';
|
|
18
|
+
import 'prismjs/components/prism-markdown';
|
|
19
|
+
import 'prismjs/components/prism-c';
|
|
20
|
+
import 'prismjs/components/prism-css';
|
|
21
|
+
import 'prismjs/components/prism-objectivec';
|
|
22
|
+
import 'prismjs/components/prism-sql';
|
|
23
|
+
import 'prismjs/components/prism-python';
|
|
24
|
+
import 'prismjs/components/prism-rust';
|
|
25
|
+
import 'prismjs/components/prism-swift';
|
|
26
|
+
import { addClassNamesToElement, removeClassNamesFromElement, } from '@lexical/utils';
|
|
27
|
+
export const DEFAULT_CODE_LANGUAGE = 'javascript';
|
|
28
|
+
export const CODE_LANGUAGE_FRIENDLY_NAME_MAP = {
|
|
29
|
+
c: 'C',
|
|
30
|
+
clike: 'C-like',
|
|
31
|
+
css: 'CSS',
|
|
32
|
+
html: 'HTML',
|
|
33
|
+
js: 'JavaScript',
|
|
34
|
+
markdown: 'Markdown',
|
|
35
|
+
objc: 'Objective-C',
|
|
36
|
+
plain: 'Plain Text',
|
|
37
|
+
py: 'Python',
|
|
38
|
+
rust: 'Rust',
|
|
39
|
+
sql: 'SQL',
|
|
40
|
+
swift: 'Swift',
|
|
41
|
+
xml: 'XML',
|
|
42
|
+
};
|
|
43
|
+
export const CODE_LANGUAGE_MAP = {
|
|
44
|
+
javascript: 'js',
|
|
45
|
+
md: 'markdown',
|
|
46
|
+
plaintext: 'plain',
|
|
47
|
+
python: 'py',
|
|
48
|
+
text: 'plain',
|
|
49
|
+
};
|
|
50
|
+
export function normalizeCodeLang(lang) {
|
|
51
|
+
return CODE_LANGUAGE_MAP[lang] || lang;
|
|
52
|
+
}
|
|
53
|
+
export function getLanguageFriendlyName(lang) {
|
|
54
|
+
const _lang = normalizeCodeLang(lang);
|
|
55
|
+
return CODE_LANGUAGE_FRIENDLY_NAME_MAP[_lang] || _lang;
|
|
56
|
+
}
|
|
57
|
+
export const getDefaultCodeLanguage = () => DEFAULT_CODE_LANGUAGE;
|
|
58
|
+
export const getCodeLanguages = () => Object.keys(Prism.languages)
|
|
59
|
+
.filter(
|
|
60
|
+
// Prism has several language helpers mixed into languages object
|
|
61
|
+
// so filtering them out here to get langs list
|
|
62
|
+
(language) => typeof Prism.languages[language] !== 'function')
|
|
63
|
+
.sort();
|
|
64
|
+
/** @noInheritDoc */
|
|
65
|
+
export class JupyterCodeHighlightNode extends TextNode {
|
|
66
|
+
/** @internal */
|
|
67
|
+
__highlightType;
|
|
68
|
+
constructor(text, highlightType, key) {
|
|
69
|
+
super(text, key);
|
|
70
|
+
this.__highlightType = highlightType;
|
|
71
|
+
}
|
|
72
|
+
static getType() {
|
|
73
|
+
return 'jupyter-code-highlight';
|
|
74
|
+
}
|
|
75
|
+
static clone(node) {
|
|
76
|
+
return new JupyterCodeHighlightNode(node.__text, node.__highlightType || undefined, node.__key);
|
|
77
|
+
}
|
|
78
|
+
getHighlightType() {
|
|
79
|
+
const self = this.getLatest();
|
|
80
|
+
return self.__highlightType;
|
|
81
|
+
}
|
|
82
|
+
createDOM(config) {
|
|
83
|
+
const element = super.createDOM(config);
|
|
84
|
+
const className = getHighlightThemeClass(config.theme, this.__highlightType);
|
|
85
|
+
addClassNamesToElement(element, className);
|
|
86
|
+
return element;
|
|
87
|
+
}
|
|
88
|
+
updateDOM(prevNode, dom, config) {
|
|
89
|
+
const update = super.updateDOM(prevNode, dom, config);
|
|
90
|
+
const prevClassName = getHighlightThemeClass(config.theme, prevNode.__highlightType);
|
|
91
|
+
const nextClassName = getHighlightThemeClass(config.theme, this.__highlightType);
|
|
92
|
+
if (prevClassName !== nextClassName) {
|
|
93
|
+
if (prevClassName) {
|
|
94
|
+
removeClassNamesFromElement(dom, prevClassName);
|
|
95
|
+
}
|
|
96
|
+
if (nextClassName) {
|
|
97
|
+
addClassNamesToElement(dom, nextClassName);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return update;
|
|
101
|
+
}
|
|
102
|
+
static importJSON(serializedNode) {
|
|
103
|
+
const node = $createJupyterCodeHighlightNode(serializedNode.text, serializedNode.highlightType);
|
|
104
|
+
node.setFormat(serializedNode.format);
|
|
105
|
+
node.setDetail(serializedNode.detail);
|
|
106
|
+
node.setMode(serializedNode.mode);
|
|
107
|
+
node.setStyle(serializedNode.style);
|
|
108
|
+
return node;
|
|
109
|
+
}
|
|
110
|
+
exportJSON() {
|
|
111
|
+
return {
|
|
112
|
+
...super.exportJSON(),
|
|
113
|
+
highlightType: this.getHighlightType(),
|
|
114
|
+
type: 'jupyter-code-highlight',
|
|
115
|
+
version: 1,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
// Prevent formatting (bold, underline, etc)
|
|
119
|
+
setFormat(format) {
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function getHighlightThemeClass(theme, highlightType) {
|
|
124
|
+
return (highlightType &&
|
|
125
|
+
theme &&
|
|
126
|
+
theme.codeHighlight &&
|
|
127
|
+
theme.codeHighlight[highlightType]);
|
|
128
|
+
}
|
|
129
|
+
export function $createJupyterCodeHighlightNode(text, highlightType) {
|
|
130
|
+
return new JupyterCodeHighlightNode(text, highlightType);
|
|
131
|
+
}
|
|
132
|
+
export function $isJupyterCodeHighlightNode(node) {
|
|
133
|
+
return node instanceof JupyterCodeHighlightNode;
|
|
134
|
+
}
|
|
135
|
+
export function getFirstJupyterCodeHighlightNodeOfLine(anchor) {
|
|
136
|
+
let currentNode = null;
|
|
137
|
+
const previousSiblings = anchor.getPreviousSiblings();
|
|
138
|
+
previousSiblings.push(anchor);
|
|
139
|
+
while (previousSiblings.length > 0) {
|
|
140
|
+
const node = previousSiblings.pop();
|
|
141
|
+
if ($isJupyterCodeHighlightNode(node)) {
|
|
142
|
+
currentNode = node;
|
|
143
|
+
}
|
|
144
|
+
if ($isLineBreakNode(node)) {
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return currentNode;
|
|
149
|
+
}
|
|
150
|
+
export function getLastJupyterCodeHighlightNodeOfLine(anchor) {
|
|
151
|
+
let currentNode = null;
|
|
152
|
+
const nextSiblings = anchor.getNextSiblings();
|
|
153
|
+
nextSiblings.unshift(anchor);
|
|
154
|
+
while (nextSiblings.length > 0) {
|
|
155
|
+
const node = nextSiblings.shift();
|
|
156
|
+
if ($isJupyterCodeHighlightNode(node)) {
|
|
157
|
+
currentNode = node;
|
|
158
|
+
}
|
|
159
|
+
if ($isLineBreakNode(node)) {
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return currentNode;
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=JupyterCodeHighlightNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JupyterCodeHighlightNode.js","sourceRoot":"","sources":["../../src/nodes/JupyterCodeHighlightNode.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AAEH,sDAAsD;AACtD,OAAO,EACL,gBAAgB,EAOhB,QAAQ,GACT,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,gCAAgC,CAAC;AACxC,OAAO,qCAAqC,CAAC;AAC7C,OAAO,iCAAiC,CAAC;AACzC,OAAO,mCAAmC,CAAC;AAC3C,OAAO,4BAA4B,CAAC;AACpC,OAAO,8BAA8B,CAAC;AACtC,OAAO,qCAAqC,CAAC;AAC7C,OAAO,8BAA8B,CAAC;AACtC,OAAO,iCAAiC,CAAC;AACzC,OAAO,+BAA+B,CAAC;AACvC,OAAO,gCA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,OAAO,IAAI,YAAY,wBAAwB,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,sCAAsC,CACpD,MAAmB;IAEnB,IAAI,WAAW,GAAG,IAAI,CAAC;IACvB,MAAM,gBAAgB,GAAG,MAAM,CAAC,mBAAmB,EAAE,CAAC;IACtD,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9B,OAAO,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;QAClC,MAAM,IAAI,GAAG,gBAAgB,CAAC,GAAG,EAAE,CAAC;QACpC,IAAI,2BAA2B,CAAC,IAAI,CAAC,EAAE;YACrC,WAAW,GAAG,IAAI,CAAC;SACpB;QACD,IAAI,gBAAgB,CAAC,IAAI,CAAC,EAAE;YAC1B,MAAM;SACP;KACF;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,qCAAqC,CACnD,MAAmB;IAEnB,IAAI,WAAW,GAAG,IAAI,CAAC;IACvB,MAAM,YAAY,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAC9C,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B,OAAO,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;QAC9B,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC;QAClC,IAAI,2BAA2B,CAAC,IAAI,CAAC,EAAE;YACrC,WAAW,GAAG,IAAI,CAAC;SACpB;QACD,IAAI,gBAAgB,CAAC,IAAI,CAAC,EAAE;YAC1B,MAAM;SACP;KACF;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { LexicalEditor, LexicalNode } from 'lexical';
|
|
8
|
+
import 'prismjs/components/prism-clike';
|
|
9
|
+
import 'prismjs/components/prism-javascript';
|
|
10
|
+
import 'prismjs/components/prism-markup';
|
|
11
|
+
import 'prismjs/components/prism-markdown';
|
|
12
|
+
import 'prismjs/components/prism-c';
|
|
13
|
+
import 'prismjs/components/prism-css';
|
|
14
|
+
import 'prismjs/components/prism-objectivec';
|
|
15
|
+
import 'prismjs/components/prism-sql';
|
|
16
|
+
import 'prismjs/components/prism-python';
|
|
17
|
+
import 'prismjs/components/prism-rust';
|
|
18
|
+
import 'prismjs/components/prism-swift';
|
|
19
|
+
import { TextNode } from 'lexical';
|
|
20
|
+
export declare function getStartOfCodeInLine(anchor: LexicalNode): {
|
|
21
|
+
node: TextNode | null;
|
|
22
|
+
offset: number;
|
|
23
|
+
};
|
|
24
|
+
export declare function getEndOfJupyterCodeInLine(anchor: LexicalNode): {
|
|
25
|
+
node: TextNode | null;
|
|
26
|
+
offset: number;
|
|
27
|
+
};
|
|
28
|
+
export declare function registerCodeHighlighting(editor: LexicalEditor): () => void;
|