@mdxeditor/editor 1.14.3 → 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 +19 -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/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 +935 -571
- 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 +103 -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
|
@@ -2,7 +2,8 @@ import { useCombobox } from "downshift";
|
|
|
2
2
|
import React__default from "react";
|
|
3
3
|
import { Controller } from "react-hook-form";
|
|
4
4
|
import styles from "../../../styles/ui.module.css.js";
|
|
5
|
-
import {
|
|
5
|
+
import { iconComponentFor$ } from "../index.js";
|
|
6
|
+
import { useCellValue } from "@mdxeditor/gurx";
|
|
6
7
|
const MAX_SUGGESTIONS = 20;
|
|
7
8
|
const DownshiftAutoComplete = (props) => {
|
|
8
9
|
if (props.suggestions.length > 0) {
|
|
@@ -21,7 +22,7 @@ const DownshiftAutoCompleteWithSuggestions = ({
|
|
|
21
22
|
setValue
|
|
22
23
|
}) => {
|
|
23
24
|
const [items, setItems] = React__default.useState(suggestions.slice(0, MAX_SUGGESTIONS));
|
|
24
|
-
const
|
|
25
|
+
const iconComponentFor = useCellValue(iconComponentFor$);
|
|
25
26
|
const enableAutoComplete = suggestions.length > 0;
|
|
26
27
|
const { isOpen, getToggleButtonProps, getMenuProps, getInputProps, highlightedIndex, getItemProps, selectedItem } = useCombobox({
|
|
27
28
|
initialInputValue,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React__default from "react";
|
|
2
2
|
import * as RadixPopover from "@radix-ui/react-popover";
|
|
3
|
-
import {
|
|
3
|
+
import { editorRootElementRef$ } from "../index.js";
|
|
4
4
|
import styles from "../../../styles/ui.module.css.js";
|
|
5
|
+
import { useCellValue } from "@mdxeditor/gurx";
|
|
5
6
|
const PopoverPortal = (props) => {
|
|
6
|
-
const
|
|
7
|
+
const editorRootElementRef = useCellValue(editorRootElementRef$);
|
|
7
8
|
return /* @__PURE__ */ React__default.createElement(RadixPopover.Portal, { ...props, container: editorRootElementRef == null ? void 0 : editorRootElementRef.current });
|
|
8
9
|
};
|
|
9
10
|
const PopoverContent = React__default.forwardRef(
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import React__default from "react";
|
|
2
|
-
import { diffSourcePluginHooks } from "./index.js";
|
|
3
2
|
import { DiffViewer } from "./DiffViewer.js";
|
|
4
3
|
import { SourceEditor } from "./SourceEditor.js";
|
|
5
|
-
import {
|
|
4
|
+
import { markdownProcessingError$, viewMode$ } from "../core/index.js";
|
|
6
5
|
import styles from "../../styles/ui.module.css.js";
|
|
6
|
+
import { useCellValues } from "@mdxeditor/gurx";
|
|
7
7
|
const DiffSourceWrapper = ({ children }) => {
|
|
8
|
-
const [error] =
|
|
9
|
-
const [viewMode] = diffSourcePluginHooks.useEmitterValues("viewMode");
|
|
8
|
+
const [error, viewMode] = useCellValues(markdownProcessingError$, viewMode$);
|
|
10
9
|
return /* @__PURE__ */ React__default.createElement("div", null, error ? /* @__PURE__ */ React__default.createElement("div", { className: styles.markdownParseError }, /* @__PURE__ */ React__default.createElement("p", null, error.error, "."), /* @__PURE__ */ React__default.createElement("p", null, "You can fix the errors in source mode and switch to rich text mode when you are ready.")) : null, /* @__PURE__ */ React__default.createElement("div", { style: { display: viewMode === "rich-text" && error == null ? "block" : "none" } }, children), viewMode === "diff" ? /* @__PURE__ */ React__default.createElement(DiffViewer, null) : null, viewMode === "source" ? /* @__PURE__ */ React__default.createElement(SourceEditor, null) : null);
|
|
11
10
|
};
|
|
12
11
|
export {
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import React__default from "react";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { diffMarkdown$, cmExtensions$ } from "./index.js";
|
|
3
|
+
import { markdown$, markdownSourceEditorValue$, onBlur$ } from "../core/index.js";
|
|
4
4
|
import { MergeView } from "@codemirror/merge";
|
|
5
5
|
import { EditorState } from "@codemirror/state";
|
|
6
6
|
import { EditorView } from "@codemirror/view";
|
|
7
7
|
import { COMMON_STATE_CONFIG_EXTENSIONS } from "./SourceEditor.js";
|
|
8
|
+
import { useCellValues, usePublisher, useCellValue } from "@mdxeditor/gurx";
|
|
8
9
|
const DiffViewer = () => {
|
|
9
|
-
const [newText] =
|
|
10
|
-
const
|
|
11
|
-
const updateMarkdown = diffSourcePluginHooks.usePublisher("markdownSourceEditorValue");
|
|
10
|
+
const [newText, oldText] = useCellValues(markdown$, diffMarkdown$);
|
|
11
|
+
const updateMarkdown = usePublisher(markdownSourceEditorValue$);
|
|
12
12
|
return /* @__PURE__ */ React__default.createElement(CmMergeView, { oldMarkdown: oldText, newMarkdown: newText, onUpdate: updateMarkdown });
|
|
13
13
|
};
|
|
14
14
|
const CmMergeView = ({ oldMarkdown, newMarkdown, onUpdate }) => {
|
|
15
15
|
const cmMergeViewRef = React__default.useRef(null);
|
|
16
|
-
const
|
|
17
|
-
const triggerOnBlur =
|
|
16
|
+
const cmExtensions = useCellValue(cmExtensions$);
|
|
17
|
+
const triggerOnBlur = usePublisher(onBlur$);
|
|
18
18
|
const ref = React__default.useCallback(
|
|
19
19
|
(el) => {
|
|
20
20
|
var _a;
|
|
@@ -4,8 +4,9 @@ import { lineNumbers, EditorView } from "@codemirror/view";
|
|
|
4
4
|
import { basicLight } from "cm6-theme-basic-light";
|
|
5
5
|
import { basicSetup } from "codemirror";
|
|
6
6
|
import React__default from "react";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { cmExtensions$ } from "./index.js";
|
|
8
|
+
import { markdown$, readOnly$, markdownSourceEditorValue$, onBlur$ } from "../core/index.js";
|
|
9
|
+
import { useCellValues, usePublisher } from "@mdxeditor/gurx";
|
|
9
10
|
const COMMON_STATE_CONFIG_EXTENSIONS = [
|
|
10
11
|
basicSetup,
|
|
11
12
|
basicLight,
|
|
@@ -14,10 +15,9 @@ const COMMON_STATE_CONFIG_EXTENSIONS = [
|
|
|
14
15
|
EditorView.lineWrapping
|
|
15
16
|
];
|
|
16
17
|
const SourceEditor = () => {
|
|
17
|
-
const [markdown2, readOnly] =
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const triggerOnBlur = corePluginHooks.usePublisher("onBlur");
|
|
18
|
+
const [markdown2, readOnly, cmExtensions] = useCellValues(markdown$, readOnly$, cmExtensions$);
|
|
19
|
+
const updateMarkdown = usePublisher(markdownSourceEditorValue$);
|
|
20
|
+
const triggerOnBlur = usePublisher(onBlur$);
|
|
21
21
|
const editorViewRef = React__default.useRef(null);
|
|
22
22
|
const ref = React__default.useCallback(
|
|
23
23
|
(el) => {
|
|
@@ -1,59 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addEditorWrapper$, viewMode$ } from "../core/index.js";
|
|
2
2
|
import { DiffSourceWrapper } from "./DiffSourceWrapper.js";
|
|
3
|
-
import {
|
|
4
|
-
import { realmPlugin } from "../../
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
r.link(markdown, markdownSourceEditorValue);
|
|
11
|
-
r.link(markdownSourceEditorValue, markdownSignal);
|
|
12
|
-
const viewMode = r.node("rich-text");
|
|
13
|
-
r.sub(
|
|
14
|
-
r.pipe(
|
|
15
|
-
viewMode,
|
|
16
|
-
r.o.scan(
|
|
17
|
-
(prev, next) => {
|
|
18
|
-
return {
|
|
19
|
-
current: prev.next,
|
|
20
|
-
next
|
|
21
|
-
};
|
|
22
|
-
},
|
|
23
|
-
{ current: "rich-text", next: "rich-text" }
|
|
24
|
-
),
|
|
25
|
-
r.o.withLatestFrom(markdownSourceEditorValue)
|
|
26
|
-
),
|
|
27
|
-
([{ current }, markdownSourceFromEditor]) => {
|
|
28
|
-
if (current === "source" || current === "diff") {
|
|
29
|
-
r.pub(setMarkdown, markdownSourceFromEditor);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
return { viewMode, diffMarkdown, markdownSourceEditorValue, cmExtensions };
|
|
34
|
-
},
|
|
35
|
-
[coreSystem]
|
|
36
|
-
);
|
|
37
|
-
const [
|
|
38
|
-
/** @internal */
|
|
39
|
-
diffSourcePlugin,
|
|
40
|
-
/** @internal */
|
|
41
|
-
diffSourcePluginHooks
|
|
42
|
-
] = realmPlugin({
|
|
43
|
-
id: "diff-source",
|
|
44
|
-
systemSpec: diffSourceSystem,
|
|
45
|
-
applyParamsToSystem: (r, params) => {
|
|
46
|
-
r.pubKey("diffMarkdown", (params == null ? void 0 : params.diffMarkdown) || "");
|
|
3
|
+
import { Cell } from "@mdxeditor/gurx";
|
|
4
|
+
import { realmPlugin } from "../../RealmWithPlugins.js";
|
|
5
|
+
const diffMarkdown$ = Cell("");
|
|
6
|
+
const cmExtensions$ = Cell([]);
|
|
7
|
+
const diffSourcePlugin = realmPlugin({
|
|
8
|
+
update: (r, params) => {
|
|
9
|
+
r.pub(diffMarkdown$, (params == null ? void 0 : params.diffMarkdown) || "");
|
|
47
10
|
},
|
|
48
11
|
init(r, params) {
|
|
49
|
-
r.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
12
|
+
r.pubIn({
|
|
13
|
+
[diffMarkdown$]: (params == null ? void 0 : params.diffMarkdown) || "",
|
|
14
|
+
[cmExtensions$]: (params == null ? void 0 : params.codeMirrorExtensions) || [],
|
|
15
|
+
[addEditorWrapper$]: DiffSourceWrapper,
|
|
16
|
+
[viewMode$]: (params == null ? void 0 : params.viewMode) || "rich-text"
|
|
17
|
+
});
|
|
53
18
|
}
|
|
54
19
|
});
|
|
55
20
|
export {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
21
|
+
cmExtensions$,
|
|
22
|
+
diffMarkdown$,
|
|
23
|
+
diffSourcePlugin
|
|
59
24
|
};
|
|
@@ -7,32 +7,48 @@ var __publicField = (obj, key, value) => {
|
|
|
7
7
|
import React__default from "react";
|
|
8
8
|
import { DecoratorNode } from "lexical";
|
|
9
9
|
import { NestedEditorsContext } from "../core/NestedLexicalEditor.js";
|
|
10
|
-
import {
|
|
10
|
+
import { directiveDescriptors$ } from "./index.js";
|
|
11
11
|
import { voidEmitter } from "../../utils/voidEmitter.js";
|
|
12
|
+
import { useCellValues } from "@mdxeditor/gurx";
|
|
12
13
|
let GENERATION = 0;
|
|
13
14
|
class DirectiveNode extends DecoratorNode {
|
|
15
|
+
/**
|
|
16
|
+
* Constructs a new {@link DirectiveNode} with the specified MDAST directive node as the object to edit.
|
|
17
|
+
*/
|
|
14
18
|
constructor(mdastNode, key) {
|
|
15
19
|
super(key);
|
|
20
|
+
/** @internal */
|
|
16
21
|
__publicField(this, "__mdastNode");
|
|
22
|
+
/** @internal */
|
|
17
23
|
__publicField(this, "__focusEmitter", voidEmitter());
|
|
24
|
+
/**
|
|
25
|
+
* Focuses the direcitive editor.
|
|
26
|
+
*/
|
|
18
27
|
__publicField(this, "select", () => {
|
|
19
28
|
this.__focusEmitter.publish();
|
|
20
29
|
});
|
|
21
30
|
this.__mdastNode = mdastNode;
|
|
22
31
|
this.generation = GENERATION++;
|
|
23
32
|
}
|
|
33
|
+
/** @internal */
|
|
24
34
|
static getType() {
|
|
25
35
|
return "directive";
|
|
26
36
|
}
|
|
37
|
+
/** @internal */
|
|
27
38
|
static clone(node) {
|
|
28
39
|
return new DirectiveNode(structuredClone(node.__mdastNode), node.__key);
|
|
29
40
|
}
|
|
41
|
+
/** @internal */
|
|
30
42
|
static importJSON(serializedNode) {
|
|
31
43
|
return $createDirectiveNode(serializedNode.mdastNode);
|
|
32
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns the MDAST node that is being edited.
|
|
47
|
+
*/
|
|
33
48
|
getMdastNode() {
|
|
34
49
|
return this.__mdastNode;
|
|
35
50
|
}
|
|
51
|
+
/** @internal */
|
|
36
52
|
exportJSON() {
|
|
37
53
|
return {
|
|
38
54
|
mdastNode: structuredClone(this.__mdastNode),
|
|
@@ -40,15 +56,21 @@ class DirectiveNode extends DecoratorNode {
|
|
|
40
56
|
version: 1
|
|
41
57
|
};
|
|
42
58
|
}
|
|
59
|
+
/** @internal */
|
|
43
60
|
createDOM() {
|
|
44
61
|
return document.createElement(this.__mdastNode.type === "textDirective" ? "span" : "div");
|
|
45
62
|
}
|
|
63
|
+
/** @internal */
|
|
46
64
|
updateDOM() {
|
|
47
65
|
return false;
|
|
48
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Sets a new MDAST node to edit.
|
|
69
|
+
*/
|
|
49
70
|
setMdastNode(mdastNode) {
|
|
50
71
|
this.getWritable().__mdastNode = mdastNode;
|
|
51
72
|
}
|
|
73
|
+
/** @internal */
|
|
52
74
|
decorate(parentEditor, config) {
|
|
53
75
|
return /* @__PURE__ */ React__default.createElement(
|
|
54
76
|
DirectiveEditorContainer,
|
|
@@ -61,23 +83,25 @@ class DirectiveNode extends DecoratorNode {
|
|
|
61
83
|
}
|
|
62
84
|
);
|
|
63
85
|
}
|
|
86
|
+
/** @internal */
|
|
64
87
|
isInline() {
|
|
65
88
|
return this.__mdastNode.type === "textDirective";
|
|
66
89
|
}
|
|
90
|
+
/** @internal */
|
|
67
91
|
isKeyboardSelectable() {
|
|
68
92
|
return true;
|
|
69
93
|
}
|
|
70
94
|
}
|
|
71
|
-
|
|
95
|
+
const DirectiveEditorContainer = (props) => {
|
|
72
96
|
const { mdastNode } = props;
|
|
73
|
-
const [directiveDescriptors] =
|
|
97
|
+
const [directiveDescriptors] = useCellValues(directiveDescriptors$);
|
|
74
98
|
const descriptor = directiveDescriptors.find((descriptor2) => descriptor2.testNode(mdastNode));
|
|
75
99
|
if (!descriptor) {
|
|
76
100
|
throw new Error(`No descriptor found for directive ${mdastNode.name}`);
|
|
77
101
|
}
|
|
78
102
|
const Editor = descriptor.Editor;
|
|
79
103
|
return /* @__PURE__ */ React__default.createElement(NestedEditorsContext.Provider, { value: props }, /* @__PURE__ */ React__default.createElement(Editor, { descriptor, mdastNode, lexicalNode: props.lexicalNode, parentEditor: props.parentEditor }));
|
|
80
|
-
}
|
|
104
|
+
};
|
|
81
105
|
function $createDirectiveNode(mdastNode, key) {
|
|
82
106
|
return new DirectiveNode(mdastNode, key);
|
|
83
107
|
}
|
|
@@ -87,6 +111,5 @@ function $isDirectiveNode(node) {
|
|
|
87
111
|
export {
|
|
88
112
|
$createDirectiveNode,
|
|
89
113
|
$isDirectiveNode,
|
|
90
|
-
DirectiveEditorContainer,
|
|
91
114
|
DirectiveNode
|
|
92
115
|
};
|
|
@@ -1,53 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { realmPlugin } from "../../RealmWithPlugins.js";
|
|
2
|
+
import { insertDecoratorNode$, addMdastExtension$, addSyntaxExtension$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addToMarkdownExtension$ } from "../core/index.js";
|
|
3
|
+
import { Cell, Signal, map } from "@mdxeditor/gurx";
|
|
3
4
|
import { directiveFromMarkdown, directiveToMarkdown } from "mdast-util-directive";
|
|
5
|
+
import { directive } from "micromark-extension-directive";
|
|
4
6
|
import { $createDirectiveNode, DirectiveNode } from "./DirectiveNode.js";
|
|
7
|
+
import { $isDirectiveNode } from "./DirectiveNode.js";
|
|
5
8
|
import { DirectiveVisitor } from "./DirectiveVisitor.js";
|
|
6
9
|
import { MdastDirectiveVisitor } from "./MdastDirectiveVisitor.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
);
|
|
22
|
-
return {
|
|
23
|
-
directiveDescriptors,
|
|
24
|
-
insertDirective
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
[coreSystem]
|
|
28
|
-
);
|
|
29
|
-
const [
|
|
30
|
-
/** @internal */
|
|
31
|
-
directivesPlugin,
|
|
32
|
-
/** @internal */
|
|
33
|
-
directivesPluginHooks
|
|
34
|
-
] = realmPlugin({
|
|
35
|
-
id: "directives",
|
|
36
|
-
systemSpec: directivesSystem,
|
|
37
|
-
applyParamsToSystem: (realm, params) => {
|
|
38
|
-
realm.pubKey("directiveDescriptors", (params == null ? void 0 : params.directiveDescriptors) || []);
|
|
10
|
+
const directiveDescriptors$ = Cell([]);
|
|
11
|
+
const insertDirective$ = Signal((r) => {
|
|
12
|
+
r.link(
|
|
13
|
+
r.pipe(
|
|
14
|
+
insertDirective$,
|
|
15
|
+
map((payload) => {
|
|
16
|
+
return () => $createDirectiveNode({ children: [], ...payload });
|
|
17
|
+
})
|
|
18
|
+
),
|
|
19
|
+
insertDecoratorNode$
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
const directivesPlugin = realmPlugin({
|
|
23
|
+
update: (realm, params) => {
|
|
24
|
+
realm.pub(directiveDescriptors$, (params == null ? void 0 : params.directiveDescriptors) || []);
|
|
39
25
|
},
|
|
40
|
-
init: (realm
|
|
41
|
-
realm.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
26
|
+
init: (realm) => {
|
|
27
|
+
realm.pubIn({
|
|
28
|
+
// import
|
|
29
|
+
[addMdastExtension$]: directiveFromMarkdown(),
|
|
30
|
+
[addSyntaxExtension$]: directive(),
|
|
31
|
+
[addImportVisitor$]: MdastDirectiveVisitor,
|
|
32
|
+
// export
|
|
33
|
+
[addLexicalNode$]: DirectiveNode,
|
|
34
|
+
[addExportVisitor$]: DirectiveVisitor,
|
|
35
|
+
[addToMarkdownExtension$]: directiveToMarkdown()
|
|
36
|
+
});
|
|
47
37
|
}
|
|
48
38
|
});
|
|
49
39
|
export {
|
|
40
|
+
$createDirectiveNode,
|
|
41
|
+
$isDirectiveNode,
|
|
42
|
+
DirectiveNode,
|
|
43
|
+
directiveDescriptors$,
|
|
50
44
|
directivesPlugin,
|
|
51
|
-
|
|
52
|
-
directivesSystem
|
|
45
|
+
insertDirective$
|
|
53
46
|
};
|
|
@@ -3,18 +3,19 @@ import classNames from "classnames";
|
|
|
3
3
|
import YamlParser from "js-yaml";
|
|
4
4
|
import React__default from "react";
|
|
5
5
|
import { useForm, useFieldArray } from "react-hook-form";
|
|
6
|
-
import {
|
|
6
|
+
import { frontmatterDialogOpen$, removeFrontmatter$ } from "./index.js";
|
|
7
7
|
import styles from "../../styles/ui.module.css.js";
|
|
8
|
-
import {
|
|
8
|
+
import { readOnly$, editorRootElementRef$, iconComponentFor$ } from "../core/index.js";
|
|
9
|
+
import { useCellValues, usePublisher } from "@mdxeditor/gurx";
|
|
9
10
|
const FrontmatterEditor = ({ yaml, onChange }) => {
|
|
10
|
-
const [readOnly, editorRootElementRef, iconComponentFor] =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const [readOnly, editorRootElementRef, iconComponentFor, frontmatterDialogOpen] = useCellValues(
|
|
12
|
+
readOnly$,
|
|
13
|
+
editorRootElementRef$,
|
|
14
|
+
iconComponentFor$,
|
|
15
|
+
frontmatterDialogOpen$
|
|
14
16
|
);
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const removeFrontmatter = frontmatterPluginHooks.usePublisher("removeFrontmatter");
|
|
17
|
+
const setFrontmatterDialogOpen = usePublisher(frontmatterDialogOpen$);
|
|
18
|
+
const removeFrontmatter = usePublisher(removeFrontmatter$);
|
|
18
19
|
const yamlConfig = React__default.useMemo(() => {
|
|
19
20
|
if (!yaml) {
|
|
20
21
|
return [];
|
|
@@ -33,16 +34,19 @@ const FrontmatterEditor = ({ yaml, onChange }) => {
|
|
|
33
34
|
const onSubmit = React__default.useCallback(
|
|
34
35
|
({ yamlConfig: yamlConfig2 }) => {
|
|
35
36
|
if (yamlConfig2.length === 0) {
|
|
36
|
-
removeFrontmatter(
|
|
37
|
+
removeFrontmatter();
|
|
37
38
|
setFrontmatterDialogOpen(false);
|
|
38
39
|
return;
|
|
39
40
|
}
|
|
40
|
-
const yaml2 = yamlConfig2.reduce(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
const yaml2 = yamlConfig2.reduce(
|
|
42
|
+
(acc, { key, value }) => {
|
|
43
|
+
if (key && value) {
|
|
44
|
+
acc[key] = value;
|
|
45
|
+
}
|
|
46
|
+
return acc;
|
|
47
|
+
},
|
|
48
|
+
{}
|
|
49
|
+
);
|
|
46
50
|
onChange(YamlParser.dump(yaml2).trim());
|
|
47
51
|
setFrontmatterDialogOpen(false);
|
|
48
52
|
},
|
|
@@ -1,76 +1,65 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { realmPlugin } from "../../RealmWithPlugins.js";
|
|
2
|
+
import { rootEditor$, createRootEditorSubscription$, addMdastExtension$, addSyntaxExtension$, addLexicalNode$, addImportVisitor$, addExportVisitor$, addToMarkdownExtension$ } from "../core/index.js";
|
|
3
|
+
import { Cell, Action, withLatestFrom } from "@mdxeditor/gurx";
|
|
4
|
+
import { $getRoot } from "lexical";
|
|
2
5
|
import { frontmatterFromMarkdown, frontmatterToMarkdown } from "mdast-util-frontmatter";
|
|
3
6
|
import { frontmatter } from "micromark-extension-frontmatter";
|
|
4
|
-
import { MdastFrontmatterVisitor } from "./MdastFrontmatterVisitor.js";
|
|
5
|
-
import { LexicalFrontmatterVisitor } from "./LexicalFrontmatterVisitor.js";
|
|
6
|
-
import { $getRoot } from "lexical";
|
|
7
7
|
import { $isFrontmatterNode, $createFrontmatterNode, FrontmatterNode } from "./FrontmatterNode.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (firstItem) {
|
|
22
|
-
firstItem.insertBefore(fmNode);
|
|
23
|
-
} else {
|
|
24
|
-
$getRoot().append(fmNode);
|
|
25
|
-
}
|
|
8
|
+
import { LexicalFrontmatterVisitor } from "./LexicalFrontmatterVisitor.js";
|
|
9
|
+
import { MdastFrontmatterVisitor } from "./MdastFrontmatterVisitor.js";
|
|
10
|
+
const frontmatterDialogOpen$ = Cell(false);
|
|
11
|
+
const insertFrontmatter$ = Action((r) => {
|
|
12
|
+
r.sub(r.pipe(insertFrontmatter$, withLatestFrom(rootEditor$)), ([, rootEditor]) => {
|
|
13
|
+
rootEditor == null ? void 0 : rootEditor.update(() => {
|
|
14
|
+
const firstItem = $getRoot().getFirstChild();
|
|
15
|
+
if (!$isFrontmatterNode(firstItem)) {
|
|
16
|
+
const fmNode = $createFrontmatterNode('"": ""');
|
|
17
|
+
if (firstItem) {
|
|
18
|
+
firstItem.insertBefore(fmNode);
|
|
19
|
+
} else {
|
|
20
|
+
$getRoot().append(fmNode);
|
|
26
21
|
}
|
|
27
|
-
}
|
|
28
|
-
r.pub(frontmatterDialogOpen, true);
|
|
22
|
+
}
|
|
29
23
|
});
|
|
30
|
-
r.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
r.pub(frontmatterDialogOpen$, true);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
const removeFrontmatter$ = Action((r) => {
|
|
28
|
+
r.sub(r.pipe(removeFrontmatter$, withLatestFrom(rootEditor$)), ([, rootEditor]) => {
|
|
29
|
+
rootEditor == null ? void 0 : rootEditor.update(() => {
|
|
30
|
+
const firstItem = $getRoot().getFirstChild();
|
|
31
|
+
if ($isFrontmatterNode(firstItem)) {
|
|
32
|
+
firstItem.remove();
|
|
33
|
+
}
|
|
38
34
|
});
|
|
39
|
-
r.pub(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
r.pub(frontmatterDialogOpen$, false);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
const hasFrontmatter$ = Cell(false, (r) => {
|
|
39
|
+
r.pub(createRootEditorSubscription$, (rootEditor) => {
|
|
40
|
+
return rootEditor.registerUpdateListener(({ editorState }) => {
|
|
41
|
+
editorState.read(() => {
|
|
42
|
+
r.pub(hasFrontmatter$, $isFrontmatterNode($getRoot().getFirstChild()));
|
|
44
43
|
});
|
|
45
44
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
hasFrontmatter,
|
|
50
|
-
frontmatterDialogOpen
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
[coreSystem]
|
|
54
|
-
);
|
|
55
|
-
const [
|
|
56
|
-
/** @internal */
|
|
57
|
-
frontmatterPlugin,
|
|
58
|
-
/** @internal */
|
|
59
|
-
frontmatterPluginHooks
|
|
60
|
-
] = realmPlugin({
|
|
61
|
-
id: "frontmatter",
|
|
62
|
-
systemSpec: frontmatterSystem,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
const frontmatterPlugin = realmPlugin({
|
|
63
48
|
init: (realm) => {
|
|
64
|
-
realm.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
49
|
+
realm.pubIn({
|
|
50
|
+
[addMdastExtension$]: frontmatterFromMarkdown("yaml"),
|
|
51
|
+
[addSyntaxExtension$]: frontmatter(),
|
|
52
|
+
[addLexicalNode$]: FrontmatterNode,
|
|
53
|
+
[addImportVisitor$]: MdastFrontmatterVisitor,
|
|
54
|
+
[addExportVisitor$]: LexicalFrontmatterVisitor,
|
|
55
|
+
[addToMarkdownExtension$]: frontmatterToMarkdown("yaml")
|
|
56
|
+
});
|
|
70
57
|
}
|
|
71
58
|
});
|
|
72
59
|
export {
|
|
60
|
+
frontmatterDialogOpen$,
|
|
73
61
|
frontmatterPlugin,
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
hasFrontmatter$,
|
|
63
|
+
insertFrontmatter$,
|
|
64
|
+
removeFrontmatter$
|
|
76
65
|
};
|