@mdxeditor/editor 0.10.1 → 0.11.0
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 +4 -3
- package/dist/FormatConstants.d.ts +9 -0
- package/dist/FormatConstants.js +10 -0
- package/dist/MDXEditor.d.ts +60 -0
- package/dist/MDXEditor.js +105 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +17 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +29 -0
- package/dist/directive-editors/GenericDirectiveEditor.d.ts +8 -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 -1105
- package/dist/index.js +140 -72
- package/dist/jsx-editors/GenericJsxEditor.d.ts +8 -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 +617 -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 +800 -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 +96 -0
- package/dist/plugins/core/NestedLexicalEditor.js +181 -0
- package/dist/plugins/core/PropertyPopover.d.ts +23 -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 +423 -0
- package/dist/plugins/core/index.js +346 -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 +27 -0
- package/dist/plugins/diff-source/index.d.ts +544 -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 +603 -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 +523 -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 +118 -0
- package/dist/plugins/headings/index.js +20 -0
- package/dist/plugins/image/ImageEditor.d.ts +9 -0
- package/dist/{ImageEditor-8db2f131.js → plugins/image/ImageEditor.js} +40 -52
- package/dist/plugins/image/ImageNode.d.ts +63 -0
- package/dist/plugins/image/ImageNode.js +136 -0
- package/dist/plugins/image/ImageResizer.d.ts +18 -0
- package/dist/plugins/image/ImageResizer.js +214 -0
- package/dist/plugins/image/LexicalImageVisitor.d.ts +4 -0
- package/dist/plugins/image/LexicalImageVisitor.js +36 -0
- package/dist/plugins/image/MdastImageVisitor.d.ts +6 -0
- package/dist/plugins/image/MdastImageVisitor.js +87 -0
- package/dist/plugins/image/index.d.ts +557 -0
- package/dist/plugins/image/index.js +246 -0
- package/dist/plugins/jsx/LexicalJsxNode.d.ts +54 -0
- package/dist/plugins/jsx/LexicalJsxNode.js +102 -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 +599 -0
- package/dist/plugins/jsx/index.js +59 -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 +68 -0
- package/dist/plugins/link/index.js +22 -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 +508 -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 +13 -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 +533 -0
- package/dist/plugins/lists/index.js +111 -0
- package/dist/plugins/markdown-shortcut/index.d.ts +63 -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 +12 -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 +361 -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 +839 -0
- package/dist/plugins/sandpack/index.js +93 -0
- package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
- package/dist/{useCodeMirrorRef-5356dfa5.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/plugins/table/TableEditor.js +384 -0
- package/dist/plugins/table/TableNode.d.ts +52 -0
- package/dist/plugins/table/TableNode.js +147 -0
- package/dist/plugins/table/index.d.ts +523 -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 +523 -0
- package/dist/plugins/thematic-break/index.js +39 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +6 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.js +52 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +5 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +35 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +6 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +30 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +7 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +32 -0
- package/dist/plugins/toolbar/components/CodeToggle.d.ts +6 -0
- package/dist/plugins/toolbar/components/CodeToggle.js +20 -0
- package/dist/plugins/toolbar/components/CreateLink.d.ts +6 -0
- package/dist/plugins/toolbar/components/CreateLink.js +11 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +18 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +27 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.js +29 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +7 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.js +20 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.js +11 -0
- package/dist/plugins/toolbar/components/InsertImage.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertImage.js +23 -0
- package/dist/plugins/toolbar/components/InsertSandpack.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertSandpack.js +13 -0
- package/dist/plugins/toolbar/components/InsertTable.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertTable.js +20 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.js +11 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +7 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +58 -0
- package/dist/plugins/toolbar/components/ListsToggle.d.ts +7 -0
- package/dist/plugins/toolbar/components/ListsToggle.js +23 -0
- package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +7 -0
- package/dist/plugins/toolbar/components/ShowSandpackInfo.js +32 -0
- package/dist/plugins/toolbar/components/UndoRedo.d.ts +5 -0
- package/dist/plugins/toolbar/components/UndoRedo.js +59 -0
- package/dist/plugins/toolbar/index.d.ts +428 -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 +8 -0
- package/dist/plugins/toolbar/primitives/TooltipWrap.js +12 -0
- package/dist/plugins/toolbar/primitives/select.d.ts +50 -0
- package/dist/plugins/toolbar/primitives/select.js +44 -0
- package/dist/plugins/toolbar/primitives/toolbar.d.ts +160 -0
- package/dist/plugins/toolbar/primitives/toolbar.js +111 -0
- package/dist/style.css +556 -249
- 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 +254 -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 +246 -14
- package/dist/CodeBlockEditor-02116cba.js +0 -79
- package/dist/CodeBlockEditor-1c7b46dc.cjs +0 -1
- package/dist/FrontmatterEditor-37a4c091.cjs +0 -1
- package/dist/FrontmatterEditor-988a8fb6.js +0 -118
- package/dist/ImageEditor-524159e9.cjs +0 -1
- package/dist/JsxEditor-606e9d86.js +0 -108
- package/dist/JsxEditor-98a94a9d.cjs +0 -1
- package/dist/LeafDirectiveEditor-38a73f5c.js +0 -59
- package/dist/LeafDirectiveEditor-dfa1ce78.cjs +0 -1
- package/dist/SandpackEditor-90425f26.cjs +0 -1
- package/dist/SandpackEditor-c771b4d0.js +0 -100
- package/dist/SourceEditor-19eb2c9e.js +0 -64
- package/dist/SourceEditor-46ed1f77.cjs +0 -1
- package/dist/TableEditor-4a993dab.cjs +0 -1
- package/dist/TableEditor-c28b3ca2.js +0 -426
- package/dist/index-1ab1a12e.js +0 -4363
- package/dist/index-8217810f.cjs +0 -1
- package/dist/index.cjs +0 -1
- package/dist/useCodeMirrorRef-7055e7de.cjs +0 -1
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { createEmptyHistoryState } from "@lexical/react/LexicalHistoryPlugin";
|
|
2
|
+
import { $isHeadingNode } from "@lexical/rich-text";
|
|
3
|
+
import { $setBlocksType } from "@lexical/selection";
|
|
4
|
+
import { $findMatchingParent, $wrapNodeInElement, $insertNodeToNearestRoot } from "@lexical/utils";
|
|
5
|
+
import { createCommand, SELECTION_CHANGE_COMMAND, $getRoot, COMMAND_PRIORITY_CRITICAL, BLUR_COMMAND, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, $getSelection, $isRangeSelection, $insertNodes, $createParagraphNode, ParagraphNode, TextNode } from "lexical";
|
|
6
|
+
import { exportMarkdownFromLexical } from "../../exportMarkdownFromLexical.js";
|
|
7
|
+
import { importMarkdownToLexical } from "../../importMarkdownToLexical.js";
|
|
8
|
+
import { LexicalLinebreakVisitor } from "./LexicalLinebreakVisitor.js";
|
|
9
|
+
import { LexicalParagraphVisitor } from "./LexicalParagraphVisitor.js";
|
|
10
|
+
import { LexicalRootVisitor } from "./LexicalRootVisitor.js";
|
|
11
|
+
import { LexicalTextVisitor } from "./LexicalTextVisitor.js";
|
|
12
|
+
import { MdastFormattingVisitor } from "./MdastFormattingVisitor.js";
|
|
13
|
+
import { MdastInlineCodeVisitor } from "./MdastInlineCodeVisitor.js";
|
|
14
|
+
import { MdastParagraphVisitor } from "./MdastParagraphVisitor.js";
|
|
15
|
+
import { MdastRootVisitor } from "./MdastRootVisitor.js";
|
|
16
|
+
import { MdastTextVisitor } from "./MdastTextVisitor.js";
|
|
17
|
+
import { SharedHistoryPlugin } from "./SharedHistoryPlugin.js";
|
|
18
|
+
import { system } from "../../gurx/realmFactory.js";
|
|
19
|
+
import { realmPlugin } from "../../gurx/react.js";
|
|
20
|
+
const NESTED_EDITOR_UPDATED_COMMAND = createCommand("NESTED_EDITOR_UPDATED_COMMAND");
|
|
21
|
+
const coreSystem = system((r) => {
|
|
22
|
+
function createAppendNodeFor(node) {
|
|
23
|
+
const appendNode = r.node();
|
|
24
|
+
r.link(
|
|
25
|
+
r.pipe(
|
|
26
|
+
appendNode,
|
|
27
|
+
r.o.withLatestFrom(node),
|
|
28
|
+
r.o.map(([newValue, values]) => {
|
|
29
|
+
if (values.includes(newValue)) {
|
|
30
|
+
return values;
|
|
31
|
+
}
|
|
32
|
+
return [...values, newValue];
|
|
33
|
+
})
|
|
34
|
+
),
|
|
35
|
+
node
|
|
36
|
+
);
|
|
37
|
+
return appendNode;
|
|
38
|
+
}
|
|
39
|
+
const rootEditor = r.node(null);
|
|
40
|
+
const activeEditor = r.node(null, true);
|
|
41
|
+
const contentEditableClassName = r.node("");
|
|
42
|
+
const inFocus = r.node(false, true);
|
|
43
|
+
const currentFormat = r.node(0, true);
|
|
44
|
+
const applyFormat = r.node();
|
|
45
|
+
const currentSelection = r.node(null);
|
|
46
|
+
const activeEditorSubscriptions = r.node([]);
|
|
47
|
+
const rootEditorSubscriptions = r.node([]);
|
|
48
|
+
const editorInFocus = r.node(null);
|
|
49
|
+
const rebind = () => r.o.scan((teardowns, [subs, activeEditorValue]) => {
|
|
50
|
+
teardowns.forEach((teardown) => {
|
|
51
|
+
if (!teardown) {
|
|
52
|
+
throw new Error("You have a subscription that does not return a teardown");
|
|
53
|
+
}
|
|
54
|
+
teardown();
|
|
55
|
+
});
|
|
56
|
+
return activeEditorValue ? subs.map((s) => s(activeEditorValue)) : [];
|
|
57
|
+
}, []);
|
|
58
|
+
r.pipe(r.combine(activeEditorSubscriptions, activeEditor), rebind());
|
|
59
|
+
r.pipe(r.combine(rootEditorSubscriptions, rootEditor), rebind());
|
|
60
|
+
const createRootEditorSubscription = createAppendNodeFor(rootEditorSubscriptions);
|
|
61
|
+
const createActiveEditorSubscription = createAppendNodeFor(activeEditorSubscriptions);
|
|
62
|
+
function handleSelectionChange() {
|
|
63
|
+
const selection = $getSelection();
|
|
64
|
+
if ($isRangeSelection(selection)) {
|
|
65
|
+
r.pubKeys({
|
|
66
|
+
currentSelection: selection,
|
|
67
|
+
currentFormat: selection.format
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
r.pub(createRootEditorSubscription, (theRootEditor) => {
|
|
72
|
+
return theRootEditor.registerCommand(
|
|
73
|
+
SELECTION_CHANGE_COMMAND,
|
|
74
|
+
(_, theActiveEditor) => {
|
|
75
|
+
r.pubIn({
|
|
76
|
+
[activeEditor.key]: theActiveEditor,
|
|
77
|
+
[inFocus.key]: true
|
|
78
|
+
});
|
|
79
|
+
if (theActiveEditor._parentEditor === null) {
|
|
80
|
+
theActiveEditor.getEditorState().read(() => {
|
|
81
|
+
r.pub(editorInFocus, {
|
|
82
|
+
rootNode: $getRoot(),
|
|
83
|
+
editorType: "lexical"
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
handleSelectionChange();
|
|
88
|
+
return false;
|
|
89
|
+
},
|
|
90
|
+
COMMAND_PRIORITY_CRITICAL
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
r.pub(createRootEditorSubscription, (theRootEditor) => {
|
|
94
|
+
return theRootEditor.registerUpdateListener(({ dirtyElements, dirtyLeaves, editorState }) => {
|
|
95
|
+
if (dirtyElements.size === 0 && dirtyLeaves.size === 0) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
let theNewMarkdownValue;
|
|
99
|
+
editorState.read(() => {
|
|
100
|
+
theNewMarkdownValue = exportMarkdownFromLexical({
|
|
101
|
+
root: $getRoot(),
|
|
102
|
+
visitors: r.getValue(exportVisitors),
|
|
103
|
+
jsxComponentDescriptors: r.getValue(jsxComponentDescriptors),
|
|
104
|
+
toMarkdownExtensions: r.getValue(toMarkdownExtensions),
|
|
105
|
+
toMarkdownOptions: r.getValue(toMarkdownOptions),
|
|
106
|
+
jsxIsAvailable: r.getValue(jsxIsAvailable)
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
r.pub(markdown, theNewMarkdownValue.trim());
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
const initialMarkdown = r.node("");
|
|
113
|
+
const markdown = r.node("", true);
|
|
114
|
+
r.link(initialMarkdown, markdown);
|
|
115
|
+
const importVisitors = r.node([]);
|
|
116
|
+
const syntaxExtensions = r.node([]);
|
|
117
|
+
const mdastExtensions = r.node([]);
|
|
118
|
+
const usedLexicalNodes = r.node([]);
|
|
119
|
+
const exportVisitors = r.node([]);
|
|
120
|
+
const toMarkdownExtensions = r.node([]);
|
|
121
|
+
const toMarkdownOptions = r.node({}, true);
|
|
122
|
+
const jsxIsAvailable = r.node(false);
|
|
123
|
+
const jsxComponentDescriptors = r.node([]);
|
|
124
|
+
const editorRootElementRef = r.node(null);
|
|
125
|
+
const addLexicalNode = createAppendNodeFor(usedLexicalNodes);
|
|
126
|
+
const addImportVisitor = createAppendNodeFor(importVisitors);
|
|
127
|
+
const addSyntaxExtension = createAppendNodeFor(syntaxExtensions);
|
|
128
|
+
const addMdastExtension = createAppendNodeFor(mdastExtensions);
|
|
129
|
+
const addExportVisitor = createAppendNodeFor(exportVisitors);
|
|
130
|
+
const addToMarkdownExtension = createAppendNodeFor(toMarkdownExtensions);
|
|
131
|
+
const setMarkdown = r.node();
|
|
132
|
+
r.sub(
|
|
133
|
+
r.pipe(setMarkdown, r.o.withLatestFrom(rootEditor, importVisitors, mdastExtensions, syntaxExtensions)),
|
|
134
|
+
([theNewMarkdownValue, editor, importVisitors2, mdastExtensions2, syntaxExtensions2]) => {
|
|
135
|
+
editor == null ? void 0 : editor.update(() => {
|
|
136
|
+
$getRoot().clear();
|
|
137
|
+
importMarkdownToLexical({
|
|
138
|
+
root: $getRoot(),
|
|
139
|
+
visitors: importVisitors2,
|
|
140
|
+
mdastExtensions: mdastExtensions2,
|
|
141
|
+
markdown: theNewMarkdownValue,
|
|
142
|
+
syntaxExtensions: syntaxExtensions2
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
const initialRootEditorState = r.node((theRootEditor) => {
|
|
148
|
+
r.pub(rootEditor, theRootEditor);
|
|
149
|
+
r.pub(activeEditor, theRootEditor);
|
|
150
|
+
importMarkdownToLexical({
|
|
151
|
+
root: $getRoot(),
|
|
152
|
+
visitors: r.getValue(importVisitors),
|
|
153
|
+
mdastExtensions: r.getValue(mdastExtensions),
|
|
154
|
+
markdown: r.getValue(initialMarkdown),
|
|
155
|
+
syntaxExtensions: r.getValue(syntaxExtensions)
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
r.pub(createActiveEditorSubscription, (editor) => {
|
|
159
|
+
return editor.registerUpdateListener(({ editorState }) => {
|
|
160
|
+
editorState.read(() => {
|
|
161
|
+
handleSelectionChange();
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
r.pub(createActiveEditorSubscription, (theEditor) => {
|
|
166
|
+
return theEditor.registerCommand(
|
|
167
|
+
BLUR_COMMAND,
|
|
168
|
+
(payload) => {
|
|
169
|
+
var _a;
|
|
170
|
+
const theRootEditor = r.getValue(rootEditor);
|
|
171
|
+
if (theRootEditor) {
|
|
172
|
+
const movingOutside = !((_a = theRootEditor.getRootElement()) == null ? void 0 : _a.contains(payload.relatedTarget));
|
|
173
|
+
if (movingOutside) {
|
|
174
|
+
r.pub(inFocus, false);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
178
|
+
},
|
|
179
|
+
COMMAND_PRIORITY_CRITICAL
|
|
180
|
+
);
|
|
181
|
+
});
|
|
182
|
+
const composerChildren = r.node([]);
|
|
183
|
+
const addComposerChild = createAppendNodeFor(composerChildren);
|
|
184
|
+
const topAreaChildren = r.node([]);
|
|
185
|
+
const addTopAreaChild = createAppendNodeFor(topAreaChildren);
|
|
186
|
+
const editorWrappers = r.node([]);
|
|
187
|
+
const addEditorWrapper = createAppendNodeFor(editorWrappers);
|
|
188
|
+
const nestedEditorChildren = r.node([]);
|
|
189
|
+
const addNestedEditorChild = createAppendNodeFor(nestedEditorChildren);
|
|
190
|
+
const historyState = r.node(createEmptyHistoryState());
|
|
191
|
+
r.sub(r.pipe(applyFormat, r.o.withLatestFrom(activeEditor)), ([format, theEditor]) => {
|
|
192
|
+
theEditor == null ? void 0 : theEditor.dispatchCommand(FORMAT_TEXT_COMMAND, format);
|
|
193
|
+
});
|
|
194
|
+
const currentBlockType = r.node("");
|
|
195
|
+
const applyBlockType = r.node();
|
|
196
|
+
r.sub(r.pipe(currentSelection, r.o.withLatestFrom(activeEditor)), ([selection, theEditor]) => {
|
|
197
|
+
if (!selection || !theEditor) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const anchorNode = selection.anchor.getNode();
|
|
201
|
+
let element = anchorNode.getKey() === "root" ? anchorNode : $findMatchingParent(anchorNode, (e) => {
|
|
202
|
+
const parent = e.getParent();
|
|
203
|
+
return parent !== null && $isRootOrShadowRoot(parent);
|
|
204
|
+
});
|
|
205
|
+
if (element === null) {
|
|
206
|
+
element = anchorNode.getTopLevelElementOrThrow();
|
|
207
|
+
}
|
|
208
|
+
const elementKey = element.getKey();
|
|
209
|
+
const elementDOM = theEditor.getElementByKey(elementKey);
|
|
210
|
+
if (elementDOM !== null) {
|
|
211
|
+
const blockType = $isHeadingNode(element) ? element.getTag() : element.getType();
|
|
212
|
+
r.pub(currentBlockType, blockType);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
const convertSelectionToNode = r.node();
|
|
216
|
+
r.sub(r.pipe(convertSelectionToNode, r.o.withLatestFrom(activeEditor)), ([factory, editor]) => {
|
|
217
|
+
editor == null ? void 0 : editor.update(() => {
|
|
218
|
+
const selection = $getSelection();
|
|
219
|
+
if ($isRangeSelection(selection)) {
|
|
220
|
+
$setBlocksType(selection, factory);
|
|
221
|
+
setTimeout(() => {
|
|
222
|
+
editor.focus();
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
const insertDecoratorNode = r.node();
|
|
228
|
+
r.sub(r.pipe(insertDecoratorNode, r.o.withLatestFrom(activeEditor)), ([nodeFactory, theEditor]) => {
|
|
229
|
+
theEditor == null ? void 0 : theEditor.focus(
|
|
230
|
+
() => {
|
|
231
|
+
theEditor.getEditorState().read(() => {
|
|
232
|
+
const selection = $getSelection();
|
|
233
|
+
if ($isRangeSelection(selection)) {
|
|
234
|
+
const focusNode = selection.focus.getNode();
|
|
235
|
+
if (focusNode !== null) {
|
|
236
|
+
theEditor.update(() => {
|
|
237
|
+
const node = nodeFactory();
|
|
238
|
+
if (node.isInline()) {
|
|
239
|
+
$insertNodes([node]);
|
|
240
|
+
if ($isRootOrShadowRoot(node.getParentOrThrow())) {
|
|
241
|
+
$wrapNodeInElement(node, $createParagraphNode).selectEnd();
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
$insertNodeToNearestRoot(node);
|
|
245
|
+
}
|
|
246
|
+
if (Object.hasOwn(node, "select") && typeof node.select === "function") {
|
|
247
|
+
setTimeout(() => node.select(), 80);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
},
|
|
254
|
+
{ defaultSelection: "rootEnd" }
|
|
255
|
+
);
|
|
256
|
+
});
|
|
257
|
+
return {
|
|
258
|
+
// state
|
|
259
|
+
activeEditor,
|
|
260
|
+
inFocus,
|
|
261
|
+
historyState,
|
|
262
|
+
currentSelection,
|
|
263
|
+
// jsx
|
|
264
|
+
jsxIsAvailable,
|
|
265
|
+
jsxComponentDescriptors,
|
|
266
|
+
// lexical editor
|
|
267
|
+
initialRootEditorState,
|
|
268
|
+
rootEditor,
|
|
269
|
+
createRootEditorSubscription,
|
|
270
|
+
createActiveEditorSubscription,
|
|
271
|
+
// import
|
|
272
|
+
importVisitors,
|
|
273
|
+
syntaxExtensions,
|
|
274
|
+
mdastExtensions,
|
|
275
|
+
usedLexicalNodes,
|
|
276
|
+
addImportVisitor,
|
|
277
|
+
addLexicalNode,
|
|
278
|
+
addSyntaxExtension,
|
|
279
|
+
addMdastExtension,
|
|
280
|
+
// export
|
|
281
|
+
toMarkdownExtensions,
|
|
282
|
+
toMarkdownOptions,
|
|
283
|
+
addToMarkdownExtension,
|
|
284
|
+
addExportVisitor,
|
|
285
|
+
exportVisitors,
|
|
286
|
+
// markdown strings
|
|
287
|
+
initialMarkdown,
|
|
288
|
+
setMarkdown,
|
|
289
|
+
markdown,
|
|
290
|
+
// DOM
|
|
291
|
+
editorRootElementRef,
|
|
292
|
+
contentEditableClassName,
|
|
293
|
+
// child controls
|
|
294
|
+
composerChildren,
|
|
295
|
+
addComposerChild,
|
|
296
|
+
topAreaChildren,
|
|
297
|
+
addTopAreaChild,
|
|
298
|
+
nestedEditorChildren,
|
|
299
|
+
addNestedEditorChild,
|
|
300
|
+
editorWrappers,
|
|
301
|
+
addEditorWrapper,
|
|
302
|
+
// editor content state and commands
|
|
303
|
+
currentFormat,
|
|
304
|
+
editorInFocus,
|
|
305
|
+
applyFormat,
|
|
306
|
+
currentBlockType,
|
|
307
|
+
applyBlockType,
|
|
308
|
+
convertSelectionToNode,
|
|
309
|
+
insertDecoratorNode
|
|
310
|
+
};
|
|
311
|
+
}, []);
|
|
312
|
+
const [
|
|
313
|
+
/** @internal */
|
|
314
|
+
corePlugin,
|
|
315
|
+
/** @internal */
|
|
316
|
+
corePluginHooks
|
|
317
|
+
] = realmPlugin({
|
|
318
|
+
id: "core",
|
|
319
|
+
systemSpec: coreSystem,
|
|
320
|
+
applyParamsToSystem(realm, params) {
|
|
321
|
+
realm.pubKey("contentEditableClassName", params.contentEditableClassName);
|
|
322
|
+
realm.pubKey("toMarkdownOptions", params.toMarkdownOptions);
|
|
323
|
+
realm.singletonSubKey("markdown", params.onChange);
|
|
324
|
+
},
|
|
325
|
+
init(realm, params) {
|
|
326
|
+
realm.pubKey("initialMarkdown", params.initialMarkdown.trim());
|
|
327
|
+
realm.pubKey("addImportVisitor", MdastRootVisitor);
|
|
328
|
+
realm.pubKey("addImportVisitor", MdastParagraphVisitor);
|
|
329
|
+
realm.pubKey("addImportVisitor", MdastTextVisitor);
|
|
330
|
+
realm.pubKey("addImportVisitor", MdastFormattingVisitor);
|
|
331
|
+
realm.pubKey("addImportVisitor", MdastInlineCodeVisitor);
|
|
332
|
+
realm.pubKey("addLexicalNode", ParagraphNode);
|
|
333
|
+
realm.pubKey("addLexicalNode", TextNode);
|
|
334
|
+
realm.pubKey("addExportVisitor", LexicalRootVisitor);
|
|
335
|
+
realm.pubKey("addExportVisitor", LexicalParagraphVisitor);
|
|
336
|
+
realm.pubKey("addExportVisitor", LexicalTextVisitor);
|
|
337
|
+
realm.pubKey("addExportVisitor", LexicalLinebreakVisitor);
|
|
338
|
+
realm.pubKey("addComposerChild", SharedHistoryPlugin);
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
export {
|
|
342
|
+
NESTED_EDITOR_UPDATED_COMMAND,
|
|
343
|
+
corePlugin,
|
|
344
|
+
corePluginHooks,
|
|
345
|
+
coreSystem
|
|
346
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import * as RadixPopover from '@radix-ui/react-popover';
|
|
3
|
+
export declare const PopoverPortal: (props: RadixPopover.PopoverPortalProps) => React.JSX.Element;
|
|
4
|
+
export declare const PopoverContent: React.ForwardRefExoticComponent<Omit<RadixPopover.PopoverContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<any>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React__default from "react";
|
|
2
|
+
import * as RadixPopover from "@radix-ui/react-popover";
|
|
3
|
+
import { corePluginHooks } from "../index.js";
|
|
4
|
+
import styles from "../../../styles/ui.module.css.js";
|
|
5
|
+
const PopoverPortal = (props) => {
|
|
6
|
+
const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
|
|
7
|
+
return /* @__PURE__ */ React__default.createElement(RadixPopover.Portal, { ...props, container: editorRootElementRef == null ? void 0 : editorRootElementRef.current });
|
|
8
|
+
};
|
|
9
|
+
const PopoverContent = React__default.forwardRef(
|
|
10
|
+
(props, ref) => {
|
|
11
|
+
return /* @__PURE__ */ React__default.createElement(RadixPopover.Content, { ...props, className: styles.popoverContent, sideOffset: 5, side: "top", ref }, /* @__PURE__ */ React__default.createElement("span", { className: styles.popoverArrow }, /* @__PURE__ */ React__default.createElement(RadixPopover.Arrow, null)), props.children);
|
|
12
|
+
}
|
|
13
|
+
);
|
|
14
|
+
export {
|
|
15
|
+
PopoverContent,
|
|
16
|
+
PopoverPortal
|
|
17
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React__default from "react";
|
|
2
|
+
import { diffSourcePluginHooks } from "./index.js";
|
|
3
|
+
import { DiffViewer } from "./DiffViewer.js";
|
|
4
|
+
import { SourceEditor } from "./SourceEditor.js";
|
|
5
|
+
const DiffSourceWrapper = ({ children }) => {
|
|
6
|
+
const [viewMode] = diffSourcePluginHooks.useEmitterValues("viewMode");
|
|
7
|
+
return /* @__PURE__ */ React__default.createElement("div", null, /* @__PURE__ */ React__default.createElement("div", { style: { display: viewMode === "rich-text" ? "block" : "none" } }, children), viewMode === "diff" ? /* @__PURE__ */ React__default.createElement(DiffViewer, null) : null, viewMode === "source" ? /* @__PURE__ */ React__default.createElement(SourceEditor, null) : null);
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
DiffSourceWrapper
|
|
11
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React__default from "react";
|
|
2
|
+
import { parseDiff, Diff, Hunk } from "react-diff-view";
|
|
3
|
+
import { formatLines, diffLines } from "unidiff";
|
|
4
|
+
import "../../node_modules/react-diff-view/style/index.css.js";
|
|
5
|
+
import { corePluginHooks } from "../core/index.js";
|
|
6
|
+
import { diffSourcePluginHooks } from "./index.js";
|
|
7
|
+
const DiffViewer = () => {
|
|
8
|
+
const [newText] = corePluginHooks.useEmitterValues("markdown");
|
|
9
|
+
const [oldText] = diffSourcePluginHooks.useEmitterValues("diffMarkdown");
|
|
10
|
+
const diffText = formatLines(diffLines(oldText, newText), { context: 3 });
|
|
11
|
+
if (diffText.trim() === "")
|
|
12
|
+
return /* @__PURE__ */ React__default.createElement("div", null, "No changes");
|
|
13
|
+
const [diff] = parseDiff(diffText, { nearbySequences: "zip" });
|
|
14
|
+
return /* @__PURE__ */ React__default.createElement(Diff, { viewType: "split", diffType: "modify", hunks: diff.hunks || [] }, (hunks) => hunks.map((hunk) => /* @__PURE__ */ React__default.createElement(Hunk, { key: hunk.content, hunk })));
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
DiffViewer
|
|
18
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { markdown } from "@codemirror/lang-markdown";
|
|
2
|
+
import { SandpackProvider, CodeEditor } from "@codesandbox/sandpack-react";
|
|
3
|
+
import React__default from "react";
|
|
4
|
+
import { diffSourcePluginHooks } from "./index.js";
|
|
5
|
+
import { corePluginHooks } from "../core/index.js";
|
|
6
|
+
import { EditorView } from "@codemirror/view";
|
|
7
|
+
const SourceEditor = () => {
|
|
8
|
+
const [markdown$1] = corePluginHooks.useEmitterValues("markdown");
|
|
9
|
+
const updateMarkdown = diffSourcePluginHooks.usePublisher("markdownSourceEditorValue");
|
|
10
|
+
const codeMirrorRef = React__default.useRef(null);
|
|
11
|
+
return /* @__PURE__ */ React__default.createElement("div", null, /* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: null }, /* @__PURE__ */ React__default.createElement(SandpackProvider, null, /* @__PURE__ */ React__default.createElement(
|
|
12
|
+
CodeEditor,
|
|
13
|
+
{
|
|
14
|
+
extensions: [EditorView.lineWrapping],
|
|
15
|
+
showLineNumbers: true,
|
|
16
|
+
additionalLanguages: [{ name: "markdown", extensions: ["md"], language: markdown() }],
|
|
17
|
+
initMode: "lazy",
|
|
18
|
+
filePath: `file.md`,
|
|
19
|
+
code: markdown$1,
|
|
20
|
+
onCodeUpdate: updateMarkdown,
|
|
21
|
+
ref: codeMirrorRef
|
|
22
|
+
}
|
|
23
|
+
))));
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
SourceEditor
|
|
27
|
+
};
|