@mdxeditor/editor 1.14.2 → 2.0.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/dist/MDXEditor.js +20 -25
- package/dist/RealmWithPlugins.js +36 -0
- package/dist/directive-editors/GenericDirectiveEditor.js +7 -4
- package/dist/index.d.ts +2590 -62
- package/dist/index.js +138 -66
- package/dist/jsx-editors/GenericJsxEditor.js +12 -9
- package/dist/plugins/codeblock/CodeBlockNode.js +5 -5
- package/dist/plugins/codeblock/index.js +37 -63
- package/dist/plugins/codemirror/CodeMirrorEditor.js +3 -2
- package/dist/plugins/codemirror/index.js +28 -45
- package/dist/plugins/core/GenericHTMLNode.js +9 -1
- package/dist/plugins/core/MdastHTMLNode.js +0 -1
- package/dist/plugins/core/NestedLexicalEditor.js +11 -10
- package/dist/plugins/core/PropertyPopover.js +3 -2
- package/dist/plugins/core/SharedHistoryPlugin.js +3 -3
- package/dist/plugins/core/index.js +426 -385
- package/dist/plugins/core/ui/DownshiftAutoComplete.js +3 -2
- package/dist/plugins/core/ui/PopoverUtils.js +3 -2
- package/dist/plugins/diff-source/DiffSourceWrapper.js +3 -4
- package/dist/plugins/diff-source/DiffViewer.js +7 -7
- package/dist/plugins/diff-source/SourceEditor.js +6 -6
- package/dist/plugins/diff-source/index.js +17 -52
- package/dist/plugins/directives/DirectiveNode.js +28 -5
- package/dist/plugins/directives/index.js +36 -43
- package/dist/plugins/frontmatter/FrontmatterEditor.js +20 -16
- package/dist/plugins/frontmatter/index.js +51 -62
- package/dist/plugins/headings/index.js +43 -49
- package/dist/plugins/image/ImageDialog.js +11 -7
- package/dist/plugins/image/ImageEditor.js +10 -7
- package/dist/plugins/image/ImageNode.js +27 -5
- package/dist/plugins/image/index.js +65 -72
- package/dist/plugins/jsx/LexicalJsxNode.js +3 -2
- package/dist/plugins/jsx/index.js +48 -60
- package/dist/plugins/link/index.js +15 -20
- package/dist/plugins/link-dialog/LinkDialog.js +17 -16
- package/dist/plugins/link-dialog/index.js +194 -216
- package/dist/plugins/lists/MdastListItemVisitor.js +3 -2
- package/dist/plugins/lists/index.js +50 -65
- package/dist/plugins/markdown-shortcut/index.js +12 -15
- package/dist/plugins/quote/index.js +11 -19
- package/dist/plugins/sandpack/SandpackEditor.js +3 -2
- package/dist/plugins/sandpack/index.js +34 -50
- package/dist/plugins/sandpack/useCodeMirrorRef.js +7 -6
- package/dist/plugins/table/TableEditor.js +12 -13
- package/dist/plugins/table/TableNode.js +28 -0
- package/dist/plugins/table/index.js +32 -39
- package/dist/plugins/thematic-break/index.js +19 -32
- package/dist/plugins/toolbar/components/BlockTypeSelect.js +9 -8
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +4 -4
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +3 -2
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +5 -5
- package/dist/plugins/toolbar/components/CodeToggle.js +4 -3
- package/dist/plugins/toolbar/components/CreateLink.js +6 -4
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +5 -5
- package/dist/plugins/toolbar/components/InsertAdmonition.js +5 -3
- package/dist/plugins/toolbar/components/InsertCodeBlock.js +5 -3
- package/dist/plugins/toolbar/components/InsertFrontmatter.js +6 -5
- package/dist/plugins/toolbar/components/InsertImage.js +6 -5
- package/dist/plugins/toolbar/components/InsertSandpack.js +5 -4
- package/dist/plugins/toolbar/components/InsertTable.js +5 -3
- package/dist/plugins/toolbar/components/InsertThematicBreak.js +6 -4
- package/dist/plugins/toolbar/components/ListsToggle.js +5 -4
- package/dist/plugins/toolbar/components/ShowSandpackInfo.js +9 -4
- package/dist/plugins/toolbar/components/UndoRedo.js +3 -3
- package/dist/plugins/toolbar/index.js +15 -31
- package/dist/plugins/toolbar/primitives/DialogButton.js +23 -24
- package/dist/plugins/toolbar/primitives/TooltipWrap.js +3 -2
- package/dist/plugins/toolbar/primitives/select.js +5 -4
- package/dist/plugins/toolbar/primitives/toolbar.js +10 -4
- package/dist/style.css +937 -570
- package/dist/styles/globals.css.js +1 -4
- package/dist/styles/lexical-theme.module.css.js +25 -19
- package/dist/styles/ui.module.css.js +106 -103
- package/package.json +64 -317
- package/dist/FormatConstants.d.ts +0 -9
- package/dist/MDXEditor.d.ts +0 -103
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +0 -17
- package/dist/directive-editors/GenericDirectiveEditor.d.ts +0 -8
- package/dist/exportMarkdownFromLexical.d.ts +0 -138
- package/dist/gurx/index.d.ts +0 -3
- package/dist/gurx/react.d.ts +0 -152
- package/dist/gurx/react.js +0 -206
- package/dist/gurx/realm.d.ts +0 -148
- package/dist/gurx/realm.js +0 -489
- package/dist/gurx/realmFactory.d.ts +0 -79
- package/dist/gurx/realmFactory.js +0 -32
- package/dist/importMarkdownToLexical.d.ts +0 -101
- package/dist/jsx-editors/GenericJsxEditor.d.ts +0 -8
- package/dist/plugins/codeblock/CodeBlockNode.d.ts +0 -100
- package/dist/plugins/codeblock/CodeBlockVisitor.d.ts +0 -4
- package/dist/plugins/codeblock/MdastCodeVisitor.d.ts +0 -3
- package/dist/plugins/codeblock/index.d.ts +0 -787
- package/dist/plugins/codemirror/CodeMirrorEditor.d.ts +0 -3
- package/dist/plugins/codemirror/index.d.ts +0 -1038
- package/dist/plugins/core/GenericHTMLNode.d.ts +0 -38
- package/dist/plugins/core/Icon.d.ts +0 -6
- package/dist/plugins/core/LexicalGenericHTMLNodeVisitor.d.ts +0 -4
- package/dist/plugins/core/LexicalLinebreakVisitor.d.ts +0 -4
- package/dist/plugins/core/LexicalParagraphVisitor.d.ts +0 -4
- package/dist/plugins/core/LexicalRootVisitor.d.ts +0 -4
- package/dist/plugins/core/LexicalTextVisitor.d.ts +0 -5
- package/dist/plugins/core/MdastBreakVisitor.d.ts +0 -3
- package/dist/plugins/core/MdastFormattingVisitor.d.ts +0 -4
- package/dist/plugins/core/MdastHTMLNode.d.ts +0 -13
- package/dist/plugins/core/MdastHTMLVisitor.d.ts +0 -3
- package/dist/plugins/core/MdastInlineCodeVisitor.d.ts +0 -3
- package/dist/plugins/core/MdastParagraphVisitor.d.ts +0 -3
- package/dist/plugins/core/MdastRootVisitor.d.ts +0 -3
- package/dist/plugins/core/MdastTextVisitor.d.ts +0 -3
- package/dist/plugins/core/NestedLexicalEditor.d.ts +0 -92
- package/dist/plugins/core/PropertyPopover.d.ts +0 -23
- package/dist/plugins/core/SharedHistoryPlugin.d.ts +0 -2
- package/dist/plugins/core/index.d.ts +0 -583
- package/dist/plugins/core/ui/DownshiftAutoComplete.d.ts +0 -15
- package/dist/plugins/core/ui/PopoverUtils.d.ts +0 -4
- package/dist/plugins/diff-source/DiffSourceWrapper.d.ts +0 -4
- package/dist/plugins/diff-source/DiffViewer.d.ts +0 -2
- package/dist/plugins/diff-source/SourceEditor.d.ts +0 -4
- package/dist/plugins/diff-source/index.d.ts +0 -725
- package/dist/plugins/directives/DirectiveNode.d.ts +0 -51
- package/dist/plugins/directives/DirectiveVisitor.d.ts +0 -4
- package/dist/plugins/directives/MdastDirectiveVisitor.d.ts +0 -3
- package/dist/plugins/directives/index.d.ts +0 -773
- package/dist/plugins/frontmatter/FrontmatterEditor.d.ts +0 -6
- package/dist/plugins/frontmatter/FrontmatterNode.d.ts +0 -35
- package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.d.ts +0 -4
- package/dist/plugins/frontmatter/MdastFrontmatterVisitor.d.ts +0 -3
- package/dist/plugins/frontmatter/index.d.ts +0 -717
- package/dist/plugins/headings/LexicalHeadingVisitor.d.ts +0 -4
- package/dist/plugins/headings/MdastHeadingVisitor.d.ts +0 -3
- package/dist/plugins/headings/index.d.ts +0 -707
- package/dist/plugins/image/ImageDialog.d.ts +0 -2
- package/dist/plugins/image/ImageEditor.d.ts +0 -10
- package/dist/plugins/image/ImageNode.d.ts +0 -65
- package/dist/plugins/image/ImageResizer.d.ts +0 -18
- package/dist/plugins/image/LexicalImageVisitor.d.ts +0 -4
- package/dist/plugins/image/MdastImageVisitor.d.ts +0 -6
- package/dist/plugins/image/index.d.ts +0 -804
- package/dist/plugins/jsx/LexicalJsxNode.d.ts +0 -54
- package/dist/plugins/jsx/LexicalJsxVisitor.d.ts +0 -4
- package/dist/plugins/jsx/MdastMdxJsEsmVisitor.d.ts +0 -3
- package/dist/plugins/jsx/MdastMdxJsxElementVisitor.d.ts +0 -3
- package/dist/plugins/jsx/index.d.ts +0 -779
- package/dist/plugins/link/AutoLinkPlugin.d.ts +0 -9
- package/dist/plugins/link/LexicalLinkVisitor.d.ts +0 -4
- package/dist/plugins/link/MdastLinkVisitor.d.ts +0 -3
- package/dist/plugins/link/index.d.ts +0 -101
- package/dist/plugins/link-dialog/LinkDialog.d.ts +0 -16
- package/dist/plugins/link-dialog/index.d.ts +0 -670
- package/dist/plugins/lists/LexicalListItemVisitor.d.ts +0 -4
- package/dist/plugins/lists/LexicalListVisitor.d.ts +0 -4
- package/dist/plugins/lists/MdastListItemVisitor.d.ts +0 -3
- package/dist/plugins/lists/MdastListVisitor.d.ts +0 -3
- package/dist/plugins/lists/index.d.ts +0 -703
- package/dist/plugins/markdown-shortcut/index.d.ts +0 -80
- package/dist/plugins/quote/LexicalQuoteVisitor.d.ts +0 -4
- package/dist/plugins/quote/MdastBlockQuoteVisitor.d.ts +0 -3
- package/dist/plugins/quote/index.d.ts +0 -480
- package/dist/plugins/sandpack/SandpackEditor.d.ts +0 -7
- package/dist/plugins/sandpack/index.d.ts +0 -1077
- package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +0 -4
- package/dist/plugins/table/LexicalTableVisitor.d.ts +0 -4
- package/dist/plugins/table/MdastTableVisitor.d.ts +0 -3
- package/dist/plugins/table/TableEditor.d.ts +0 -21
- package/dist/plugins/table/TableNode.d.ts +0 -52
- package/dist/plugins/table/index.d.ts +0 -704
- package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.d.ts +0 -4
- package/dist/plugins/thematic-break/MdastThematicBreakVisitor.d.ts +0 -3
- package/dist/plugins/thematic-break/index.d.ts +0 -693
- package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +0 -6
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +0 -5
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +0 -6
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +0 -7
- package/dist/plugins/toolbar/components/CodeToggle.d.ts +0 -6
- package/dist/plugins/toolbar/components/CreateLink.d.ts +0 -6
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +0 -18
- package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +0 -6
- package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +0 -7
- package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +0 -6
- package/dist/plugins/toolbar/components/InsertImage.d.ts +0 -6
- package/dist/plugins/toolbar/components/InsertSandpack.d.ts +0 -6
- package/dist/plugins/toolbar/components/InsertTable.d.ts +0 -6
- package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +0 -6
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +0 -7
- package/dist/plugins/toolbar/components/ListsToggle.d.ts +0 -7
- package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +0 -7
- package/dist/plugins/toolbar/components/UndoRedo.d.ts +0 -5
- package/dist/plugins/toolbar/index.d.ts +0 -564
- package/dist/plugins/toolbar/primitives/DialogButton.d.ts +0 -40
- package/dist/plugins/toolbar/primitives/TooltipWrap.d.ts +0 -8
- package/dist/plugins/toolbar/primitives/select.d.ts +0 -50
- package/dist/plugins/toolbar/primitives/toolbar.d.ts +0 -163
- package/dist/styles/lexicalTheme.d.ts +0 -2
- package/dist/utils/detectMac.d.ts +0 -3
- package/dist/utils/fp.d.ts +0 -47
- package/dist/utils/isPartOftheEditorUI.d.ts +0 -1
- package/dist/utils/lexicalHelpers.d.ts +0 -11
- package/dist/utils/makeHslTransparent.d.ts +0 -1
- package/dist/utils/mergeStyleAttributes.d.ts +0 -1
- package/dist/utils/uuid4.d.ts +0 -1
- package/dist/utils/voidEmitter.d.ts +0 -14
- package/dist/utils/whitespaceConversion.d.ts +0 -2
- package/dist/utils/whitespaceConversion.js +0 -9
|
@@ -1,202 +1,116 @@
|
|
|
1
|
+
import { realmPlugin } from "../../RealmWithPlugins.js";
|
|
1
2
|
import { createEmptyHistoryState } from "@lexical/react/LexicalHistoryPlugin.js";
|
|
2
3
|
import { $isHeadingNode } from "@lexical/rich-text";
|
|
3
4
|
import { $setBlocksType } from "@lexical/selection";
|
|
4
5
|
import { $findMatchingParent, $wrapNodeInElement, $insertNodeToNearestRoot } from "@lexical/utils";
|
|
5
|
-
import {
|
|
6
|
+
import { Cell, withLatestFrom, Signal, filter, scan } from "@mdxeditor/gurx";
|
|
7
|
+
import { createCommand, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, $getRoot, $setSelection, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, FOCUS_COMMAND, KEY_DOWN_COMMAND, $isDecoratorNode, BLUR_COMMAND, $getSelection, $isRangeSelection, $insertNodes, $createParagraphNode, ParagraphNode, TextNode } from "lexical";
|
|
8
|
+
import { mdxJsxFromMarkdown, mdxJsxToMarkdown } from "mdast-util-mdx-jsx";
|
|
9
|
+
import { mdxJsx } from "micromark-extension-mdx-jsx";
|
|
6
10
|
import { exportMarkdownFromLexical } from "../../exportMarkdownFromLexical.js";
|
|
7
11
|
import { importMarkdownToLexical, MarkdownParseError, UnrecognizedMarkdownConstructError } from "../../importMarkdownToLexical.js";
|
|
12
|
+
import { controlOrMeta } from "../../utils/detectMac.js";
|
|
13
|
+
import { noop } from "../../utils/fp.js";
|
|
14
|
+
import { GenericHTMLNode } from "./GenericHTMLNode.js";
|
|
15
|
+
import { $createGenericHTMLNode, $isGenericHTMLNode, TYPE_NAME } from "./GenericHTMLNode.js";
|
|
16
|
+
import { LexicalGenericHTMLVisitor } from "./LexicalGenericHTMLNodeVisitor.js";
|
|
8
17
|
import { LexicalLinebreakVisitor } from "./LexicalLinebreakVisitor.js";
|
|
9
18
|
import { LexicalParagraphVisitor } from "./LexicalParagraphVisitor.js";
|
|
10
19
|
import { LexicalRootVisitor } from "./LexicalRootVisitor.js";
|
|
11
20
|
import { LexicalTextVisitor } from "./LexicalTextVisitor.js";
|
|
21
|
+
import { MdastBreakVisitor } from "./MdastBreakVisitor.js";
|
|
12
22
|
import { MdastFormattingVisitor } from "./MdastFormattingVisitor.js";
|
|
23
|
+
import { MdastHTMLVisitor } from "./MdastHTMLVisitor.js";
|
|
13
24
|
import { MdastInlineCodeVisitor } from "./MdastInlineCodeVisitor.js";
|
|
14
25
|
import { MdastParagraphVisitor } from "./MdastParagraphVisitor.js";
|
|
15
26
|
import { MdastRootVisitor } from "./MdastRootVisitor.js";
|
|
16
27
|
import { MdastTextVisitor } from "./MdastTextVisitor.js";
|
|
17
28
|
import { SharedHistoryPlugin } from "./SharedHistoryPlugin.js";
|
|
18
|
-
import { noop } from "../../utils/fp.js";
|
|
19
|
-
import { controlOrMeta } from "../../utils/detectMac.js";
|
|
20
|
-
import { MdastBreakVisitor } from "./MdastBreakVisitor.js";
|
|
21
|
-
import { mdxJsxFromMarkdown, mdxJsxToMarkdown } from "mdast-util-mdx-jsx";
|
|
22
|
-
import { mdxJsx } from "micromark-extension-mdx-jsx";
|
|
23
|
-
import { MdastHTMLVisitor } from "./MdastHTMLVisitor.js";
|
|
24
|
-
import { GenericHTMLNode } from "./GenericHTMLNode.js";
|
|
25
|
-
import { $createGenericHTMLNode, $isGenericHTMLNode } from "./GenericHTMLNode.js";
|
|
26
|
-
import { LexicalGenericHTMLVisitor } from "./LexicalGenericHTMLNodeVisitor.js";
|
|
27
|
-
import { system } from "../../gurx/realmFactory.js";
|
|
28
|
-
import { realmPlugin } from "../../gurx/react.js";
|
|
29
29
|
const NESTED_EDITOR_UPDATED_COMMAND = createCommand("NESTED_EDITOR_UPDATED_COMMAND");
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
node
|
|
45
|
-
);
|
|
46
|
-
return appendNode;
|
|
47
|
-
}
|
|
48
|
-
const rootEditor = r.node(null);
|
|
49
|
-
const activeEditor = r.node(null, true);
|
|
50
|
-
const contentEditableClassName = r.node("");
|
|
51
|
-
const readOnly = r.node(false);
|
|
52
|
-
const placeholder = r.node("");
|
|
53
|
-
const autoFocus = r.node(false);
|
|
54
|
-
const inFocus = r.node(false, true);
|
|
55
|
-
const currentFormat = r.node(0, true);
|
|
56
|
-
const markdownProcessingError = r.node(null);
|
|
57
|
-
const markdownErrorSignal = r.node();
|
|
30
|
+
const rootEditor$ = Cell(null);
|
|
31
|
+
const activeEditor$ = Cell(null);
|
|
32
|
+
const contentEditableClassName$ = Cell("");
|
|
33
|
+
const readOnly$ = Cell(false, (r) => {
|
|
34
|
+
r.sub(r.pipe(readOnly$, withLatestFrom(rootEditor$)), ([readOnly, rootEditor]) => {
|
|
35
|
+
rootEditor == null ? void 0 : rootEditor.setEditable(!readOnly);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
const placeholder$ = Cell("");
|
|
39
|
+
const autoFocus$ = Cell(false);
|
|
40
|
+
const inFocus$ = Cell(false);
|
|
41
|
+
const currentFormat$ = Cell(0);
|
|
42
|
+
const markdownProcessingError$ = Cell(null);
|
|
43
|
+
const markdownErrorSignal$ = Signal((r) => {
|
|
58
44
|
r.link(
|
|
59
45
|
r.pipe(
|
|
60
|
-
markdownProcessingError
|
|
61
|
-
|
|
46
|
+
markdownProcessingError$,
|
|
47
|
+
filter((e) => e !== null)
|
|
62
48
|
),
|
|
63
|
-
markdownErrorSignal
|
|
49
|
+
markdownErrorSignal$
|
|
64
50
|
);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const editorInFocus = r.node(null);
|
|
70
|
-
const onBlur = r.node();
|
|
71
|
-
const iconComponentFor = r.node((name) => {
|
|
72
|
-
throw new Error(`No icon component for ${name}`);
|
|
51
|
+
});
|
|
52
|
+
const applyFormat$ = Signal((r) => {
|
|
53
|
+
r.sub(r.pipe(applyFormat$, withLatestFrom(activeEditor$)), ([format, theEditor]) => {
|
|
54
|
+
theEditor == null ? void 0 : theEditor.dispatchCommand(FORMAT_TEXT_COMMAND, format);
|
|
73
55
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
teardown();
|
|
80
|
-
});
|
|
81
|
-
return activeEditorValue ? subs.map((s) => s(activeEditorValue)) : [];
|
|
82
|
-
}, []);
|
|
83
|
-
r.pipe(r.combine(activeEditorSubscriptions, activeEditor), rebind());
|
|
84
|
-
r.pipe(r.combine(rootEditorSubscriptions, rootEditor), rebind());
|
|
85
|
-
const createRootEditorSubscription = createAppendNodeFor(rootEditorSubscriptions);
|
|
86
|
-
const createActiveEditorSubscription = createAppendNodeFor(activeEditorSubscriptions);
|
|
87
|
-
function handleSelectionChange() {
|
|
88
|
-
const selection = $getSelection();
|
|
89
|
-
if ($isRangeSelection(selection)) {
|
|
90
|
-
r.pubKeys({
|
|
91
|
-
currentSelection: selection,
|
|
92
|
-
currentFormat: selection.format
|
|
93
|
-
});
|
|
56
|
+
});
|
|
57
|
+
const currentSelection$ = Cell(null, (r) => {
|
|
58
|
+
r.sub(r.pipe(currentSelection$, withLatestFrom(activeEditor$)), ([selection, theEditor]) => {
|
|
59
|
+
if (!selection || !theEditor) {
|
|
60
|
+
return;
|
|
94
61
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
(_, theActiveEditor) => {
|
|
100
|
-
r.pubIn({
|
|
101
|
-
[activeEditor.key]: theActiveEditor,
|
|
102
|
-
[inFocus.key]: true
|
|
103
|
-
});
|
|
104
|
-
if (theActiveEditor._parentEditor === null) {
|
|
105
|
-
theActiveEditor.getEditorState().read(() => {
|
|
106
|
-
r.pub(editorInFocus, {
|
|
107
|
-
rootNode: $getRoot(),
|
|
108
|
-
editorType: "lexical"
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
handleSelectionChange();
|
|
113
|
-
return false;
|
|
114
|
-
},
|
|
115
|
-
COMMAND_PRIORITY_CRITICAL
|
|
116
|
-
);
|
|
117
|
-
});
|
|
118
|
-
r.pub(createRootEditorSubscription, (theRootEditor) => {
|
|
119
|
-
return theRootEditor.registerUpdateListener(({ dirtyElements, dirtyLeaves, editorState }) => {
|
|
120
|
-
const err = r.getValue(markdownProcessingError);
|
|
121
|
-
if (err !== null) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (dirtyElements.size === 0 && dirtyLeaves.size === 0) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
let theNewMarkdownValue;
|
|
128
|
-
editorState.read(() => {
|
|
129
|
-
theNewMarkdownValue = exportMarkdownFromLexical({
|
|
130
|
-
root: $getRoot(),
|
|
131
|
-
visitors: r.getValue(exportVisitors),
|
|
132
|
-
jsxComponentDescriptors: r.getValue(jsxComponentDescriptors),
|
|
133
|
-
toMarkdownExtensions: r.getValue(toMarkdownExtensions),
|
|
134
|
-
toMarkdownOptions: r.getValue(toMarkdownOptions),
|
|
135
|
-
jsxIsAvailable: r.getValue(jsxIsAvailable)
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
r.pub(markdown, theNewMarkdownValue.trim());
|
|
62
|
+
const anchorNode = selection.anchor.getNode();
|
|
63
|
+
let element = anchorNode.getKey() === "root" ? anchorNode : $findMatchingParent(anchorNode, (e) => {
|
|
64
|
+
const parent = e.getParent();
|
|
65
|
+
return parent !== null && $isRootOrShadowRoot(parent);
|
|
139
66
|
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const markdown = r.node("", true);
|
|
143
|
-
const markdownSignal = r.node();
|
|
144
|
-
r.link(markdown, markdownSignal);
|
|
145
|
-
r.link(initialMarkdown, markdown);
|
|
146
|
-
const importVisitors = r.node([]);
|
|
147
|
-
const syntaxExtensions = r.node([]);
|
|
148
|
-
const mdastExtensions = r.node([]);
|
|
149
|
-
const usedLexicalNodes = r.node([]);
|
|
150
|
-
const exportVisitors = r.node([]);
|
|
151
|
-
const toMarkdownExtensions = r.node([]);
|
|
152
|
-
const toMarkdownOptions = r.node({}, true);
|
|
153
|
-
const jsxIsAvailable = r.node(false);
|
|
154
|
-
const jsxComponentDescriptors = r.node([]);
|
|
155
|
-
const editorRootElementRef = r.node(null);
|
|
156
|
-
const addLexicalNode = createAppendNodeFor(usedLexicalNodes);
|
|
157
|
-
const addImportVisitor = createAppendNodeFor(importVisitors);
|
|
158
|
-
const addSyntaxExtension = createAppendNodeFor(syntaxExtensions);
|
|
159
|
-
const addMdastExtension = createAppendNodeFor(mdastExtensions);
|
|
160
|
-
const addExportVisitor = createAppendNodeFor(exportVisitors);
|
|
161
|
-
const addToMarkdownExtension = createAppendNodeFor(toMarkdownExtensions);
|
|
162
|
-
const setMarkdown = r.node();
|
|
163
|
-
function tryImportingMarkdown(markdownValue) {
|
|
164
|
-
try {
|
|
165
|
-
importMarkdownToLexical({
|
|
166
|
-
root: $getRoot(),
|
|
167
|
-
visitors: r.getValue(importVisitors),
|
|
168
|
-
mdastExtensions: r.getValue(mdastExtensions),
|
|
169
|
-
markdown: markdownValue,
|
|
170
|
-
syntaxExtensions: r.getValue(syntaxExtensions)
|
|
171
|
-
});
|
|
172
|
-
r.pub(markdownProcessingError, null);
|
|
173
|
-
} catch (e) {
|
|
174
|
-
if (e instanceof MarkdownParseError || e instanceof UnrecognizedMarkdownConstructError) {
|
|
175
|
-
r.pubIn({
|
|
176
|
-
[markdown.key]: markdownValue,
|
|
177
|
-
[markdownProcessingError.key]: {
|
|
178
|
-
error: e.message,
|
|
179
|
-
source: markdown
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
} else {
|
|
183
|
-
throw e;
|
|
184
|
-
}
|
|
67
|
+
if (element === null) {
|
|
68
|
+
element = anchorNode.getTopLevelElementOrThrow();
|
|
185
69
|
}
|
|
186
|
-
|
|
70
|
+
const elementKey = element.getKey();
|
|
71
|
+
const elementDOM = theEditor.getElementByKey(elementKey);
|
|
72
|
+
if (elementDOM !== null) {
|
|
73
|
+
const blockType = $isHeadingNode(element) ? element.getTag() : element.getType();
|
|
74
|
+
r.pub(currentBlockType$, blockType);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
const initialMarkdown$ = Cell("");
|
|
79
|
+
const markdown$ = Cell("");
|
|
80
|
+
const markdownSignal$ = Signal((r) => {
|
|
81
|
+
r.link(markdown$, markdownSignal$);
|
|
82
|
+
r.link(initialMarkdown$, markdown$);
|
|
83
|
+
});
|
|
84
|
+
const importVisitors$ = Cell([]);
|
|
85
|
+
const syntaxExtensions$ = Cell([]);
|
|
86
|
+
const mdastExtensions$ = Cell([]);
|
|
87
|
+
const usedLexicalNodes$ = Cell([]);
|
|
88
|
+
const exportVisitors$ = Cell([]);
|
|
89
|
+
const toMarkdownExtensions$ = Cell([]);
|
|
90
|
+
const toMarkdownOptions$ = Cell({});
|
|
91
|
+
const jsxIsAvailable$ = Cell(false);
|
|
92
|
+
const jsxComponentDescriptors$ = Cell([]);
|
|
93
|
+
const editorRootElementRef$ = Cell(null);
|
|
94
|
+
const addLexicalNode$ = Appender(usedLexicalNodes$);
|
|
95
|
+
const addImportVisitor$ = Appender(importVisitors$);
|
|
96
|
+
const addSyntaxExtension$ = Appender(syntaxExtensions$);
|
|
97
|
+
const addMdastExtension$ = Appender(mdastExtensions$);
|
|
98
|
+
const addExportVisitor$ = Appender(exportVisitors$);
|
|
99
|
+
const addToMarkdownExtension$ = Appender(toMarkdownExtensions$);
|
|
100
|
+
const setMarkdown$ = Signal((r) => {
|
|
187
101
|
r.sub(
|
|
188
102
|
r.pipe(
|
|
189
|
-
setMarkdown
|
|
190
|
-
|
|
191
|
-
|
|
103
|
+
setMarkdown$,
|
|
104
|
+
withLatestFrom(markdown$, rootEditor$, inFocus$),
|
|
105
|
+
filter(([newMarkdown, oldMarkdown]) => {
|
|
192
106
|
return newMarkdown.trim() !== oldMarkdown.trim();
|
|
193
107
|
})
|
|
194
108
|
),
|
|
195
|
-
([theNewMarkdownValue, , editor,
|
|
109
|
+
([theNewMarkdownValue, , editor, inFocus]) => {
|
|
196
110
|
editor == null ? void 0 : editor.update(() => {
|
|
197
111
|
$getRoot().clear();
|
|
198
|
-
tryImportingMarkdown(theNewMarkdownValue);
|
|
199
|
-
if (!
|
|
112
|
+
tryImportingMarkdown(r, theNewMarkdownValue);
|
|
113
|
+
if (!inFocus) {
|
|
200
114
|
$setSelection(null);
|
|
201
115
|
} else {
|
|
202
116
|
editor.focus();
|
|
@@ -204,124 +118,232 @@ const coreSystem = system((r) => {
|
|
|
204
118
|
});
|
|
205
119
|
}
|
|
206
120
|
);
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (autoFocusValue === true) {
|
|
214
|
-
setTimeout(() => theRootEditor.focus(noop, { defaultSelection: "rootStart" }));
|
|
215
|
-
return;
|
|
121
|
+
});
|
|
122
|
+
function rebind() {
|
|
123
|
+
return scan((teardowns, [subs, activeEditorValue]) => {
|
|
124
|
+
teardowns.forEach((teardown) => {
|
|
125
|
+
if (!teardown) {
|
|
126
|
+
throw new Error("You have a subscription that does not return a teardown");
|
|
216
127
|
}
|
|
217
|
-
|
|
218
|
-
() => theRootEditor.focus(noop, {
|
|
219
|
-
defaultSelection: autoFocusValue.defaultSelection ?? "rootStart"
|
|
220
|
-
})
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
r.pub(createActiveEditorSubscription, (editor) => {
|
|
225
|
-
return editor.registerUpdateListener(({ editorState }) => {
|
|
226
|
-
editorState.read(() => {
|
|
227
|
-
handleSelectionChange();
|
|
228
|
-
});
|
|
128
|
+
teardown();
|
|
229
129
|
});
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
130
|
+
return activeEditorValue ? subs.map((s) => s(activeEditorValue)) : [];
|
|
131
|
+
}, []);
|
|
132
|
+
}
|
|
133
|
+
const activeEditorSubscriptions$ = Cell([], (r) => {
|
|
134
|
+
r.pipe(r.combine(activeEditorSubscriptions$, activeEditor$), rebind());
|
|
135
|
+
});
|
|
136
|
+
const rootEditorSubscriptions$ = Cell([], (r) => {
|
|
137
|
+
r.pipe(r.combine(rootEditorSubscriptions$, rootEditor$), rebind());
|
|
138
|
+
});
|
|
139
|
+
const editorInFocus$ = Cell(null);
|
|
140
|
+
const onBlur$ = Signal();
|
|
141
|
+
const iconComponentFor$ = Cell((name) => {
|
|
142
|
+
throw new Error(`No icon component for ${name}`);
|
|
143
|
+
});
|
|
144
|
+
function Appender(cell$, init) {
|
|
145
|
+
return Signal((r, sig$) => {
|
|
146
|
+
r.changeWith(cell$, sig$, (values, newValue) => {
|
|
147
|
+
if (!Array.isArray(newValue)) {
|
|
148
|
+
newValue = [newValue];
|
|
149
|
+
}
|
|
150
|
+
let result = values;
|
|
151
|
+
for (const v of newValue) {
|
|
152
|
+
if (!values.includes(v)) {
|
|
153
|
+
result = [...result, v];
|
|
245
154
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
);
|
|
250
|
-
});
|
|
251
|
-
r.pub(createRootEditorSubscription, (theEditor) => {
|
|
252
|
-
return theEditor.registerCommand(
|
|
253
|
-
FOCUS_COMMAND,
|
|
254
|
-
() => {
|
|
255
|
-
r.pub(inFocus, true);
|
|
256
|
-
return false;
|
|
257
|
-
},
|
|
258
|
-
COMMAND_PRIORITY_CRITICAL
|
|
259
|
-
);
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
});
|
|
158
|
+
init == null ? void 0 : init(r, sig$);
|
|
260
159
|
});
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
160
|
+
}
|
|
161
|
+
function handleSelectionChange(r) {
|
|
162
|
+
const selection = $getSelection();
|
|
163
|
+
if ($isRangeSelection(selection)) {
|
|
164
|
+
r.pubIn({
|
|
165
|
+
[currentSelection$]: selection,
|
|
166
|
+
[currentFormat$]: selection.format
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const createRootEditorSubscription$ = Appender(rootEditorSubscriptions$, (r, sig$) => {
|
|
171
|
+
r.pub(sig$, [
|
|
172
|
+
(rootEditor) => {
|
|
173
|
+
return rootEditor.registerCommand(
|
|
174
|
+
SELECTION_CHANGE_COMMAND,
|
|
175
|
+
(_, theActiveEditor) => {
|
|
176
|
+
r.pubIn({
|
|
177
|
+
[activeEditor$]: theActiveEditor,
|
|
178
|
+
[inFocus$]: true
|
|
270
179
|
});
|
|
271
|
-
if (
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const rootElement = theRootEditor.getRootElement();
|
|
277
|
-
(_a = window.getSelection()) == null ? void 0 : _a.selectAllChildren(rootElement);
|
|
278
|
-
rootElement.focus({
|
|
279
|
-
preventScroll: true
|
|
180
|
+
if (theActiveEditor._parentEditor === null) {
|
|
181
|
+
theActiveEditor.getEditorState().read(() => {
|
|
182
|
+
r.pub(editorInFocus$, {
|
|
183
|
+
rootNode: $getRoot(),
|
|
184
|
+
editorType: "lexical"
|
|
280
185
|
});
|
|
281
186
|
});
|
|
282
|
-
return true;
|
|
283
187
|
}
|
|
188
|
+
handleSelectionChange(r);
|
|
189
|
+
return false;
|
|
190
|
+
},
|
|
191
|
+
COMMAND_PRIORITY_CRITICAL
|
|
192
|
+
);
|
|
193
|
+
},
|
|
194
|
+
// Export handler
|
|
195
|
+
(rootEditor) => {
|
|
196
|
+
return rootEditor.registerUpdateListener(({ dirtyElements, dirtyLeaves, editorState }) => {
|
|
197
|
+
const err = r.getValue(markdownProcessingError$);
|
|
198
|
+
if (err !== null) {
|
|
199
|
+
return;
|
|
284
200
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
201
|
+
if (dirtyElements.size === 0 && dirtyLeaves.size === 0) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
let theNewMarkdownValue;
|
|
205
|
+
editorState.read(() => {
|
|
206
|
+
theNewMarkdownValue = exportMarkdownFromLexical({
|
|
207
|
+
root: $getRoot(),
|
|
208
|
+
visitors: r.getValue(exportVisitors$),
|
|
209
|
+
jsxComponentDescriptors: r.getValue(jsxComponentDescriptors$),
|
|
210
|
+
toMarkdownExtensions: r.getValue(toMarkdownExtensions$),
|
|
211
|
+
toMarkdownOptions: r.getValue(toMarkdownOptions$),
|
|
212
|
+
jsxIsAvailable: r.getValue(jsxIsAvailable$)
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
r.pub(markdown$, theNewMarkdownValue.trim());
|
|
216
|
+
});
|
|
217
|
+
},
|
|
218
|
+
(rootEditor) => {
|
|
219
|
+
return rootEditor.registerCommand(
|
|
220
|
+
FOCUS_COMMAND,
|
|
221
|
+
() => {
|
|
222
|
+
r.pub(inFocus$, true);
|
|
223
|
+
return false;
|
|
224
|
+
},
|
|
225
|
+
COMMAND_PRIORITY_CRITICAL
|
|
226
|
+
);
|
|
227
|
+
},
|
|
228
|
+
// Fixes select all when frontmatter is present
|
|
229
|
+
(rootEditor) => {
|
|
230
|
+
return rootEditor.registerCommand(
|
|
231
|
+
KEY_DOWN_COMMAND,
|
|
232
|
+
(event) => {
|
|
233
|
+
const { keyCode, ctrlKey, metaKey } = event;
|
|
234
|
+
if (keyCode === 65 && controlOrMeta(metaKey, ctrlKey)) {
|
|
235
|
+
let shouldOverride = false;
|
|
236
|
+
rootEditor.getEditorState().read(() => {
|
|
237
|
+
shouldOverride = $isDecoratorNode($getRoot().getFirstChild()) || $isDecoratorNode($getRoot().getLastChild());
|
|
238
|
+
});
|
|
239
|
+
if (shouldOverride) {
|
|
240
|
+
event.preventDefault();
|
|
241
|
+
event.stopImmediatePropagation();
|
|
242
|
+
rootEditor.update(() => {
|
|
243
|
+
var _a;
|
|
244
|
+
const rootElement = rootEditor.getRootElement();
|
|
245
|
+
(_a = window.getSelection()) == null ? void 0 : _a.selectAllChildren(rootElement);
|
|
246
|
+
rootElement.focus({
|
|
247
|
+
preventScroll: true
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return false;
|
|
254
|
+
},
|
|
255
|
+
COMMAND_PRIORITY_CRITICAL
|
|
256
|
+
);
|
|
307
257
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
258
|
+
]);
|
|
259
|
+
});
|
|
260
|
+
const createActiveEditorSubscription$ = Appender(activeEditorSubscriptions$, (r, sig$) => {
|
|
261
|
+
r.pub(sig$, [
|
|
262
|
+
(editor) => {
|
|
263
|
+
return editor.registerUpdateListener(({ editorState }) => {
|
|
264
|
+
editorState.read(() => {
|
|
265
|
+
handleSelectionChange(r);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
},
|
|
269
|
+
(editor) => {
|
|
270
|
+
return editor.registerCommand(
|
|
271
|
+
BLUR_COMMAND,
|
|
272
|
+
(payload) => {
|
|
273
|
+
var _a;
|
|
274
|
+
const theRootEditor = r.getValue(rootEditor$);
|
|
275
|
+
if (theRootEditor) {
|
|
276
|
+
const movingOutside = !((_a = theRootEditor.getRootElement()) == null ? void 0 : _a.contains(payload.relatedTarget));
|
|
277
|
+
if (movingOutside) {
|
|
278
|
+
r.pubIn({
|
|
279
|
+
[inFocus$]: false,
|
|
280
|
+
[onBlur$]: payload
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return false;
|
|
285
|
+
},
|
|
286
|
+
COMMAND_PRIORITY_CRITICAL
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
]);
|
|
290
|
+
});
|
|
291
|
+
function tryImportingMarkdown(r, markdownValue) {
|
|
292
|
+
try {
|
|
293
|
+
importMarkdownToLexical({
|
|
294
|
+
root: $getRoot(),
|
|
295
|
+
visitors: r.getValue(importVisitors$),
|
|
296
|
+
mdastExtensions: r.getValue(mdastExtensions$),
|
|
297
|
+
markdown: markdownValue,
|
|
298
|
+
syntaxExtensions: r.getValue(syntaxExtensions$)
|
|
312
299
|
});
|
|
313
|
-
|
|
314
|
-
|
|
300
|
+
r.pub(markdownProcessingError$, null);
|
|
301
|
+
} catch (e) {
|
|
302
|
+
if (e instanceof MarkdownParseError || e instanceof UnrecognizedMarkdownConstructError) {
|
|
303
|
+
r.pubIn({
|
|
304
|
+
[markdown$]: markdownValue,
|
|
305
|
+
[markdownProcessingError$]: {
|
|
306
|
+
error: e.message,
|
|
307
|
+
source: markdownValue
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
} else {
|
|
311
|
+
throw e;
|
|
315
312
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
const initialRootEditorState$ = Cell(null, (r) => {
|
|
316
|
+
r.pub(initialRootEditorState$, (theRootEditor) => {
|
|
317
|
+
r.pub(rootEditor$, theRootEditor);
|
|
318
|
+
r.pub(activeEditor$, theRootEditor);
|
|
319
|
+
tryImportingMarkdown(r, r.getValue(initialMarkdown$));
|
|
320
|
+
const autoFocusValue = r.getValue(autoFocus$);
|
|
321
|
+
if (autoFocusValue) {
|
|
322
|
+
if (autoFocusValue === true) {
|
|
323
|
+
setTimeout(() => theRootEditor.focus(noop, { defaultSelection: "rootStart" }));
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
setTimeout(
|
|
327
|
+
() => theRootEditor.focus(noop, {
|
|
328
|
+
defaultSelection: autoFocusValue.defaultSelection ?? "rootStart"
|
|
329
|
+
})
|
|
330
|
+
);
|
|
321
331
|
}
|
|
322
332
|
});
|
|
323
|
-
|
|
324
|
-
|
|
333
|
+
});
|
|
334
|
+
const composerChildren$ = Cell([]);
|
|
335
|
+
const addComposerChild$ = Appender(composerChildren$);
|
|
336
|
+
const topAreaChildren$ = Cell([]);
|
|
337
|
+
const addTopAreaChild$ = Appender(topAreaChildren$);
|
|
338
|
+
const editorWrappers$ = Cell([]);
|
|
339
|
+
const addEditorWrapper$ = Appender(editorWrappers$);
|
|
340
|
+
const nestedEditorChildren$ = Cell([]);
|
|
341
|
+
const addNestedEditorChild$ = Appender(nestedEditorChildren$);
|
|
342
|
+
const historyState$ = Cell(createEmptyHistoryState());
|
|
343
|
+
const currentBlockType$ = Cell("");
|
|
344
|
+
const applyBlockType$ = Signal();
|
|
345
|
+
const convertSelectionToNode$ = Signal((r) => {
|
|
346
|
+
r.sub(r.pipe(convertSelectionToNode$, withLatestFrom(activeEditor$)), ([factory, editor]) => {
|
|
325
347
|
editor == null ? void 0 : editor.update(() => {
|
|
326
348
|
const selection = $getSelection();
|
|
327
349
|
if ($isRangeSelection(selection)) {
|
|
@@ -332,8 +354,9 @@ const coreSystem = system((r) => {
|
|
|
332
354
|
}
|
|
333
355
|
});
|
|
334
356
|
});
|
|
335
|
-
|
|
336
|
-
|
|
357
|
+
});
|
|
358
|
+
const insertDecoratorNode$ = Signal((r) => {
|
|
359
|
+
r.sub(r.pipe(insertDecoratorNode$, withLatestFrom(activeEditor$)), ([nodeFactory, theEditor]) => {
|
|
337
360
|
theEditor == null ? void 0 : theEditor.focus(
|
|
338
361
|
() => {
|
|
339
362
|
theEditor.getEditorState().read(() => {
|
|
@@ -365,126 +388,144 @@ const coreSystem = system((r) => {
|
|
|
365
388
|
{ defaultSelection: "rootEnd" }
|
|
366
389
|
);
|
|
367
390
|
});
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
currentFormat,
|
|
422
|
-
editorInFocus,
|
|
423
|
-
applyFormat,
|
|
424
|
-
currentBlockType,
|
|
425
|
-
applyBlockType,
|
|
426
|
-
convertSelectionToNode,
|
|
427
|
-
insertDecoratorNode,
|
|
428
|
-
// Events
|
|
429
|
-
onBlur,
|
|
430
|
-
iconComponentFor,
|
|
431
|
-
// error handling
|
|
432
|
-
markdownProcessingError,
|
|
433
|
-
markdownErrorSignal
|
|
434
|
-
};
|
|
435
|
-
}, []);
|
|
436
|
-
const [
|
|
437
|
-
/** @internal */
|
|
438
|
-
corePlugin,
|
|
439
|
-
/** @internal */
|
|
440
|
-
corePluginHooks
|
|
441
|
-
] = realmPlugin({
|
|
442
|
-
id: "core",
|
|
443
|
-
systemSpec: coreSystem,
|
|
444
|
-
applyParamsToSystem(realm, params) {
|
|
445
|
-
realm.pubKeys({
|
|
446
|
-
contentEditableClassName: params.contentEditableClassName,
|
|
447
|
-
toMarkdownOptions: params.toMarkdownOptions,
|
|
448
|
-
autoFocus: params.autoFocus,
|
|
449
|
-
placeholder: params.placeholder,
|
|
450
|
-
readOnly: params.readOnly
|
|
391
|
+
});
|
|
392
|
+
const viewMode$ = Cell("rich-text", (r) => {
|
|
393
|
+
r.sub(
|
|
394
|
+
r.pipe(
|
|
395
|
+
viewMode$,
|
|
396
|
+
scan(
|
|
397
|
+
(prev, next) => {
|
|
398
|
+
return {
|
|
399
|
+
current: prev.next,
|
|
400
|
+
next
|
|
401
|
+
};
|
|
402
|
+
},
|
|
403
|
+
{ current: "rich-text", next: "rich-text" }
|
|
404
|
+
),
|
|
405
|
+
withLatestFrom(markdownSourceEditorValue$)
|
|
406
|
+
),
|
|
407
|
+
([{ current }, markdownSourceFromEditor]) => {
|
|
408
|
+
if (current === "source" || current === "diff") {
|
|
409
|
+
r.pub(setMarkdown$, markdownSourceFromEditor);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
);
|
|
413
|
+
});
|
|
414
|
+
const markdownSourceEditorValue$ = Cell("", (r) => {
|
|
415
|
+
r.link(markdown$, markdownSourceEditorValue$);
|
|
416
|
+
r.link(markdownSourceEditorValue$, markdownSignal$);
|
|
417
|
+
});
|
|
418
|
+
const activePlugins$ = Cell([]);
|
|
419
|
+
const addActivePlugin$ = Appender(activePlugins$);
|
|
420
|
+
const corePlugin = realmPlugin({
|
|
421
|
+
init(r, params) {
|
|
422
|
+
r.register(createRootEditorSubscription$);
|
|
423
|
+
r.register(createActiveEditorSubscription$);
|
|
424
|
+
r.pubIn({
|
|
425
|
+
[initialMarkdown$]: params == null ? void 0 : params.initialMarkdown.trim(),
|
|
426
|
+
[iconComponentFor$]: params == null ? void 0 : params.iconComponentFor,
|
|
427
|
+
[addImportVisitor$]: [
|
|
428
|
+
MdastRootVisitor,
|
|
429
|
+
MdastParagraphVisitor,
|
|
430
|
+
MdastTextVisitor,
|
|
431
|
+
MdastFormattingVisitor,
|
|
432
|
+
MdastInlineCodeVisitor,
|
|
433
|
+
MdastBreakVisitor
|
|
434
|
+
],
|
|
435
|
+
[addLexicalNode$]: [ParagraphNode, TextNode, GenericHTMLNode],
|
|
436
|
+
[addExportVisitor$]: [
|
|
437
|
+
LexicalRootVisitor,
|
|
438
|
+
LexicalParagraphVisitor,
|
|
439
|
+
LexicalTextVisitor,
|
|
440
|
+
LexicalLinebreakVisitor,
|
|
441
|
+
LexicalGenericHTMLVisitor
|
|
442
|
+
],
|
|
443
|
+
[addComposerChild$]: SharedHistoryPlugin
|
|
451
444
|
});
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
realm.pubKey("addImportVisitor", MdastRootVisitor);
|
|
460
|
-
realm.pubKey("addImportVisitor", MdastParagraphVisitor);
|
|
461
|
-
realm.pubKey("addImportVisitor", MdastTextVisitor);
|
|
462
|
-
realm.pubKey("addImportVisitor", MdastFormattingVisitor);
|
|
463
|
-
realm.pubKey("addImportVisitor", MdastInlineCodeVisitor);
|
|
464
|
-
realm.pubKey("addImportVisitor", MdastBreakVisitor);
|
|
465
|
-
realm.pubKey("addLexicalNode", ParagraphNode);
|
|
466
|
-
realm.pubKey("addLexicalNode", TextNode);
|
|
467
|
-
realm.pubKey("addLexicalNode", GenericHTMLNode);
|
|
468
|
-
realm.pubKey("addExportVisitor", LexicalRootVisitor);
|
|
469
|
-
realm.pubKey("addExportVisitor", LexicalParagraphVisitor);
|
|
470
|
-
realm.pubKey("addExportVisitor", LexicalTextVisitor);
|
|
471
|
-
realm.pubKey("addExportVisitor", LexicalLinebreakVisitor);
|
|
472
|
-
realm.pubKey("addExportVisitor", LexicalGenericHTMLVisitor);
|
|
473
|
-
realm.pubKey("addComposerChild", SharedHistoryPlugin);
|
|
474
|
-
if (!params.suppressHtmlProcessing) {
|
|
475
|
-
realm.pubKey("addMdastExtension", mdxJsxFromMarkdown());
|
|
476
|
-
realm.pubKey("addSyntaxExtension", mdxJsx());
|
|
477
|
-
realm.pubKey("addToMarkdownExtension", mdxJsxToMarkdown());
|
|
478
|
-
realm.pubKey("addImportVisitor", MdastHTMLVisitor);
|
|
445
|
+
if (!(params == null ? void 0 : params.suppressHtmlProcessing)) {
|
|
446
|
+
r.pubIn({
|
|
447
|
+
[addMdastExtension$]: mdxJsxFromMarkdown(),
|
|
448
|
+
[addSyntaxExtension$]: mdxJsx(),
|
|
449
|
+
[addToMarkdownExtension$]: mdxJsxToMarkdown(),
|
|
450
|
+
[addImportVisitor$]: MdastHTMLVisitor
|
|
451
|
+
});
|
|
479
452
|
}
|
|
453
|
+
},
|
|
454
|
+
update(realm, params) {
|
|
455
|
+
realm.pubIn({
|
|
456
|
+
[contentEditableClassName$]: params == null ? void 0 : params.contentEditableClassName,
|
|
457
|
+
[toMarkdownOptions$]: params == null ? void 0 : params.toMarkdownOptions,
|
|
458
|
+
[autoFocus$]: params == null ? void 0 : params.autoFocus,
|
|
459
|
+
[placeholder$]: params == null ? void 0 : params.placeholder,
|
|
460
|
+
[readOnly$]: params == null ? void 0 : params.readOnly
|
|
461
|
+
});
|
|
462
|
+
realm.singletonSub(markdownSignal$, params == null ? void 0 : params.onChange);
|
|
463
|
+
realm.singletonSub(onBlur$, params == null ? void 0 : params.onBlur);
|
|
464
|
+
realm.singletonSub(markdownErrorSignal$, params == null ? void 0 : params.onError);
|
|
480
465
|
}
|
|
481
466
|
});
|
|
482
467
|
export {
|
|
483
468
|
$createGenericHTMLNode,
|
|
484
469
|
$isGenericHTMLNode,
|
|
470
|
+
Appender,
|
|
485
471
|
GenericHTMLNode,
|
|
486
472
|
NESTED_EDITOR_UPDATED_COMMAND,
|
|
473
|
+
TYPE_NAME,
|
|
474
|
+
activeEditor$,
|
|
475
|
+
activeEditorSubscriptions$,
|
|
476
|
+
activePlugins$,
|
|
477
|
+
addActivePlugin$,
|
|
478
|
+
addComposerChild$,
|
|
479
|
+
addEditorWrapper$,
|
|
480
|
+
addExportVisitor$,
|
|
481
|
+
addImportVisitor$,
|
|
482
|
+
addLexicalNode$,
|
|
483
|
+
addMdastExtension$,
|
|
484
|
+
addNestedEditorChild$,
|
|
485
|
+
addSyntaxExtension$,
|
|
486
|
+
addToMarkdownExtension$,
|
|
487
|
+
addTopAreaChild$,
|
|
488
|
+
applyBlockType$,
|
|
489
|
+
applyFormat$,
|
|
490
|
+
autoFocus$,
|
|
491
|
+
composerChildren$,
|
|
492
|
+
contentEditableClassName$,
|
|
493
|
+
convertSelectionToNode$,
|
|
487
494
|
corePlugin,
|
|
488
|
-
|
|
489
|
-
|
|
495
|
+
createActiveEditorSubscription$,
|
|
496
|
+
createRootEditorSubscription$,
|
|
497
|
+
currentBlockType$,
|
|
498
|
+
currentFormat$,
|
|
499
|
+
currentSelection$,
|
|
500
|
+
editorInFocus$,
|
|
501
|
+
editorRootElementRef$,
|
|
502
|
+
editorWrappers$,
|
|
503
|
+
exportVisitors$,
|
|
504
|
+
historyState$,
|
|
505
|
+
iconComponentFor$,
|
|
506
|
+
importVisitors$,
|
|
507
|
+
inFocus$,
|
|
508
|
+
initialMarkdown$,
|
|
509
|
+
initialRootEditorState$,
|
|
510
|
+
insertDecoratorNode$,
|
|
511
|
+
jsxComponentDescriptors$,
|
|
512
|
+
jsxIsAvailable$,
|
|
513
|
+
markdown$,
|
|
514
|
+
markdownErrorSignal$,
|
|
515
|
+
markdownProcessingError$,
|
|
516
|
+
markdownSourceEditorValue$,
|
|
517
|
+
mdastExtensions$,
|
|
518
|
+
nestedEditorChildren$,
|
|
519
|
+
onBlur$,
|
|
520
|
+
placeholder$,
|
|
521
|
+
readOnly$,
|
|
522
|
+
rootEditor$,
|
|
523
|
+
rootEditorSubscriptions$,
|
|
524
|
+
setMarkdown$,
|
|
525
|
+
syntaxExtensions$,
|
|
526
|
+
toMarkdownExtensions$,
|
|
527
|
+
toMarkdownOptions$,
|
|
528
|
+
topAreaChildren$,
|
|
529
|
+
usedLexicalNodes$,
|
|
530
|
+
viewMode$
|
|
490
531
|
};
|