@mdxeditor/editor 1.14.3 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/MDXEditor.js +19 -25
- package/dist/RealmWithPlugins.js +38 -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 +433 -384
- 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 +12 -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/LexicalListItemVisitor.js +2 -1
- 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 +20 -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 +65 -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,11 +1,11 @@
|
|
|
1
|
-
import { coreSystem } from "../core/index.js";
|
|
2
|
-
import { MdastHeadingVisitor } from "./MdastHeadingVisitor.js";
|
|
3
1
|
import { $createHeadingNode, HeadingNode } from "@lexical/rich-text";
|
|
4
|
-
import {
|
|
2
|
+
import { Cell } from "@mdxeditor/gurx";
|
|
5
3
|
import { KEY_DOWN_COMMAND, $createParagraphNode, COMMAND_PRIORITY_LOW } from "lexical";
|
|
4
|
+
import { realmPlugin } from "../../RealmWithPlugins.js";
|
|
6
5
|
import { controlOrMeta } from "../../utils/detectMac.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { createRootEditorSubscription$, convertSelectionToNode$, addActivePlugin$, addImportVisitor$, addLexicalNode$, addExportVisitor$ } from "../core/index.js";
|
|
7
|
+
import { LexicalHeadingVisitor } from "./LexicalHeadingVisitor.js";
|
|
8
|
+
import { MdastHeadingVisitor } from "./MdastHeadingVisitor.js";
|
|
9
9
|
const FORMATTING_KEYS = [48, 49, 50, 51, 52, 53, 54];
|
|
10
10
|
const ALL_HEADING_LEVELS = [1, 2, 3, 4, 5, 6];
|
|
11
11
|
const CODE_TO_HEADING_LEVEL_MAP = {
|
|
@@ -16,54 +16,48 @@ const CODE_TO_HEADING_LEVEL_MAP = {
|
|
|
16
16
|
53: 5,
|
|
17
17
|
54: 6
|
|
18
18
|
};
|
|
19
|
-
const
|
|
20
|
-
(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (!allowedHeadingLevelsValues.includes(requestedHeadingLevel)) {
|
|
36
|
-
r.pub(convertSelectionToNode, () => $createHeadingNode(`h${requestedHeadingLevel}`));
|
|
37
|
-
}
|
|
19
|
+
const allowedHeadingLevels$ = Cell(ALL_HEADING_LEVELS, (r) => {
|
|
20
|
+
r.pub(createRootEditorSubscription$, (theRootEditor) => {
|
|
21
|
+
return theRootEditor.registerCommand(
|
|
22
|
+
KEY_DOWN_COMMAND,
|
|
23
|
+
(event) => {
|
|
24
|
+
const { keyCode, ctrlKey, metaKey, altKey } = event;
|
|
25
|
+
if (FORMATTING_KEYS.includes(keyCode) && controlOrMeta(metaKey, ctrlKey) && altKey) {
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
theRootEditor.update(() => {
|
|
28
|
+
if (keyCode === 48) {
|
|
29
|
+
r.pub(convertSelectionToNode$, () => $createParagraphNode());
|
|
30
|
+
} else {
|
|
31
|
+
const allowedHeadingLevels = r.getValue(allowedHeadingLevels$);
|
|
32
|
+
const requestedHeadingLevel = CODE_TO_HEADING_LEVEL_MAP[keyCode];
|
|
33
|
+
if (!allowedHeadingLevels.includes(requestedHeadingLevel)) {
|
|
34
|
+
r.pub(convertSelectionToNode$, () => $createHeadingNode(`h${requestedHeadingLevel}`));
|
|
38
35
|
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
},
|
|
42
|
+
COMMAND_PRIORITY_LOW
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
const headingsPlugin = realmPlugin({
|
|
47
|
+
init(realm) {
|
|
48
|
+
realm.pubIn({
|
|
49
|
+
[addActivePlugin$]: "headings",
|
|
50
|
+
[addImportVisitor$]: MdastHeadingVisitor,
|
|
51
|
+
[addLexicalNode$]: HeadingNode,
|
|
52
|
+
[addExportVisitor$]: LexicalHeadingVisitor
|
|
46
53
|
});
|
|
47
|
-
return {
|
|
48
|
-
allowedHeadingLevels
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
[coreSystem]
|
|
52
|
-
);
|
|
53
|
-
const [headingsPlugin, headingsPluginHooks] = realmPlugin({
|
|
54
|
-
id: "headings",
|
|
55
|
-
systemSpec: headingsSystem,
|
|
56
|
-
applyParamsToSystem(realm, params) {
|
|
57
|
-
realm.pubKey("allowedHeadingLevels", (params == null ? void 0 : params.allowedHeadingLevels) ?? ALL_HEADING_LEVELS);
|
|
58
54
|
},
|
|
59
|
-
|
|
60
|
-
realm.
|
|
61
|
-
realm.pubKey("addLexicalNode", HeadingNode);
|
|
62
|
-
realm.pubKey("addExportVisitor", LexicalHeadingVisitor);
|
|
55
|
+
update(realm, params) {
|
|
56
|
+
realm.pub(allowedHeadingLevels$, (params == null ? void 0 : params.allowedHeadingLevels) ?? ALL_HEADING_LEVELS);
|
|
63
57
|
}
|
|
64
58
|
});
|
|
65
59
|
export {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
ALL_HEADING_LEVELS,
|
|
61
|
+
allowedHeadingLevels$,
|
|
62
|
+
headingsPlugin
|
|
69
63
|
};
|
|
@@ -3,14 +3,18 @@ import classNames from "classnames";
|
|
|
3
3
|
import React__default from "react";
|
|
4
4
|
import { useForm } from "react-hook-form";
|
|
5
5
|
import styles from "../../styles/ui.module.css.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { editorRootElementRef$ } from "../core/index.js";
|
|
7
|
+
import { imageAutocompleteSuggestions$, imageDialogState$, saveImage$, closeImageDialog$ } from "./index.js";
|
|
8
8
|
import { DownshiftAutoComplete } from "../core/ui/DownshiftAutoComplete.js";
|
|
9
|
+
import { useCellValues, usePublisher } from "@mdxeditor/gurx";
|
|
9
10
|
const ImageDialog = () => {
|
|
10
|
-
const [imageAutocompleteSuggestions, state] =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const [imageAutocompleteSuggestions, state, editorRootElementRef] = useCellValues(
|
|
12
|
+
imageAutocompleteSuggestions$,
|
|
13
|
+
imageDialogState$,
|
|
14
|
+
editorRootElementRef$
|
|
15
|
+
);
|
|
16
|
+
const saveImage = usePublisher(saveImage$);
|
|
17
|
+
const closeImageDialog = usePublisher(closeImageDialog$);
|
|
14
18
|
const { register, handleSubmit, control, setValue, reset } = useForm({
|
|
15
19
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
16
20
|
values: state.type === "editing" ? state.initialValues : {}
|
|
@@ -21,7 +25,7 @@ const ImageDialog = () => {
|
|
|
21
25
|
open: state.type !== "inactive",
|
|
22
26
|
onOpenChange: (open) => {
|
|
23
27
|
if (!open) {
|
|
24
|
-
closeImageDialog(
|
|
28
|
+
closeImageDialog();
|
|
25
29
|
reset({ src: "", title: "", altText: "" });
|
|
26
30
|
}
|
|
27
31
|
}
|
|
@@ -4,11 +4,12 @@ import { useLexicalNodeSelection } from "@lexical/react/useLexicalNodeSelection.
|
|
|
4
4
|
import { mergeRegister } from "@lexical/utils";
|
|
5
5
|
import classNames from "classnames";
|
|
6
6
|
import { $isNodeSelection, $getSelection, $getNodeByKey, $setSelection, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_LOW, CLICK_COMMAND, DRAGSTART_COMMAND, KEY_DELETE_COMMAND, KEY_BACKSPACE_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND } from "lexical";
|
|
7
|
-
import {
|
|
7
|
+
import { disableImageResize$, imagePreviewHandler$, openEditImageDialog$ } from "./index.js";
|
|
8
8
|
import styles from "../../styles/ui.module.css.js";
|
|
9
|
-
import {
|
|
9
|
+
import { iconComponentFor$, readOnly$ } from "../core/index.js";
|
|
10
10
|
import { $isImageNode } from "./ImageNode.js";
|
|
11
11
|
import ImageResizer from "./ImageResizer.js";
|
|
12
|
+
import { useCellValues, usePublisher } from "@mdxeditor/gurx";
|
|
12
13
|
const imageCache = /* @__PURE__ */ new Set();
|
|
13
14
|
function useSuspenseImage(src) {
|
|
14
15
|
if (!imageCache.has(src)) {
|
|
@@ -47,6 +48,13 @@ function LazyImage({
|
|
|
47
48
|
);
|
|
48
49
|
}
|
|
49
50
|
function ImageEditor({ src, title, alt, nodeKey, width, height }) {
|
|
51
|
+
const [disableImageResize, imagePreviewHandler, iconComponentFor, readOnly] = useCellValues(
|
|
52
|
+
disableImageResize$,
|
|
53
|
+
imagePreviewHandler$,
|
|
54
|
+
iconComponentFor$,
|
|
55
|
+
readOnly$
|
|
56
|
+
);
|
|
57
|
+
const openEditImageDialog = usePublisher(openEditImageDialog$);
|
|
50
58
|
const imageRef = React__default.useRef(null);
|
|
51
59
|
const buttonRef = React__default.useRef(null);
|
|
52
60
|
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
|
|
@@ -54,12 +62,8 @@ function ImageEditor({ src, title, alt, nodeKey, width, height }) {
|
|
|
54
62
|
const [selection, setSelection] = React__default.useState(null);
|
|
55
63
|
const activeEditorRef = React__default.useRef(null);
|
|
56
64
|
const [isResizing, setIsResizing] = React__default.useState(false);
|
|
57
|
-
const [disableImageResize] = imagePluginHooks.useEmitterValues("disableImageResize");
|
|
58
|
-
const [imagePreviewHandler] = imagePluginHooks.useEmitterValues("imagePreviewHandler");
|
|
59
65
|
const [imageSource, setImageSource] = React__default.useState(null);
|
|
60
66
|
const [initialImagePath, setInitialImagePath] = React__default.useState(null);
|
|
61
|
-
const openEditImageDialog = imagePluginHooks.usePublisher("openEditImageDialog");
|
|
62
|
-
const [iconComponentFor] = corePluginHooks.useEmitterValues("iconComponentFor");
|
|
63
67
|
const onDelete = React__default.useCallback(
|
|
64
68
|
(payload) => {
|
|
65
69
|
if (isSelected && $isNodeSelection($getSelection())) {
|
|
@@ -118,7 +122,7 @@ function ImageEditor({ src, title, alt, nodeKey, width, height }) {
|
|
|
118
122
|
} else {
|
|
119
123
|
setImageSource(src);
|
|
120
124
|
}
|
|
121
|
-
}, [src, imagePreviewHandler]);
|
|
125
|
+
}, [src, imagePreviewHandler, initialImagePath]);
|
|
122
126
|
React__default.useEffect(() => {
|
|
123
127
|
let isMounted = true;
|
|
124
128
|
const unregister = mergeRegister(
|
|
@@ -211,6 +215,7 @@ function ImageEditor({ src, title, alt, nodeKey, width, height }) {
|
|
|
211
215
|
type: "button",
|
|
212
216
|
className: classNames(styles.iconButton, styles.editImageButton),
|
|
213
217
|
title: "Edit image",
|
|
218
|
+
disabled: readOnly,
|
|
214
219
|
onClick: () => {
|
|
215
220
|
openEditImageDialog({
|
|
216
221
|
nodeKey,
|
|
@@ -16,12 +16,21 @@ function convertImageElement(domNode) {
|
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
18
|
class ImageNode extends DecoratorNode {
|
|
19
|
+
/**
|
|
20
|
+
* Constructs a new {@link ImageNode} with the specified image parameters.
|
|
21
|
+
* Use {@link $createImageNode} to construct one.
|
|
22
|
+
*/
|
|
19
23
|
constructor(src, altText, title, width, height, key) {
|
|
20
24
|
super(key);
|
|
25
|
+
/** @internal */
|
|
21
26
|
__publicField(this, "__src");
|
|
27
|
+
/** @internal */
|
|
22
28
|
__publicField(this, "__altText");
|
|
29
|
+
/** @internal */
|
|
23
30
|
__publicField(this, "__title");
|
|
31
|
+
/** @internal */
|
|
24
32
|
__publicField(this, "__width");
|
|
33
|
+
/** @internal */
|
|
25
34
|
__publicField(this, "__height");
|
|
26
35
|
this.__src = src;
|
|
27
36
|
this.__title = title;
|
|
@@ -29,12 +38,15 @@ class ImageNode extends DecoratorNode {
|
|
|
29
38
|
this.__width = width || "inherit";
|
|
30
39
|
this.__height = height || "inherit";
|
|
31
40
|
}
|
|
41
|
+
/** @internal */
|
|
32
42
|
static getType() {
|
|
33
43
|
return "image";
|
|
34
44
|
}
|
|
45
|
+
/** @internal */
|
|
35
46
|
static clone(node) {
|
|
36
47
|
return new ImageNode(node.__src, node.__altText, node.__title, node.__width, node.__height, node.__key);
|
|
37
48
|
}
|
|
49
|
+
/** @internal */
|
|
38
50
|
static importJSON(serializedNode) {
|
|
39
51
|
const { altText, title, src, width, height } = serializedNode;
|
|
40
52
|
const node = $createImageNode({
|
|
@@ -46,6 +58,7 @@ class ImageNode extends DecoratorNode {
|
|
|
46
58
|
});
|
|
47
59
|
return node;
|
|
48
60
|
}
|
|
61
|
+
/** @internal */
|
|
49
62
|
exportDOM() {
|
|
50
63
|
const element = document.createElement("img");
|
|
51
64
|
element.setAttribute("src", this.__src);
|
|
@@ -61,6 +74,7 @@ class ImageNode extends DecoratorNode {
|
|
|
61
74
|
}
|
|
62
75
|
return { element };
|
|
63
76
|
}
|
|
77
|
+
/** @internal */
|
|
64
78
|
static importDOM() {
|
|
65
79
|
return {
|
|
66
80
|
img: () => ({
|
|
@@ -69,6 +83,7 @@ class ImageNode extends DecoratorNode {
|
|
|
69
83
|
})
|
|
70
84
|
};
|
|
71
85
|
}
|
|
86
|
+
/** @internal */
|
|
72
87
|
exportJSON() {
|
|
73
88
|
return {
|
|
74
89
|
altText: this.getAltText(),
|
|
@@ -80,11 +95,15 @@ class ImageNode extends DecoratorNode {
|
|
|
80
95
|
version: 1
|
|
81
96
|
};
|
|
82
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Sets the image dimensions
|
|
100
|
+
*/
|
|
83
101
|
setWidthAndHeight(width, height) {
|
|
84
102
|
const writable = this.getWritable();
|
|
85
103
|
writable.__width = width;
|
|
86
104
|
writable.__height = height;
|
|
87
105
|
}
|
|
106
|
+
/** @internal */
|
|
88
107
|
createDOM(config) {
|
|
89
108
|
const span = document.createElement("span");
|
|
90
109
|
const theme = config.theme;
|
|
@@ -94,6 +113,7 @@ class ImageNode extends DecoratorNode {
|
|
|
94
113
|
}
|
|
95
114
|
return span;
|
|
96
115
|
}
|
|
116
|
+
/** @internal */
|
|
97
117
|
updateDOM() {
|
|
98
118
|
return false;
|
|
99
119
|
}
|
|
@@ -112,9 +132,6 @@ class ImageNode extends DecoratorNode {
|
|
|
112
132
|
getWidth() {
|
|
113
133
|
return this.__width;
|
|
114
134
|
}
|
|
115
|
-
hasExplicitDimensions() {
|
|
116
|
-
return this.__width !== "inherit" || this.__height !== "inherit";
|
|
117
|
-
}
|
|
118
135
|
setTitle(title) {
|
|
119
136
|
this.getWritable().__title = title;
|
|
120
137
|
}
|
|
@@ -124,6 +141,11 @@ class ImageNode extends DecoratorNode {
|
|
|
124
141
|
setAltText(altText) {
|
|
125
142
|
this.getWritable().__altText = altText ?? "";
|
|
126
143
|
}
|
|
144
|
+
/** @internal */
|
|
145
|
+
hasExplicitDimensions() {
|
|
146
|
+
return this.__width !== "inherit" || this.__height !== "inherit";
|
|
147
|
+
}
|
|
148
|
+
/** @internal */
|
|
127
149
|
decorate(_parentEditor) {
|
|
128
150
|
return /* @__PURE__ */ React__default.createElement(
|
|
129
151
|
ImageEditor,
|
|
@@ -138,8 +160,8 @@ class ImageNode extends DecoratorNode {
|
|
|
138
160
|
);
|
|
139
161
|
}
|
|
140
162
|
}
|
|
141
|
-
function $createImageNode(
|
|
142
|
-
const { altText, title, src, key, width, height } =
|
|
163
|
+
function $createImageNode(params) {
|
|
164
|
+
const { altText, title, src, key, width, height } = params;
|
|
143
165
|
return new ImageNode(src, altText, title, width, height, key);
|
|
144
166
|
}
|
|
145
167
|
function $isImageNode(node) {
|
|
@@ -1,37 +1,24 @@
|
|
|
1
|
+
import { realmPlugin } from "../../RealmWithPlugins.js";
|
|
1
2
|
import { $wrapNodeInElement } from "@lexical/utils";
|
|
3
|
+
import { Signal, Cell, withLatestFrom, Action, mapTo, map } from "@mdxeditor/gurx";
|
|
2
4
|
import { $getNodeByKey, $insertNodes, $isRootOrShadowRoot, $createParagraphNode, COMMAND_PRIORITY_EDITOR, DRAGSTART_COMMAND, COMMAND_PRIORITY_HIGH, DRAGOVER_COMMAND, COMMAND_PRIORITY_LOW, DROP_COMMAND, PASTE_COMMAND, COMMAND_PRIORITY_CRITICAL, createCommand, $createRangeSelection, $setSelection, $getSelection, $isNodeSelection } from "lexical";
|
|
3
|
-
import { coreSystem } from "../core/index.js";
|
|
4
|
-
import { $createImageNode, $isImageNode, ImageNode } from "./ImageNode.js";
|
|
5
|
-
import { LexicalImageVisitor } from "./LexicalImageVisitor.js";
|
|
6
|
-
import { MdastImageVisitor, MdastHtmlImageVisitor, MdastJsxImageVisitor } from "./MdastImageVisitor.js";
|
|
7
5
|
import { CAN_USE_DOM } from "../../utils/detectMac.js";
|
|
6
|
+
import { rootEditor$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addComposerChild$ } from "../core/index.js";
|
|
8
7
|
import { ImageDialog } from "./ImageDialog.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const openEditImageDialog = r.node();
|
|
21
|
-
const closeImageDialog = r.node();
|
|
22
|
-
const saveImage = r.node();
|
|
23
|
-
r.link(r.pipe(closeImageDialog, r.o.mapTo({ type: "inactive" })), imageDialogState);
|
|
24
|
-
r.link(r.pipe(openNewImageDialog, r.o.mapTo({ type: "new" })), imageDialogState);
|
|
25
|
-
r.link(
|
|
26
|
-
r.pipe(
|
|
27
|
-
openEditImageDialog,
|
|
28
|
-
r.o.map((payload) => ({ type: "editing", ...payload }))
|
|
29
|
-
),
|
|
30
|
-
imageDialogState
|
|
31
|
-
);
|
|
8
|
+
import { $createImageNode, ImageNode, $isImageNode } from "./ImageNode.js";
|
|
9
|
+
import { LexicalImageVisitor } from "./LexicalImageVisitor.js";
|
|
10
|
+
import { MdastImageVisitor, MdastHtmlImageVisitor, MdastJsxImageVisitor } from "./MdastImageVisitor.js";
|
|
11
|
+
const insertImage$ = Signal();
|
|
12
|
+
const imageAutocompleteSuggestions$ = Cell([]);
|
|
13
|
+
const disableImageResize$ = Cell(false);
|
|
14
|
+
const imageUploadHandler$ = Cell(null);
|
|
15
|
+
const imagePreviewHandler$ = Cell(null);
|
|
16
|
+
const imageDialogState$ = Cell(
|
|
17
|
+
{ type: "inactive" },
|
|
18
|
+
(r) => {
|
|
32
19
|
r.sub(
|
|
33
|
-
r.pipe(saveImage
|
|
34
|
-
([values, theEditor,
|
|
20
|
+
r.pipe(saveImage$, withLatestFrom(rootEditor$, imageUploadHandler$, imageDialogState$)),
|
|
21
|
+
([values, theEditor, imageUploadHandler, dialogState]) => {
|
|
35
22
|
const handler = dialogState.type === "editing" ? (src) => {
|
|
36
23
|
theEditor == null ? void 0 : theEditor.update(() => {
|
|
37
24
|
const { nodeKey } = dialogState;
|
|
@@ -40,7 +27,7 @@ const imageSystem = system(
|
|
|
40
27
|
imageNode.setAltText(values.altText);
|
|
41
28
|
imageNode.setSrc(src);
|
|
42
29
|
});
|
|
43
|
-
r.pub(imageDialogState
|
|
30
|
+
r.pub(imageDialogState$, { type: "inactive" });
|
|
44
31
|
} : (src) => {
|
|
45
32
|
theEditor == null ? void 0 : theEditor.update(() => {
|
|
46
33
|
const imageNode = $createImageNode({ altText: values.altText ?? "", src, title: values.title ?? "" });
|
|
@@ -49,10 +36,10 @@ const imageSystem = system(
|
|
|
49
36
|
$wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
|
|
50
37
|
}
|
|
51
38
|
});
|
|
52
|
-
r.pub(imageDialogState
|
|
39
|
+
r.pub(imageDialogState$, { type: "inactive" });
|
|
53
40
|
};
|
|
54
41
|
if (values.file.length > 0) {
|
|
55
|
-
|
|
42
|
+
imageUploadHandler == null ? void 0 : imageUploadHandler(values.file.item(0)).then(handler).catch((e) => {
|
|
56
43
|
throw e;
|
|
57
44
|
});
|
|
58
45
|
} else if (values.src) {
|
|
@@ -60,7 +47,7 @@ const imageSystem = system(
|
|
|
60
47
|
}
|
|
61
48
|
}
|
|
62
49
|
);
|
|
63
|
-
r.sub(rootEditor
|
|
50
|
+
r.sub(rootEditor$, (editor) => {
|
|
64
51
|
editor == null ? void 0 : editor.registerCommand(
|
|
65
52
|
INSERT_IMAGE_COMMAND,
|
|
66
53
|
(payload) => {
|
|
@@ -73,7 +60,7 @@ const imageSystem = system(
|
|
|
73
60
|
},
|
|
74
61
|
COMMAND_PRIORITY_EDITOR
|
|
75
62
|
);
|
|
76
|
-
const theUploadHandler = r.getValue(imageUploadHandler);
|
|
63
|
+
const theUploadHandler = r.getValue(imageUploadHandler$);
|
|
77
64
|
editor == null ? void 0 : editor.registerCommand(
|
|
78
65
|
DRAGSTART_COMMAND,
|
|
79
66
|
(event) => {
|
|
@@ -91,7 +78,7 @@ const imageSystem = system(
|
|
|
91
78
|
editor == null ? void 0 : editor.registerCommand(
|
|
92
79
|
DROP_COMMAND,
|
|
93
80
|
(event) => {
|
|
94
|
-
return onDrop(event, editor, r.getValue(imageUploadHandler));
|
|
81
|
+
return onDrop(event, editor, r.getValue(imageUploadHandler$));
|
|
95
82
|
},
|
|
96
83
|
COMMAND_PRIORITY_HIGH
|
|
97
84
|
);
|
|
@@ -107,7 +94,7 @@ const imageSystem = system(
|
|
|
107
94
|
if (!cbPayload.length || cbPayload.length === 0) {
|
|
108
95
|
return false;
|
|
109
96
|
}
|
|
110
|
-
const imageUploadHandlerValue = r.getValue(imageUploadHandler);
|
|
97
|
+
const imageUploadHandlerValue = r.getValue(imageUploadHandler$);
|
|
111
98
|
Promise.all(cbPayload.map((file) => imageUploadHandlerValue(file.getAsFile()))).then((urls) => {
|
|
112
99
|
urls.forEach((url) => {
|
|
113
100
|
editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
|
|
@@ -123,42 +110,40 @@ const imageSystem = system(
|
|
|
123
110
|
COMMAND_PRIORITY_CRITICAL
|
|
124
111
|
);
|
|
125
112
|
});
|
|
126
|
-
|
|
127
|
-
imageDialogState,
|
|
128
|
-
saveImage,
|
|
129
|
-
openNewImageDialog,
|
|
130
|
-
openEditImageDialog,
|
|
131
|
-
closeImageDialog,
|
|
132
|
-
imageUploadHandler,
|
|
133
|
-
imageAutocompleteSuggestions,
|
|
134
|
-
disableImageResize,
|
|
135
|
-
insertImage,
|
|
136
|
-
imagePreviewHandler
|
|
137
|
-
};
|
|
138
|
-
},
|
|
139
|
-
[coreSystem]
|
|
113
|
+
}
|
|
140
114
|
);
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
115
|
+
const openNewImageDialog$ = Action((r) => {
|
|
116
|
+
r.link(r.pipe(openNewImageDialog$, mapTo({ type: "new" })), imageDialogState$);
|
|
117
|
+
});
|
|
118
|
+
const openEditImageDialog$ = Signal((r) => {
|
|
119
|
+
r.link(
|
|
120
|
+
r.pipe(
|
|
121
|
+
openEditImageDialog$,
|
|
122
|
+
map((payload) => ({ type: "editing", ...payload }))
|
|
123
|
+
),
|
|
124
|
+
imageDialogState$
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
const closeImageDialog$ = Action((r) => {
|
|
128
|
+
r.link(r.pipe(closeImageDialog$, mapTo({ type: "inactive" })), imageDialogState$);
|
|
129
|
+
});
|
|
130
|
+
const saveImage$ = Signal();
|
|
131
|
+
const imagePlugin = realmPlugin({
|
|
132
|
+
init(realm) {
|
|
133
|
+
realm.pubIn({
|
|
134
|
+
[addImportVisitor$]: [MdastImageVisitor, MdastHtmlImageVisitor, MdastJsxImageVisitor],
|
|
135
|
+
[addLexicalNode$]: ImageNode,
|
|
136
|
+
[addExportVisitor$]: LexicalImageVisitor,
|
|
137
|
+
[addComposerChild$]: ImageDialog
|
|
138
|
+
});
|
|
154
139
|
},
|
|
155
|
-
|
|
156
|
-
realm.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
140
|
+
update(realm, params) {
|
|
141
|
+
realm.pubIn({
|
|
142
|
+
[imageUploadHandler$]: (params == null ? void 0 : params.imageUploadHandler) || null,
|
|
143
|
+
[imageAutocompleteSuggestions$]: (params == null ? void 0 : params.imageAutocompleteSuggestions) || [],
|
|
144
|
+
[disableImageResize$]: Boolean(params == null ? void 0 : params.disableImageResize),
|
|
145
|
+
[imagePreviewHandler$]: (params == null ? void 0 : params.imagePreviewHandler) || null
|
|
146
|
+
});
|
|
162
147
|
}
|
|
163
148
|
});
|
|
164
149
|
const getDOMSelection = (targetWindow) => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
|
|
@@ -294,7 +279,15 @@ export {
|
|
|
294
279
|
$isImageNode,
|
|
295
280
|
INSERT_IMAGE_COMMAND,
|
|
296
281
|
ImageNode,
|
|
282
|
+
closeImageDialog$,
|
|
283
|
+
disableImageResize$,
|
|
284
|
+
imageAutocompleteSuggestions$,
|
|
285
|
+
imageDialogState$,
|
|
297
286
|
imagePlugin,
|
|
298
|
-
|
|
299
|
-
|
|
287
|
+
imagePreviewHandler$,
|
|
288
|
+
imageUploadHandler$,
|
|
289
|
+
insertImage$,
|
|
290
|
+
openEditImageDialog$,
|
|
291
|
+
openNewImageDialog$,
|
|
292
|
+
saveImage$
|
|
300
293
|
};
|
|
@@ -7,8 +7,9 @@ var __publicField = (obj, key, value) => {
|
|
|
7
7
|
import { DecoratorNode } from "lexical";
|
|
8
8
|
import React__default from "react";
|
|
9
9
|
import { NestedEditorsContext } from "../core/NestedLexicalEditor.js";
|
|
10
|
-
import { jsxPluginHooks } from "./index.js";
|
|
11
10
|
import { voidEmitter } from "../../utils/voidEmitter.js";
|
|
11
|
+
import { useCellValue } from "@mdxeditor/gurx";
|
|
12
|
+
import { jsxComponentDescriptors$ } from "../core/index.js";
|
|
12
13
|
class LexicalJsxNode extends DecoratorNode {
|
|
13
14
|
constructor(mdastNode, key) {
|
|
14
15
|
super(key);
|
|
@@ -68,7 +69,7 @@ class LexicalJsxNode extends DecoratorNode {
|
|
|
68
69
|
}
|
|
69
70
|
function JsxEditorContainer(props) {
|
|
70
71
|
const { mdastNode } = props;
|
|
71
|
-
const
|
|
72
|
+
const jsxComponentDescriptors = useCellValue(jsxComponentDescriptors$);
|
|
72
73
|
const descriptor = jsxComponentDescriptors.find((descriptor2) => descriptor2.name === mdastNode.name);
|
|
73
74
|
if (!descriptor) {
|
|
74
75
|
throw new Error(`No JSX descriptor found for ${mdastNode.name}`);
|