@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,33 +1,28 @@
|
|
|
1
1
|
import React__default from "react";
|
|
2
|
-
import { coreSystem } from "../core/index.js";
|
|
3
2
|
import { MdastLinkVisitor } from "./MdastLinkVisitor.js";
|
|
4
3
|
import { LexicalLinkVisitor } from "./LexicalLinkVisitor.js";
|
|
5
4
|
import { LinkNode, AutoLinkNode } from "@lexical/link";
|
|
6
5
|
import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin.js";
|
|
7
6
|
import { LexicalAutoLinkPlugin } from "./AutoLinkPlugin.js";
|
|
8
|
-
import {
|
|
9
|
-
import { realmPlugin } from "../../
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
[coreSystem]
|
|
16
|
-
);
|
|
17
|
-
const [linkPlugin] = realmPlugin({
|
|
18
|
-
id: "link",
|
|
19
|
-
systemSpec: linkSystem,
|
|
20
|
-
init: (realm, params) => {
|
|
7
|
+
import { Cell } from "@mdxeditor/gurx";
|
|
8
|
+
import { realmPlugin } from "../../RealmWithPlugins.js";
|
|
9
|
+
import { addActivePlugin$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addComposerChild$ } from "../core/index.js";
|
|
10
|
+
const disableAutoLink$ = Cell(false);
|
|
11
|
+
const linkPlugin = realmPlugin({
|
|
12
|
+
init(realm, params) {
|
|
21
13
|
const disableAutoLink = Boolean(params == null ? void 0 : params.disableAutoLink);
|
|
22
|
-
realm.pubKey("addImportVisitor", MdastLinkVisitor);
|
|
23
|
-
realm.pubKey("addLexicalNode", LinkNode);
|
|
24
|
-
realm.pubKey("addLexicalNode", AutoLinkNode);
|
|
25
|
-
realm.pubKey("addExportVisitor", LexicalLinkVisitor);
|
|
26
|
-
realm.pubKey("disableAutoLink", disableAutoLink);
|
|
27
14
|
const linkPluginProps = (params == null ? void 0 : params.validateUrl) ? { validateUrl: params.validateUrl } : {};
|
|
28
|
-
realm.
|
|
15
|
+
realm.pubIn({
|
|
16
|
+
[addActivePlugin$]: "link",
|
|
17
|
+
[addImportVisitor$]: MdastLinkVisitor,
|
|
18
|
+
[addLexicalNode$]: [LinkNode, AutoLinkNode],
|
|
19
|
+
[addExportVisitor$]: LexicalLinkVisitor,
|
|
20
|
+
[disableAutoLink$]: disableAutoLink,
|
|
21
|
+
[addComposerChild$]: () => /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(LinkPlugin, { ...linkPluginProps }), disableAutoLink ? null : /* @__PURE__ */ React__default.createElement(LexicalAutoLinkPlugin, null))
|
|
22
|
+
});
|
|
29
23
|
}
|
|
30
24
|
});
|
|
31
25
|
export {
|
|
26
|
+
disableAutoLink$,
|
|
32
27
|
linkPlugin
|
|
33
28
|
};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import * as RadixPopover from "@radix-ui/react-popover";
|
|
2
2
|
import * as Tooltip from "@radix-ui/react-tooltip";
|
|
3
3
|
import React__default from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { editorRootElementRef$, activeEditor$, iconComponentFor$ } from "../core/index.js";
|
|
5
5
|
import { DownshiftAutoComplete } from "../core/ui/DownshiftAutoComplete.js";
|
|
6
6
|
import styles from "../../styles/ui.module.css.js";
|
|
7
7
|
import classNames from "classnames";
|
|
8
8
|
import { createCommand } from "lexical";
|
|
9
9
|
import { useForm } from "react-hook-form";
|
|
10
|
-
import {
|
|
10
|
+
import { linkDialogState$, linkAutocompleteSuggestions$, onWindowChange$, updateLink$, cancelLinkEdit$, switchFromPreviewToLinkEdit$, removeLink$ } from "./index.js";
|
|
11
|
+
import { useCellValues, usePublisher } from "@mdxeditor/gurx";
|
|
11
12
|
createCommand();
|
|
12
13
|
function LinkEditForm({ url, title, onSubmit, onCancel, linkAutocompleteSuggestions }) {
|
|
13
14
|
const {
|
|
@@ -54,18 +55,18 @@ function LinkEditForm({ url, title, onSubmit, onCancel, linkAutocompleteSuggesti
|
|
|
54
55
|
);
|
|
55
56
|
}
|
|
56
57
|
const LinkDialog = () => {
|
|
57
|
-
const [editorRootElementRef] =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"linkAutocompleteSuggestions"
|
|
58
|
+
const [editorRootElementRef, activeEditor, iconComponentFor, linkDialogState, linkAutocompleteSuggestions] = useCellValues(
|
|
59
|
+
editorRootElementRef$,
|
|
60
|
+
activeEditor$,
|
|
61
|
+
iconComponentFor$,
|
|
62
|
+
linkDialogState$,
|
|
63
|
+
linkAutocompleteSuggestions$
|
|
64
64
|
);
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
65
|
+
const publishWindowChange = usePublisher(onWindowChange$);
|
|
66
|
+
const updateLink = usePublisher(updateLink$);
|
|
67
|
+
const cancelLinkEdit = usePublisher(cancelLinkEdit$);
|
|
68
|
+
const switchFromPreviewToLinkEdit = usePublisher(switchFromPreviewToLinkEdit$);
|
|
69
|
+
const removeLink = usePublisher(removeLink$);
|
|
69
70
|
React__default.useEffect(() => {
|
|
70
71
|
const update = () => {
|
|
71
72
|
activeEditor == null ? void 0 : activeEditor.getEditorState().read(() => {
|
|
@@ -108,7 +109,7 @@ const LinkDialog = () => {
|
|
|
108
109
|
url: linkDialogState.url,
|
|
109
110
|
title: linkDialogState.title,
|
|
110
111
|
onSubmit: updateLink,
|
|
111
|
-
onCancel: cancelLinkEdit.bind(null
|
|
112
|
+
onCancel: cancelLinkEdit.bind(null),
|
|
112
113
|
linkAutocompleteSuggestions
|
|
113
114
|
}
|
|
114
115
|
),
|
|
@@ -122,7 +123,7 @@ const LinkDialog = () => {
|
|
|
122
123
|
},
|
|
123
124
|
/* @__PURE__ */ React__default.createElement("span", null, linkDialogState.url),
|
|
124
125
|
urlIsExternal && iconComponentFor("open_in_new")
|
|
125
|
-
), /* @__PURE__ */ React__default.createElement(ActionButton, { onClick: () => switchFromPreviewToLinkEdit(
|
|
126
|
+
), /* @__PURE__ */ React__default.createElement(ActionButton, { onClick: () => switchFromPreviewToLinkEdit(), title: "Edit link URL", "aria-label": "Edit link URL" }, iconComponentFor("edit")), /* @__PURE__ */ React__default.createElement(Tooltip.Provider, null, /* @__PURE__ */ React__default.createElement(Tooltip.Root, { open: copyUrlTooltipOpen }, /* @__PURE__ */ React__default.createElement(Tooltip.Trigger, { asChild: true }, /* @__PURE__ */ React__default.createElement(
|
|
126
127
|
ActionButton,
|
|
127
128
|
{
|
|
128
129
|
title: "Copy to clipboard",
|
|
@@ -135,7 +136,7 @@ const LinkDialog = () => {
|
|
|
135
136
|
}
|
|
136
137
|
},
|
|
137
138
|
copyUrlTooltipOpen ? iconComponentFor("check") : iconComponentFor("content_copy")
|
|
138
|
-
)), /* @__PURE__ */ React__default.createElement(Tooltip.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Tooltip.Content, { className: classNames(styles.tooltipContent), sideOffset: 5 }, "Copied!", /* @__PURE__ */ React__default.createElement(Tooltip.Arrow, null))))), /* @__PURE__ */ React__default.createElement(ActionButton, { title: "Remove link", "aria-label": "Remove link", onClick: () => removeLink(
|
|
139
|
+
)), /* @__PURE__ */ React__default.createElement(Tooltip.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Tooltip.Content, { className: classNames(styles.tooltipContent), sideOffset: 5 }, "Copied!", /* @__PURE__ */ React__default.createElement(Tooltip.Arrow, null))))), /* @__PURE__ */ React__default.createElement(ActionButton, { title: "Remove link", "aria-label": "Remove link", onClick: () => removeLink() }, iconComponentFor("link_off"))),
|
|
139
140
|
/* @__PURE__ */ React__default.createElement(RadixPopover.Arrow, { className: styles.popoverArrow })
|
|
140
141
|
)));
|
|
141
142
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { TOGGLE_LINK_COMMAND, $isLinkNode } from "@lexical/link";
|
|
2
|
-
import {
|
|
2
|
+
import { KEY_ESCAPE_COMMAND, COMMAND_PRIORITY_LOW, KEY_MODIFIER_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_HIGH, $createTextNode, $insertNodes } from "lexical";
|
|
3
3
|
import { IS_APPLE } from "../../utils/detectMac.js";
|
|
4
4
|
import { getSelectionRectangle, getSelectedNode } from "../../utils/lexicalHelpers.js";
|
|
5
|
-
import {
|
|
5
|
+
import { createActiveEditorSubscription$, activeEditor$, currentSelection$, addComposerChild$ } from "../core/index.js";
|
|
6
6
|
import { LinkDialog } from "./LinkDialog.js";
|
|
7
|
-
import {
|
|
8
|
-
import { realmPlugin } from "../../
|
|
7
|
+
import { Signal, Cell, withLatestFrom, map, Action, filter } from "@mdxeditor/gurx";
|
|
8
|
+
import { realmPlugin } from "../../RealmWithPlugins.js";
|
|
9
9
|
function getLinkNodeInSelection(selection) {
|
|
10
10
|
if (!selection) {
|
|
11
11
|
return null;
|
|
@@ -22,236 +22,214 @@ function getLinkNodeInSelection(selection) {
|
|
|
22
22
|
}
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
openLinkEditDialog,
|
|
40
|
-
r.o.withLatestFrom(currentSelection, activeEditor),
|
|
41
|
-
r.o.filter(([, selection]) => $isRangeSelection(selection))
|
|
42
|
-
),
|
|
43
|
-
([, selection, editor]) => {
|
|
44
|
-
editor == null ? void 0 : editor.focus(() => {
|
|
45
|
-
editor == null ? void 0 : editor.getEditorState().read(() => {
|
|
46
|
-
const node = getLinkNodeInSelection(selection);
|
|
47
|
-
const rectangle = getSelectionRectangle(editor);
|
|
48
|
-
if (node) {
|
|
49
|
-
r.pub(linkDialogState, {
|
|
50
|
-
type: "edit",
|
|
51
|
-
initialUrl: node.getURL(),
|
|
52
|
-
initialTitle: node.getTitle() || "",
|
|
53
|
-
url: node.getURL(),
|
|
54
|
-
title: node.getTitle() || "",
|
|
55
|
-
linkNodeKey: node.getKey(),
|
|
56
|
-
rectangle
|
|
57
|
-
});
|
|
58
|
-
} else {
|
|
59
|
-
r.pub(linkDialogState, {
|
|
60
|
-
type: "edit",
|
|
61
|
-
initialUrl: "",
|
|
62
|
-
initialTitle: "",
|
|
63
|
-
title: "",
|
|
64
|
-
url: "",
|
|
65
|
-
linkNodeKey: "",
|
|
66
|
-
rectangle
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
}
|
|
25
|
+
const onWindowChange$ = Signal();
|
|
26
|
+
const linkDialogState$ = Cell({ type: "inactive" }, (r) => {
|
|
27
|
+
r.pub(createActiveEditorSubscription$, (editor) => {
|
|
28
|
+
return editor.registerCommand(
|
|
29
|
+
KEY_ESCAPE_COMMAND,
|
|
30
|
+
() => {
|
|
31
|
+
const state = r.getValue(linkDialogState$);
|
|
32
|
+
if (state.type === "preview") {
|
|
33
|
+
r.pub(linkDialogState$, { type: "inactive" });
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
},
|
|
38
|
+
COMMAND_PRIORITY_LOW
|
|
72
39
|
);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
40
|
+
});
|
|
41
|
+
r.pub(createActiveEditorSubscription$, (editor) => {
|
|
42
|
+
return editor.registerCommand(
|
|
43
|
+
KEY_MODIFIER_COMMAND,
|
|
44
|
+
(event) => {
|
|
45
|
+
if (event.key === "k" && (IS_APPLE ? event.metaKey : event.ctrlKey)) {
|
|
46
|
+
const selection = $getSelection();
|
|
47
|
+
if ($isRangeSelection(selection)) {
|
|
48
|
+
r.pub(openLinkEditDialog$);
|
|
49
|
+
event.stopPropagation();
|
|
50
|
+
event.preventDefault();
|
|
83
51
|
return true;
|
|
52
|
+
} else {
|
|
53
|
+
return false;
|
|
84
54
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
},
|
|
58
|
+
COMMAND_PRIORITY_HIGH
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
r.link(
|
|
62
|
+
r.pipe(
|
|
63
|
+
switchFromPreviewToLinkEdit$,
|
|
64
|
+
withLatestFrom(linkDialogState$),
|
|
65
|
+
map(([, state]) => {
|
|
66
|
+
if (state.type === "preview") {
|
|
67
|
+
return {
|
|
68
|
+
type: "edit",
|
|
69
|
+
initialUrl: state.url,
|
|
70
|
+
url: state.url,
|
|
71
|
+
title: state.title,
|
|
72
|
+
linkNodeKey: state.linkNodeKey,
|
|
73
|
+
rectangle: state.rectangle
|
|
74
|
+
};
|
|
75
|
+
} else {
|
|
76
|
+
throw new Error("Cannot switch to edit mode when not in preview mode");
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
),
|
|
80
|
+
linkDialogState$
|
|
81
|
+
);
|
|
82
|
+
r.sub(r.pipe(updateLink$, withLatestFrom(activeEditor$, linkDialogState$, currentSelection$)), ([payload, editor, state, selection]) => {
|
|
83
|
+
const url = payload.url.trim();
|
|
84
|
+
const title = payload.title.trim();
|
|
85
|
+
if (url.trim() !== "") {
|
|
86
|
+
if (selection == null ? void 0 : selection.isCollapsed()) {
|
|
87
|
+
const linkContent = title || url;
|
|
88
|
+
editor == null ? void 0 : editor.update(
|
|
89
|
+
() => {
|
|
90
|
+
if (!getLinkNodeInSelection(selection)) {
|
|
91
|
+
const node = $createTextNode(linkContent);
|
|
92
|
+
$insertNodes([node]);
|
|
93
|
+
node.select();
|
|
103
94
|
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
95
|
+
},
|
|
96
|
+
{ discrete: true }
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, { url, title });
|
|
100
|
+
r.pub(linkDialogState$, {
|
|
101
|
+
type: "preview",
|
|
102
|
+
linkNodeKey: state.linkNodeKey,
|
|
103
|
+
rectangle: state.rectangle,
|
|
104
|
+
title,
|
|
105
|
+
url
|
|
106
|
+
});
|
|
107
|
+
} else {
|
|
108
|
+
if (state.type === "edit" && state.initialUrl !== "") {
|
|
109
|
+
editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
110
|
+
}
|
|
111
|
+
r.pub(linkDialogState$, {
|
|
112
|
+
type: "inactive"
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
r.link(
|
|
117
|
+
r.pipe(
|
|
118
|
+
cancelLinkEdit$,
|
|
119
|
+
withLatestFrom(linkDialogState$, activeEditor$),
|
|
120
|
+
map(([, state, editor]) => {
|
|
121
|
+
if (state.type === "edit") {
|
|
122
|
+
editor == null ? void 0 : editor.focus();
|
|
123
|
+
if (state.initialUrl === "") {
|
|
116
124
|
return {
|
|
117
|
-
type: "
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
125
|
+
type: "inactive"
|
|
126
|
+
};
|
|
127
|
+
} else {
|
|
128
|
+
return {
|
|
129
|
+
type: "preview",
|
|
130
|
+
url: state.initialUrl,
|
|
121
131
|
linkNodeKey: state.linkNodeKey,
|
|
122
132
|
rectangle: state.rectangle
|
|
123
133
|
};
|
|
124
|
-
} else {
|
|
125
|
-
throw new Error("Cannot switch to edit mode when not in preview mode");
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
),
|
|
129
|
-
linkDialogState
|
|
130
|
-
);
|
|
131
|
-
r.sub(
|
|
132
|
-
r.pipe(updateLink, r.o.withLatestFrom(activeEditor, linkDialogState, currentSelection)),
|
|
133
|
-
([payload, editor, state, selection]) => {
|
|
134
|
-
const url = payload.url.trim();
|
|
135
|
-
const title = payload.title.trim();
|
|
136
|
-
if (url.trim() !== "") {
|
|
137
|
-
if (selection == null ? void 0 : selection.isCollapsed()) {
|
|
138
|
-
const linkContent = title || url;
|
|
139
|
-
editor == null ? void 0 : editor.update(
|
|
140
|
-
() => {
|
|
141
|
-
if (!getLinkNodeInSelection(selection)) {
|
|
142
|
-
const node = $createTextNode(linkContent);
|
|
143
|
-
$insertNodes([node]);
|
|
144
|
-
node.select();
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
{ discrete: true }
|
|
148
|
-
);
|
|
149
134
|
}
|
|
150
|
-
editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, { url, title });
|
|
151
|
-
r.pub(linkDialogState, {
|
|
152
|
-
type: "preview",
|
|
153
|
-
linkNodeKey: state.linkNodeKey,
|
|
154
|
-
rectangle: state.rectangle,
|
|
155
|
-
title,
|
|
156
|
-
url
|
|
157
|
-
});
|
|
158
135
|
} else {
|
|
159
|
-
|
|
160
|
-
editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
161
|
-
}
|
|
162
|
-
r.pub(linkDialogState, {
|
|
163
|
-
type: "inactive"
|
|
164
|
-
});
|
|
136
|
+
throw new Error("Cannot cancel edit when not in edit mode");
|
|
165
137
|
}
|
|
166
|
-
}
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
};
|
|
186
|
-
}
|
|
138
|
+
})
|
|
139
|
+
),
|
|
140
|
+
linkDialogState$
|
|
141
|
+
);
|
|
142
|
+
r.link(
|
|
143
|
+
r.pipe(
|
|
144
|
+
r.combine(currentSelection$, onWindowChange$),
|
|
145
|
+
withLatestFrom(activeEditor$, linkDialogState$),
|
|
146
|
+
map(([[selection], activeEditor]) => {
|
|
147
|
+
if ($isRangeSelection(selection) && activeEditor) {
|
|
148
|
+
const node = getLinkNodeInSelection(selection);
|
|
149
|
+
if (node) {
|
|
150
|
+
return {
|
|
151
|
+
type: "preview",
|
|
152
|
+
url: node.getURL(),
|
|
153
|
+
linkNodeKey: node.getKey(),
|
|
154
|
+
title: node.getTitle(),
|
|
155
|
+
rectangle: getSelectionRectangle(activeEditor)
|
|
156
|
+
};
|
|
187
157
|
} else {
|
|
188
|
-
|
|
158
|
+
return { type: "inactive" };
|
|
189
159
|
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
160
|
+
} else {
|
|
161
|
+
return { type: "inactive" };
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
),
|
|
165
|
+
linkDialogState$
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
const updateLink$ = Signal();
|
|
169
|
+
const cancelLinkEdit$ = Action();
|
|
170
|
+
const applyLinkChanges$ = Action();
|
|
171
|
+
const switchFromPreviewToLinkEdit$ = Action();
|
|
172
|
+
const removeLink$ = Action((r) => {
|
|
173
|
+
r.sub(r.pipe(removeLink$, withLatestFrom(activeEditor$)), ([, editor]) => {
|
|
174
|
+
editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
const openLinkEditDialog$ = Action((r) => {
|
|
178
|
+
r.sub(
|
|
179
|
+
r.pipe(
|
|
180
|
+
openLinkEditDialog$,
|
|
181
|
+
withLatestFrom(currentSelection$, activeEditor$),
|
|
182
|
+
filter(([, selection]) => $isRangeSelection(selection))
|
|
183
|
+
),
|
|
184
|
+
([, selection, editor]) => {
|
|
185
|
+
editor == null ? void 0 : editor.focus(() => {
|
|
186
|
+
editor == null ? void 0 : editor.getEditorState().read(() => {
|
|
187
|
+
const node = getLinkNodeInSelection(selection);
|
|
188
|
+
const rectangle = getSelectionRectangle(editor);
|
|
189
|
+
if (node) {
|
|
190
|
+
r.pub(linkDialogState$, {
|
|
191
|
+
type: "edit",
|
|
192
|
+
initialUrl: node.getURL(),
|
|
193
|
+
initialTitle: node.getTitle() || "",
|
|
194
|
+
url: node.getURL(),
|
|
195
|
+
title: node.getTitle() || "",
|
|
196
|
+
linkNodeKey: node.getKey(),
|
|
197
|
+
rectangle
|
|
198
|
+
});
|
|
214
199
|
} else {
|
|
215
|
-
|
|
216
|
-
type: "
|
|
217
|
-
|
|
200
|
+
r.pub(linkDialogState$, {
|
|
201
|
+
type: "edit",
|
|
202
|
+
initialUrl: "",
|
|
203
|
+
initialTitle: "",
|
|
204
|
+
title: "",
|
|
205
|
+
url: "",
|
|
206
|
+
linkNodeKey: "",
|
|
207
|
+
rectangle
|
|
208
|
+
});
|
|
218
209
|
}
|
|
219
|
-
})
|
|
220
|
-
)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
linkDialogState,
|
|
227
|
-
updateLink,
|
|
228
|
-
switchFromPreviewToLinkEdit,
|
|
229
|
-
cancelLinkEdit,
|
|
230
|
-
removeLink,
|
|
231
|
-
openLinkEditDialog,
|
|
232
|
-
applyLinkChanges,
|
|
233
|
-
linkAutocompleteSuggestions
|
|
234
|
-
};
|
|
235
|
-
},
|
|
236
|
-
[coreSystem]
|
|
237
|
-
);
|
|
238
|
-
const [
|
|
239
|
-
/** @internal */
|
|
240
|
-
linkDialogPlugin,
|
|
241
|
-
/** @internal */
|
|
242
|
-
linkDialogPluginHooks
|
|
243
|
-
] = realmPlugin({
|
|
244
|
-
id: "link-dialog",
|
|
245
|
-
dependencies: ["link"],
|
|
246
|
-
systemSpec: linkDialogSystem,
|
|
247
|
-
applyParamsToSystem(r, params = {}) {
|
|
248
|
-
r.pubKey("linkAutocompleteSuggestions", params.linkAutocompleteSuggestions || []);
|
|
249
|
-
},
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
const linkAutocompleteSuggestions$ = Cell([]);
|
|
216
|
+
const linkDialogPlugin = realmPlugin({
|
|
250
217
|
init(r, params) {
|
|
251
|
-
r.
|
|
218
|
+
r.pub(addComposerChild$, (params == null ? void 0 : params.LinkDialog) || LinkDialog);
|
|
219
|
+
},
|
|
220
|
+
update(r, params = {}) {
|
|
221
|
+
r.pub(linkAutocompleteSuggestions$, params.linkAutocompleteSuggestions || []);
|
|
252
222
|
}
|
|
253
223
|
});
|
|
254
224
|
export {
|
|
225
|
+
applyLinkChanges$,
|
|
226
|
+
cancelLinkEdit$,
|
|
227
|
+
linkAutocompleteSuggestions$,
|
|
255
228
|
linkDialogPlugin,
|
|
256
|
-
|
|
229
|
+
linkDialogState$,
|
|
230
|
+
onWindowChange$,
|
|
231
|
+
openLinkEditDialog$,
|
|
232
|
+
removeLink$,
|
|
233
|
+
switchFromPreviewToLinkEdit$,
|
|
234
|
+
updateLink$
|
|
257
235
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { $createListItemNode } from "@lexical/list";
|
|
2
2
|
const MdastListItemVisitor = {
|
|
3
3
|
testNode: "listItem",
|
|
4
|
-
visitNode({ mdastNode, actions }) {
|
|
5
|
-
|
|
4
|
+
visitNode({ mdastNode, actions, lexicalParent }) {
|
|
5
|
+
const isChecked = lexicalParent.getListType() === "check" ? mdastNode.checked ?? false : void 0;
|
|
6
|
+
actions.addAndStepInto($createListItemNode(isChecked));
|
|
6
7
|
}
|
|
7
8
|
};
|
|
8
9
|
export {
|