@mdxeditor/editor 0.8.0 → 0.10.0-alpha.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/README.md +2 -2
- package/dist/FormatConstants.d.ts +9 -0
- package/dist/FormatConstants.js +10 -0
- package/dist/MDXEditor.d.ts +31 -0
- package/dist/MDXEditor.js +105 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +4 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +29 -0
- package/dist/directive-editors/GenericDirectiveEditor.d.ts +3 -0
- package/dist/directive-editors/GenericDirectiveEditor.js +32 -0
- package/dist/exportMarkdownFromLexical.d.ts +114 -0
- package/dist/exportMarkdownFromLexical.js +199 -0
- package/dist/gurx/index.d.ts +3 -0
- package/dist/gurx/react.d.ts +121 -0
- package/dist/gurx/react.js +112 -0
- package/dist/gurx/realm.d.ts +133 -0
- package/dist/gurx/realm.js +491 -0
- package/dist/gurx/realmFactory.d.ts +58 -0
- package/dist/gurx/realmFactory.js +28 -0
- package/dist/icons/add_column.svg.js +8 -0
- package/dist/icons/add_photo.svg.js +8 -0
- package/dist/icons/add_row.svg.js +8 -0
- package/dist/icons/arrow_drop_down.svg.js +8 -0
- package/dist/icons/arrow_right.svg.js +8 -0
- package/dist/icons/check.svg.js +8 -0
- package/dist/icons/close.svg.js +8 -0
- package/dist/icons/code.svg.js +8 -0
- package/dist/icons/content_copy.svg.js +8 -0
- package/dist/icons/delete.svg.js +8 -0
- package/dist/icons/delete_small.svg.js +8 -0
- package/dist/icons/deployed_code.svg.js +8 -0
- package/dist/icons/difference.svg.js +8 -0
- package/dist/icons/edit.svg.js +8 -0
- package/dist/icons/emergency_home.svg.js +8 -0
- package/dist/icons/format_align_center.svg.js +8 -0
- package/dist/icons/format_align_left.svg.js +8 -0
- package/dist/icons/format_align_right.svg.js +8 -0
- package/dist/icons/format_bold.svg.js +8 -0
- package/dist/icons/format_italic.svg.js +8 -0
- package/dist/icons/format_list_bulleted.svg.js +8 -0
- package/dist/icons/format_list_numbered.svg.js +8 -0
- package/dist/icons/format_underlined.svg.js +8 -0
- package/dist/icons/frame_source.svg.js +8 -0
- package/dist/icons/frontmatter.svg.js +8 -0
- package/dist/icons/horizontal_rule.svg.js +8 -0
- package/dist/icons/insert_col_left.svg.js +8 -0
- package/dist/icons/insert_col_right.svg.js +8 -0
- package/dist/icons/insert_row_above.svg.js +8 -0
- package/dist/icons/insert_row_below.svg.js +8 -0
- package/dist/icons/link.svg.js +8 -0
- package/dist/icons/link_off.svg.js +8 -0
- package/dist/icons/markdown.svg.js +8 -0
- package/dist/icons/more_horiz.svg.js +8 -0
- package/dist/icons/open_in_new.svg.js +8 -0
- package/dist/icons/redo.svg.js +8 -0
- package/dist/icons/rich_text.svg.js +8 -0
- package/dist/icons/settings.svg.js +8 -0
- package/dist/icons/table.svg.js +8 -0
- package/dist/icons/undo.svg.js +8 -0
- package/dist/importMarkdownToLexical.d.ts +84 -0
- package/dist/importMarkdownToLexical.js +65 -0
- package/dist/index.d.ts +49 -973
- package/dist/index.js +133 -66
- package/dist/jsx-editors/GenericJsxEditor.d.ts +3 -0
- package/dist/jsx-editors/GenericJsxEditor.js +56 -0
- package/dist/node_modules/react-diff-view/style/index.css.js +4 -0
- package/dist/plugins/codeblock/CodeBlockNode.d.ts +99 -0
- package/dist/plugins/codeblock/CodeBlockNode.js +155 -0
- package/dist/plugins/codeblock/CodeBlockVisitor.d.ts +4 -0
- package/dist/plugins/codeblock/CodeBlockVisitor.js +14 -0
- package/dist/plugins/codeblock/MdastCodeVisitor.d.ts +3 -0
- package/dist/plugins/codeblock/MdastCodeVisitor.js +16 -0
- package/dist/plugins/codeblock/index.d.ts +604 -0
- package/dist/plugins/codeblock/index.js +73 -0
- package/dist/plugins/codemirror/CodeMirrorEditor.d.ts +3 -0
- package/dist/plugins/codemirror/CodeMirrorEditor.js +33 -0
- package/dist/plugins/codemirror/index.d.ts +786 -0
- package/dist/plugins/codemirror/index.js +62 -0
- package/dist/plugins/core/LexicalLinebreakVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalLinebreakVisitor.js +10 -0
- package/dist/plugins/core/LexicalParagraphVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalParagraphVisitor.js +10 -0
- package/dist/plugins/core/LexicalRootVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalRootVisitor.js +10 -0
- package/dist/plugins/core/LexicalTextVisitor.d.ts +5 -0
- package/dist/plugins/core/LexicalTextVisitor.js +85 -0
- package/dist/plugins/core/MdastFormattingVisitor.d.ts +4 -0
- package/dist/plugins/core/MdastFormattingVisitor.js +36 -0
- package/dist/plugins/core/MdastInlineCodeVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastInlineCodeVisitor.js +11 -0
- package/dist/plugins/core/MdastParagraphVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastParagraphVisitor.js +15 -0
- package/dist/plugins/core/MdastRootVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastRootVisitor.js +9 -0
- package/dist/plugins/core/MdastTextVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastTextVisitor.js +10 -0
- package/dist/plugins/core/NestedLexicalEditor.d.ts +69 -0
- package/dist/plugins/core/NestedLexicalEditor.js +181 -0
- package/dist/plugins/core/PropertyPopover.d.ts +8 -0
- package/dist/plugins/core/PropertyPopover.js +36 -0
- package/dist/plugins/core/SharedHistoryPlugin.d.ts +2 -0
- package/dist/plugins/core/SharedHistoryPlugin.js +10 -0
- package/dist/plugins/core/index.d.ts +419 -0
- package/dist/plugins/core/index.js +343 -0
- package/dist/plugins/core/ui/PopoverUtils.d.ts +4 -0
- package/dist/plugins/core/ui/PopoverUtils.js +17 -0
- package/dist/plugins/diff-source/DiffSourceWrapper.d.ts +4 -0
- package/dist/plugins/diff-source/DiffSourceWrapper.js +11 -0
- package/dist/plugins/diff-source/DiffViewer.d.ts +2 -0
- package/dist/plugins/diff-source/DiffViewer.js +18 -0
- package/dist/plugins/diff-source/SourceEditor.d.ts +2 -0
- package/dist/plugins/diff-source/SourceEditor.js +25 -0
- package/dist/plugins/diff-source/index.d.ts +530 -0
- package/dist/plugins/diff-source/index.js +55 -0
- package/dist/plugins/directives/DirectiveNode.d.ts +51 -0
- package/dist/plugins/directives/DirectiveNode.js +92 -0
- package/dist/plugins/directives/DirectiveVisitor.d.ts +4 -0
- package/dist/plugins/directives/DirectiveVisitor.js +10 -0
- package/dist/plugins/directives/MdastDirectiveVisitor.d.ts +3 -0
- package/dist/plugins/directives/MdastDirectiveVisitor.js +13 -0
- package/dist/plugins/directives/index.d.ts +591 -0
- package/dist/plugins/directives/index.js +53 -0
- package/dist/plugins/frontmatter/FrontmatterEditor.d.ts +6 -0
- package/dist/plugins/frontmatter/FrontmatterEditor.js +69 -0
- package/dist/plugins/frontmatter/FrontmatterNode.d.ts +35 -0
- package/dist/plugins/frontmatter/FrontmatterNode.js +71 -0
- package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.d.ts +4 -0
- package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.js +10 -0
- package/dist/plugins/frontmatter/MdastFrontmatterVisitor.d.ts +3 -0
- package/dist/plugins/frontmatter/MdastFrontmatterVisitor.js +10 -0
- package/dist/plugins/frontmatter/index.d.ts +510 -0
- package/dist/plugins/frontmatter/index.js +53 -0
- package/dist/plugins/headings/LexicalHeadingVisitor.d.ts +4 -0
- package/dist/plugins/headings/LexicalHeadingVisitor.js +11 -0
- package/dist/plugins/headings/MdastHeadingVisitor.d.ts +3 -0
- package/dist/plugins/headings/MdastHeadingVisitor.js +10 -0
- package/dist/plugins/headings/index.d.ts +105 -0
- package/dist/plugins/headings/index.js +20 -0
- package/dist/plugins/image/ImageEditor.d.ts +7 -0
- package/dist/{ImageEditor-5f203a1c.js → plugins/image/ImageEditor.js} +12 -46
- package/dist/plugins/image/ImageNode.d.ts +53 -0
- package/dist/plugins/image/ImageNode.js +108 -0
- package/dist/plugins/image/LexicalImageVisitor.d.ts +4 -0
- package/dist/plugins/image/LexicalImageVisitor.js +15 -0
- package/dist/plugins/image/MdastImageVisitor.d.ts +3 -0
- package/dist/plugins/image/MdastImageVisitor.js +16 -0
- package/dist/plugins/image/index.d.ts +541 -0
- package/dist/plugins/image/index.js +244 -0
- package/dist/plugins/jsx/LexicalJsxNode.d.ts +54 -0
- package/dist/plugins/jsx/LexicalJsxNode.js +99 -0
- package/dist/plugins/jsx/LexicalJsxVisitor.d.ts +4 -0
- package/dist/plugins/jsx/LexicalJsxVisitor.js +12 -0
- package/dist/plugins/jsx/MdastMdxJsEsmVisitor.d.ts +3 -0
- package/dist/plugins/jsx/MdastMdxJsEsmVisitor.js +8 -0
- package/dist/plugins/jsx/MdastMdxJsxElementVisitor.d.ts +3 -0
- package/dist/plugins/jsx/MdastMdxJsxElementVisitor.js +12 -0
- package/dist/plugins/jsx/index.d.ts +461 -0
- package/dist/plugins/jsx/index.js +37 -0
- package/dist/plugins/link/LexicalLinkVisitor.d.ts +4 -0
- package/dist/plugins/link/LexicalLinkVisitor.js +10 -0
- package/dist/plugins/link/MdastLinkVisitor.d.ts +3 -0
- package/dist/plugins/link/MdastLinkVisitor.js +14 -0
- package/dist/plugins/link/index.d.ts +108 -0
- package/dist/plugins/link/index.js +24 -0
- package/dist/plugins/link-dialog/LinkDialog.d.ts +12 -0
- package/dist/plugins/link-dialog/LinkDialog.js +174 -0
- package/dist/plugins/link-dialog/index.d.ts +496 -0
- package/dist/plugins/link-dialog/index.js +242 -0
- package/dist/plugins/lists/LexicalListItemVisitor.d.ts +4 -0
- package/dist/plugins/lists/LexicalListItemVisitor.js +22 -0
- package/dist/plugins/lists/LexicalListVisitor.d.ts +4 -0
- package/dist/plugins/lists/LexicalListVisitor.js +14 -0
- package/dist/plugins/lists/MdastListItemVisitor.d.ts +3 -0
- package/dist/plugins/lists/MdastListItemVisitor.js +10 -0
- package/dist/plugins/lists/MdastListVisitor.d.ts +3 -0
- package/dist/plugins/lists/MdastListVisitor.js +18 -0
- package/dist/plugins/lists/index.d.ts +521 -0
- package/dist/plugins/lists/index.js +111 -0
- package/dist/plugins/markdown-shortcut/index.d.ts +51 -0
- package/dist/plugins/markdown-shortcut/index.js +34 -0
- package/dist/plugins/quote/LexicalQuoteVisitor.d.ts +4 -0
- package/dist/plugins/quote/LexicalQuoteVisitor.js +14 -0
- package/dist/plugins/quote/MdastBlockQuoteVisitor.d.ts +3 -0
- package/dist/plugins/quote/MdastBlockQuoteVisitor.js +10 -0
- package/dist/plugins/quote/index.d.ts +348 -0
- package/dist/plugins/quote/index.js +26 -0
- package/dist/plugins/sandpack/SandpackEditor.d.ts +7 -0
- package/dist/plugins/sandpack/SandpackEditor.js +35 -0
- package/dist/plugins/sandpack/index.d.ts +826 -0
- package/dist/plugins/sandpack/index.js +93 -0
- package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
- package/dist/{useCodeMirrorRef-ff0c2781.js → plugins/sandpack/useCodeMirrorRef.js} +22 -10
- package/dist/plugins/table/LexicalTableVisitor.d.ts +4 -0
- package/dist/plugins/table/LexicalTableVisitor.js +10 -0
- package/dist/plugins/table/MdastTableVisitor.d.ts +3 -0
- package/dist/plugins/table/MdastTableVisitor.js +10 -0
- package/dist/plugins/table/TableEditor.d.ts +21 -0
- package/dist/{TableEditor-bb94be2b.js → plugins/table/TableEditor.js} +109 -161
- package/dist/plugins/table/TableNode.d.ts +52 -0
- package/dist/plugins/table/TableNode.js +147 -0
- package/dist/plugins/table/index.d.ts +511 -0
- package/dist/plugins/table/index.js +59 -0
- package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.d.ts +4 -0
- package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +10 -0
- package/dist/plugins/thematic-break/MdastThematicBreakVisitor.d.ts +3 -0
- package/dist/plugins/thematic-break/MdastThematicBreakVisitor.js +10 -0
- package/dist/plugins/thematic-break/index.d.ts +510 -0
- package/dist/plugins/thematic-break/index.js +39 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +2 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.js +52 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +2 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +35 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +2 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +30 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +2 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +32 -0
- package/dist/plugins/toolbar/components/CodeToggle.d.ts +2 -0
- package/dist/plugins/toolbar/components/CodeToggle.js +20 -0
- package/dist/plugins/toolbar/components/CreateLink.d.ts +2 -0
- package/dist/plugins/toolbar/components/CreateLink.js +11 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +4 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +27 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +2 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.js +29 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +2 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.js +20 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +2 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.js +11 -0
- package/dist/plugins/toolbar/components/InsertImage.d.ts +2 -0
- package/dist/plugins/toolbar/components/InsertImage.js +23 -0
- package/dist/plugins/toolbar/components/InsertSandpack.d.ts +2 -0
- package/dist/plugins/toolbar/components/InsertSandpack.js +13 -0
- package/dist/plugins/toolbar/components/InsertTable.d.ts +2 -0
- package/dist/plugins/toolbar/components/InsertTable.js +20 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +2 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.js +11 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +2 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +58 -0
- package/dist/plugins/toolbar/components/ListsToggle.d.ts +2 -0
- package/dist/plugins/toolbar/components/ListsToggle.js +23 -0
- package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +2 -0
- package/dist/plugins/toolbar/components/ShowSandpackInfo.js +32 -0
- package/dist/plugins/toolbar/components/UndoRedo.d.ts +2 -0
- package/dist/plugins/toolbar/components/UndoRedo.js +59 -0
- package/dist/plugins/toolbar/index.d.ts +416 -0
- package/dist/plugins/toolbar/index.js +39 -0
- package/dist/plugins/toolbar/primitives/DialogButton.d.ts +40 -0
- package/dist/plugins/toolbar/primitives/DialogButton.js +115 -0
- package/dist/plugins/toolbar/primitives/TooltipWrap.d.ts +5 -0
- package/dist/plugins/toolbar/primitives/TooltipWrap.js +12 -0
- package/dist/plugins/toolbar/primitives/select.d.ts +31 -0
- package/dist/plugins/toolbar/primitives/select.js +44 -0
- package/dist/plugins/toolbar/primitives/toolbar.d.ts +85 -0
- package/dist/plugins/toolbar/primitives/toolbar.js +111 -0
- package/dist/style.css +480 -240
- package/dist/styles/globals.css.js +4 -0
- package/dist/styles/lexical-theme.module.css.js +53 -0
- package/dist/styles/lexicalTheme.d.ts +2 -0
- package/dist/styles/lexicalTheme.js +28 -0
- package/dist/styles/ui.module.css.js +227 -0
- package/dist/utils/detectMac.d.ts +2 -0
- package/dist/utils/detectMac.js +6 -0
- package/dist/utils/fp.d.ts +47 -0
- package/dist/utils/fp.js +10 -0
- package/dist/utils/isPartOftheEditorUI.d.ts +1 -0
- package/dist/utils/isPartOftheEditorUI.js +12 -0
- package/dist/utils/lexicalHelpers.d.ts +11 -0
- package/dist/utils/lexicalHelpers.js +49 -0
- package/dist/utils/uuid4.d.ts +1 -0
- package/dist/utils/uuid4.js +10 -0
- package/dist/utils/voidEmitter.d.ts +14 -0
- package/dist/utils/voidEmitter.js +15 -0
- package/package.json +184 -14
- package/dist/CodeBlockEditor-59b65408.js +0 -78
- package/dist/CodeBlockEditor-5ae8b0a9.cjs +0 -1
- package/dist/FrontmatterEditor-2b27f5a7.js +0 -117
- package/dist/FrontmatterEditor-74ad4eb7.cjs +0 -1
- package/dist/ImageEditor-e5fd6b26.cjs +0 -1
- package/dist/JsxEditor-95724372.cjs +0 -1
- package/dist/JsxEditor-f061cc75.js +0 -108
- package/dist/SandpackEditor-37261889.cjs +0 -1
- package/dist/SandpackEditor-ce901c3c.js +0 -98
- package/dist/SourceEditor-6135bf63.cjs +0 -1
- package/dist/SourceEditor-e499b8bb.js +0 -63
- package/dist/TableEditor-4d00f956.cjs +0 -1
- package/dist/index-383c60bb.cjs +0 -1
- package/dist/index-470693d8.js +0 -4095
- package/dist/index.cjs +0 -1
- package/dist/useCodeMirrorRef-72d8430b.cjs +0 -1
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { $wrapNodeInElement } from "@lexical/utils";
|
|
2
|
+
import { createCommand, $insertNodes, $isRootOrShadowRoot, $createParagraphNode, COMMAND_PRIORITY_EDITOR, DRAGSTART_COMMAND, COMMAND_PRIORITY_HIGH, DRAGOVER_COMMAND, COMMAND_PRIORITY_LOW, DROP_COMMAND, PASTE_COMMAND, COMMAND_PRIORITY_CRITICAL, $createRangeSelection, $setSelection, $getSelection, $isNodeSelection } from "lexical";
|
|
3
|
+
import { coreSystem } from "../core/index.js";
|
|
4
|
+
import { $createImageNode, $isImageNode, ImageNode } from "./ImageNode.js";
|
|
5
|
+
import { LexicalImageVisitor } from "./LexicalImageVisitor.js";
|
|
6
|
+
import { MdastImageVisitor } from "./MdastImageVisitor.js";
|
|
7
|
+
import { CAN_USE_DOM } from "../../utils/detectMac.js";
|
|
8
|
+
import { system } from "../../gurx/realmFactory.js";
|
|
9
|
+
import { realmPlugin } from "../../gurx/react.js";
|
|
10
|
+
const imageSystem = system(
|
|
11
|
+
(r, [{ rootEditor }]) => {
|
|
12
|
+
const insertImage = r.node();
|
|
13
|
+
const imageAutocompleteSuggestions = r.node([]);
|
|
14
|
+
const imageUploadHandler = r.node((_) => {
|
|
15
|
+
throw new Error("Image upload handling is not implemented");
|
|
16
|
+
});
|
|
17
|
+
r.sub(r.pipe(insertImage, r.o.withLatestFrom(rootEditor)), ([src, theEditor]) => {
|
|
18
|
+
theEditor == null ? void 0 : theEditor.update(() => {
|
|
19
|
+
const imageNode = $createImageNode({ altText: "", src, title: "" });
|
|
20
|
+
$insertNodes([imageNode]);
|
|
21
|
+
if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
|
|
22
|
+
$wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
r.sub(rootEditor, (editor) => {
|
|
27
|
+
editor == null ? void 0 : editor.registerCommand(
|
|
28
|
+
INSERT_IMAGE_COMMAND,
|
|
29
|
+
(payload) => {
|
|
30
|
+
const imageNode = $createImageNode(payload);
|
|
31
|
+
$insertNodes([imageNode]);
|
|
32
|
+
if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
|
|
33
|
+
$wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
},
|
|
37
|
+
COMMAND_PRIORITY_EDITOR
|
|
38
|
+
);
|
|
39
|
+
editor == null ? void 0 : editor.registerCommand(
|
|
40
|
+
DRAGSTART_COMMAND,
|
|
41
|
+
(event) => {
|
|
42
|
+
return onDragStart(event);
|
|
43
|
+
},
|
|
44
|
+
COMMAND_PRIORITY_HIGH
|
|
45
|
+
);
|
|
46
|
+
editor == null ? void 0 : editor.registerCommand(
|
|
47
|
+
DRAGOVER_COMMAND,
|
|
48
|
+
(event) => {
|
|
49
|
+
return onDragover(event);
|
|
50
|
+
},
|
|
51
|
+
COMMAND_PRIORITY_LOW
|
|
52
|
+
);
|
|
53
|
+
editor == null ? void 0 : editor.registerCommand(
|
|
54
|
+
DROP_COMMAND,
|
|
55
|
+
(event) => {
|
|
56
|
+
return onDrop(event, editor, r.getValue(imageUploadHandler));
|
|
57
|
+
},
|
|
58
|
+
COMMAND_PRIORITY_HIGH
|
|
59
|
+
);
|
|
60
|
+
editor == null ? void 0 : editor.registerCommand(
|
|
61
|
+
PASTE_COMMAND,
|
|
62
|
+
(event) => {
|
|
63
|
+
var _a;
|
|
64
|
+
let cbPayload = Array.from(((_a = event.clipboardData) == null ? void 0 : _a.items) || []);
|
|
65
|
+
cbPayload = cbPayload.filter((i) => /image/.test(i.type));
|
|
66
|
+
if (!cbPayload.length || cbPayload.length === 0) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const imageUploadHandlerValue = r.getValue(imageUploadHandler);
|
|
70
|
+
Promise.all(cbPayload.map((file) => imageUploadHandlerValue(file.getAsFile()))).then((urls) => {
|
|
71
|
+
urls.forEach((url) => {
|
|
72
|
+
r.pub(insertImage, url);
|
|
73
|
+
});
|
|
74
|
+
}).catch((e) => {
|
|
75
|
+
throw e;
|
|
76
|
+
});
|
|
77
|
+
return true;
|
|
78
|
+
},
|
|
79
|
+
COMMAND_PRIORITY_CRITICAL
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
imageUploadHandler,
|
|
84
|
+
imageAutocompleteSuggestions,
|
|
85
|
+
insertImage
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
[coreSystem]
|
|
89
|
+
);
|
|
90
|
+
const defaultParams = {
|
|
91
|
+
imageUploadHandler: () => {
|
|
92
|
+
throw new Error("Image upload handling is not implemented");
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const [
|
|
96
|
+
/** @internal */
|
|
97
|
+
imagePlugin,
|
|
98
|
+
/** @internal */
|
|
99
|
+
imagePluginHooks
|
|
100
|
+
] = realmPlugin({
|
|
101
|
+
id: "image",
|
|
102
|
+
systemSpec: imageSystem,
|
|
103
|
+
applyParamsToSystem: (realm, params = defaultParams) => {
|
|
104
|
+
realm.pubKey("imageUploadHandler", params.imageUploadHandler);
|
|
105
|
+
realm.pubKey("imageAutocompleteSuggestions", params.imageAutocompleteSuggestions || []);
|
|
106
|
+
},
|
|
107
|
+
init: (realm) => {
|
|
108
|
+
realm.pubKey("addImportVisitor", MdastImageVisitor);
|
|
109
|
+
realm.pubKey("addLexicalNode", ImageNode);
|
|
110
|
+
realm.pubKey("addExportVisitor", LexicalImageVisitor);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
const getDOMSelection = (targetWindow) => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
|
|
114
|
+
const INSERT_IMAGE_COMMAND = createCommand("INSERT_IMAGE_COMMAND");
|
|
115
|
+
const TRANSPARENT_IMAGE = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
|
|
116
|
+
function onDragStart(event) {
|
|
117
|
+
const node = getImageNodeInSelection();
|
|
118
|
+
if (!node) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
const dataTransfer = event.dataTransfer;
|
|
122
|
+
if (!dataTransfer) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
dataTransfer.setData("text/plain", "_");
|
|
126
|
+
const img = document.createElement("img");
|
|
127
|
+
img.src = TRANSPARENT_IMAGE;
|
|
128
|
+
dataTransfer.setDragImage(img, 0, 0);
|
|
129
|
+
dataTransfer.setData(
|
|
130
|
+
"application/x-lexical-drag",
|
|
131
|
+
JSON.stringify({
|
|
132
|
+
data: {
|
|
133
|
+
altText: node.__altText,
|
|
134
|
+
title: node.__title,
|
|
135
|
+
key: node.getKey(),
|
|
136
|
+
src: node.__src
|
|
137
|
+
},
|
|
138
|
+
type: "image"
|
|
139
|
+
})
|
|
140
|
+
);
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
function onDragover(event) {
|
|
144
|
+
var _a;
|
|
145
|
+
let cbPayload = Array.from(((_a = event.dataTransfer) == null ? void 0 : _a.items) || []);
|
|
146
|
+
cbPayload = cbPayload.filter((i) => /image/.test(i.type));
|
|
147
|
+
if (cbPayload.length > 0) {
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
const node = getImageNodeInSelection();
|
|
152
|
+
if (!node) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
if (!canDropImage(event)) {
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
function onDrop(event, editor, imageUploadHandler) {
|
|
161
|
+
var _a;
|
|
162
|
+
let cbPayload = Array.from(((_a = event.dataTransfer) == null ? void 0 : _a.items) || []);
|
|
163
|
+
cbPayload = cbPayload.filter((i) => /image/.test(i.type));
|
|
164
|
+
if (cbPayload.length > 0) {
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
Promise.all(cbPayload.map((image) => imageUploadHandler(image.getAsFile()))).then((urls) => {
|
|
167
|
+
urls.forEach((url) => {
|
|
168
|
+
editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
|
|
169
|
+
src: url,
|
|
170
|
+
altText: ""
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}).catch((e) => {
|
|
174
|
+
throw e;
|
|
175
|
+
});
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
const node = getImageNodeInSelection();
|
|
179
|
+
if (!node) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
const data = getDragImageData(event);
|
|
183
|
+
if (!data) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
if (canDropImage(event)) {
|
|
188
|
+
const range = getDragSelection(event);
|
|
189
|
+
node.remove();
|
|
190
|
+
const rangeSelection = $createRangeSelection();
|
|
191
|
+
if (range !== null && range !== void 0) {
|
|
192
|
+
rangeSelection.applyDOMRange(range);
|
|
193
|
+
}
|
|
194
|
+
$setSelection(rangeSelection);
|
|
195
|
+
editor.dispatchCommand(INSERT_IMAGE_COMMAND, data);
|
|
196
|
+
}
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
function getImageNodeInSelection() {
|
|
200
|
+
const selection = $getSelection();
|
|
201
|
+
if (!$isNodeSelection(selection)) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
const nodes = selection.getNodes();
|
|
205
|
+
const node = nodes[0];
|
|
206
|
+
return $isImageNode(node) ? node : null;
|
|
207
|
+
}
|
|
208
|
+
function getDragImageData(event) {
|
|
209
|
+
var _a;
|
|
210
|
+
const dragData = (_a = event.dataTransfer) == null ? void 0 : _a.getData("application/x-lexical-drag");
|
|
211
|
+
if (!dragData) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
const { type, data } = JSON.parse(dragData);
|
|
215
|
+
if (type !== "image") {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
return data;
|
|
219
|
+
}
|
|
220
|
+
function canDropImage(event) {
|
|
221
|
+
const target = event.target;
|
|
222
|
+
return !!(target && target instanceof HTMLElement && target.parentElement);
|
|
223
|
+
}
|
|
224
|
+
function getDragSelection(event) {
|
|
225
|
+
let range;
|
|
226
|
+
const target = event.target;
|
|
227
|
+
const targetWindow = target == null ? null : target.nodeType === 9 ? target.defaultView : target.ownerDocument.defaultView;
|
|
228
|
+
const domSelection = getDOMSelection(targetWindow);
|
|
229
|
+
if (document.caretRangeFromPoint) {
|
|
230
|
+
range = document.caretRangeFromPoint(event.clientX, event.clientY);
|
|
231
|
+
} else if (event.rangeParent && domSelection !== null) {
|
|
232
|
+
domSelection.collapse(event.rangeParent, event.rangeOffset || 0);
|
|
233
|
+
range = domSelection.getRangeAt(0);
|
|
234
|
+
} else {
|
|
235
|
+
throw Error(`Cannot get the selection when dragging`);
|
|
236
|
+
}
|
|
237
|
+
return range;
|
|
238
|
+
}
|
|
239
|
+
export {
|
|
240
|
+
INSERT_IMAGE_COMMAND,
|
|
241
|
+
imagePlugin,
|
|
242
|
+
imagePluginHooks,
|
|
243
|
+
imageSystem
|
|
244
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
|
|
2
|
+
import { DecoratorNode } from 'lexical';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { MdastJsx } from '.';
|
|
5
|
+
import { VoidEmitter } from '../../utils/voidEmitter';
|
|
6
|
+
/**
|
|
7
|
+
* A serialized representation of an {@link LexicalJsxNode}.
|
|
8
|
+
*/
|
|
9
|
+
export type SerializedLexicalJsxNode = Spread<{
|
|
10
|
+
mdastNode: MdastJsx;
|
|
11
|
+
type: 'jsx';
|
|
12
|
+
version: 1;
|
|
13
|
+
}, SerializedLexicalNode>;
|
|
14
|
+
/**
|
|
15
|
+
* A lexical node that represents an image. Use {@link "$createLexicalJsxNode"} to construct one.
|
|
16
|
+
*/
|
|
17
|
+
export declare class LexicalJsxNode extends DecoratorNode<JSX.Element> {
|
|
18
|
+
__mdastNode: MdastJsx;
|
|
19
|
+
__focusEmitter: {
|
|
20
|
+
publish: () => void;
|
|
21
|
+
subscribe: (cb: () => void) => void;
|
|
22
|
+
};
|
|
23
|
+
static getType(): string;
|
|
24
|
+
static clone(node: LexicalJsxNode): LexicalJsxNode;
|
|
25
|
+
static importJSON(serializedNode: SerializedLexicalJsxNode): LexicalJsxNode;
|
|
26
|
+
constructor(mdastNode: MdastJsx, key?: NodeKey);
|
|
27
|
+
getMdastNode(): MdastJsx;
|
|
28
|
+
exportJSON(): SerializedLexicalJsxNode;
|
|
29
|
+
createDOM(): HTMLElement;
|
|
30
|
+
updateDOM(): false;
|
|
31
|
+
setMdastNode(mdastNode: MdastJsx): void;
|
|
32
|
+
select: () => void;
|
|
33
|
+
decorate(parentEditor: LexicalEditor, config: EditorConfig): JSX.Element;
|
|
34
|
+
isInline(): boolean;
|
|
35
|
+
isKeyboardSelectable(): boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare function JsxEditorContainer(props: {
|
|
38
|
+
/** The Lexical editor that contains the node */
|
|
39
|
+
parentEditor: LexicalEditor;
|
|
40
|
+
/** The Lexical node that is being edited */
|
|
41
|
+
lexicalJsxNode: LexicalJsxNode;
|
|
42
|
+
/** The MDAST node that is being edited */
|
|
43
|
+
mdastNode: MdastJsx;
|
|
44
|
+
config: EditorConfig;
|
|
45
|
+
focusEmitter: VoidEmitter;
|
|
46
|
+
}): React.JSX.Element;
|
|
47
|
+
/**
|
|
48
|
+
* Creates an {@link LexicalJsxNode}.
|
|
49
|
+
*/
|
|
50
|
+
export declare function $createLexicalJsxNode(mdastNode: MdastJsx): LexicalJsxNode;
|
|
51
|
+
/**
|
|
52
|
+
* Retruns true if the node is an {@link LexicalJsxNode}.
|
|
53
|
+
*/
|
|
54
|
+
export declare function $isLexicalJsxNode(node: LexicalNode | null | undefined): node is LexicalJsxNode;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import { DecoratorNode } from "lexical";
|
|
8
|
+
import React__default from "react";
|
|
9
|
+
import { NestedEditorsContext } from "../core/NestedLexicalEditor.js";
|
|
10
|
+
import { jsxPluginHooks } from "./index.js";
|
|
11
|
+
import { voidEmitter } from "../../utils/voidEmitter.js";
|
|
12
|
+
class LexicalJsxNode extends DecoratorNode {
|
|
13
|
+
constructor(mdastNode, key) {
|
|
14
|
+
super(key);
|
|
15
|
+
__publicField(this, "__mdastNode");
|
|
16
|
+
__publicField(this, "__focusEmitter", voidEmitter());
|
|
17
|
+
__publicField(this, "select", () => {
|
|
18
|
+
this.__focusEmitter.publish();
|
|
19
|
+
});
|
|
20
|
+
this.__mdastNode = mdastNode;
|
|
21
|
+
}
|
|
22
|
+
static getType() {
|
|
23
|
+
return "jsx";
|
|
24
|
+
}
|
|
25
|
+
static clone(node) {
|
|
26
|
+
return new LexicalJsxNode(structuredClone(node.__mdastNode));
|
|
27
|
+
}
|
|
28
|
+
static importJSON(serializedNode) {
|
|
29
|
+
return $createLexicalJsxNode(serializedNode.mdastNode);
|
|
30
|
+
}
|
|
31
|
+
getMdastNode() {
|
|
32
|
+
return this.__mdastNode;
|
|
33
|
+
}
|
|
34
|
+
exportJSON() {
|
|
35
|
+
return {
|
|
36
|
+
mdastNode: this.getMdastNode(),
|
|
37
|
+
type: "jsx",
|
|
38
|
+
version: 1
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
createDOM() {
|
|
42
|
+
return document.createElement(this.__mdastNode.type === "mdxJsxTextElement" ? "span" : "div");
|
|
43
|
+
}
|
|
44
|
+
updateDOM() {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
setMdastNode(mdastNode) {
|
|
48
|
+
this.getWritable().__mdastNode = mdastNode;
|
|
49
|
+
}
|
|
50
|
+
decorate(parentEditor, config) {
|
|
51
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
52
|
+
JsxEditorContainer,
|
|
53
|
+
{
|
|
54
|
+
lexicalJsxNode: this,
|
|
55
|
+
config,
|
|
56
|
+
mdastNode: this.getMdastNode(),
|
|
57
|
+
parentEditor,
|
|
58
|
+
focusEmitter: this.__focusEmitter
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
isInline() {
|
|
63
|
+
return this.__mdastNode.type === "mdxJsxTextElement";
|
|
64
|
+
}
|
|
65
|
+
isKeyboardSelectable() {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function JsxEditorContainer(props) {
|
|
70
|
+
const { mdastNode } = props;
|
|
71
|
+
const [jsxComponentDescriptors] = jsxPluginHooks.useEmitterValues("jsxComponentDescriptors");
|
|
72
|
+
const descriptor = jsxComponentDescriptors.find((descriptor2) => descriptor2.name === mdastNode.name);
|
|
73
|
+
const Editor = descriptor.Editor;
|
|
74
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
75
|
+
NestedEditorsContext.Provider,
|
|
76
|
+
{
|
|
77
|
+
value: {
|
|
78
|
+
config: props.config,
|
|
79
|
+
focusEmitter: props.focusEmitter,
|
|
80
|
+
mdastNode,
|
|
81
|
+
parentEditor: props.parentEditor,
|
|
82
|
+
lexicalNode: props.lexicalJsxNode
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
/* @__PURE__ */ React__default.createElement(Editor, { descriptor, mdastNode })
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
function $createLexicalJsxNode(mdastNode) {
|
|
89
|
+
return new LexicalJsxNode(mdastNode);
|
|
90
|
+
}
|
|
91
|
+
function $isLexicalJsxNode(node) {
|
|
92
|
+
return node instanceof LexicalJsxNode;
|
|
93
|
+
}
|
|
94
|
+
export {
|
|
95
|
+
$createLexicalJsxNode,
|
|
96
|
+
$isLexicalJsxNode,
|
|
97
|
+
JsxEditorContainer,
|
|
98
|
+
LexicalJsxNode
|
|
99
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx-jsx';
|
|
2
|
+
import { LexicalJsxNode } from './LexicalJsxNode';
|
|
3
|
+
import { LexicalExportVisitor } from '../../exportMarkdownFromLexical';
|
|
4
|
+
export declare const LexicalJsxVisitor: LexicalExportVisitor<LexicalJsxNode, MdxJsxFlowElement | MdxJsxTextElement>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { $isLexicalJsxNode } from "./LexicalJsxNode.js";
|
|
2
|
+
const LexicalJsxVisitor = {
|
|
3
|
+
testLexicalNode: $isLexicalJsxNode,
|
|
4
|
+
visitLexicalNode({ actions, mdastParent, lexicalNode }) {
|
|
5
|
+
const mdastNode = lexicalNode.getMdastNode();
|
|
6
|
+
actions.registerReferredComponent(mdastNode.name);
|
|
7
|
+
actions.appendToParent(mdastParent, mdastNode);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
LexicalJsxVisitor
|
|
12
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { $createLexicalJsxNode } from "./LexicalJsxNode.js";
|
|
2
|
+
const MdastMdxJsxElementVisitor = {
|
|
3
|
+
testNode: (node) => {
|
|
4
|
+
return node.type === "mdxJsxTextElement" || node.type === "mdxJsxFlowElement";
|
|
5
|
+
},
|
|
6
|
+
visitNode({ lexicalParent, mdastNode }) {
|
|
7
|
+
lexicalParent.append($createLexicalJsxNode(mdastNode));
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
MdastMdxJsxElementVisitor
|
|
12
|
+
};
|