@mdxeditor/editor 0.10.1 → 0.11.1-alpha.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/README.md +4 -3
- package/dist/FormatConstants.d.ts +9 -0
- package/dist/FormatConstants.js +10 -0
- package/dist/MDXEditor.d.ts +60 -0
- package/dist/MDXEditor.js +105 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +17 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +29 -0
- package/dist/directive-editors/GenericDirectiveEditor.d.ts +8 -0
- package/dist/directive-editors/GenericDirectiveEditor.js +32 -0
- package/dist/exportMarkdownFromLexical.d.ts +114 -0
- package/dist/exportMarkdownFromLexical.js +199 -0
- package/dist/gurx/index.d.ts +3 -0
- package/dist/gurx/react.d.ts +121 -0
- package/dist/gurx/react.js +198 -0
- package/dist/gurx/realm.d.ts +133 -0
- package/dist/gurx/realm.js +491 -0
- package/dist/gurx/realmFactory.d.ts +58 -0
- package/dist/gurx/realmFactory.js +32 -0
- package/dist/icons/add_column.svg.js +8 -0
- package/dist/icons/add_photo.svg.js +8 -0
- package/dist/icons/add_row.svg.js +8 -0
- package/dist/icons/arrow_drop_down.svg.js +8 -0
- package/dist/icons/arrow_right.svg.js +8 -0
- package/dist/icons/check.svg.js +8 -0
- package/dist/icons/close.svg.js +8 -0
- package/dist/icons/code.svg.js +8 -0
- package/dist/icons/content_copy.svg.js +8 -0
- package/dist/icons/delete.svg.js +8 -0
- package/dist/icons/delete_small.svg.js +8 -0
- package/dist/icons/deployed_code.svg.js +8 -0
- package/dist/icons/difference.svg.js +8 -0
- package/dist/icons/edit.svg.js +8 -0
- package/dist/icons/emergency_home.svg.js +8 -0
- package/dist/icons/format_align_center.svg.js +8 -0
- package/dist/icons/format_align_left.svg.js +8 -0
- package/dist/icons/format_align_right.svg.js +8 -0
- package/dist/icons/format_bold.svg.js +8 -0
- package/dist/icons/format_italic.svg.js +8 -0
- package/dist/icons/format_list_bulleted.svg.js +8 -0
- package/dist/icons/format_list_numbered.svg.js +8 -0
- package/dist/icons/format_underlined.svg.js +8 -0
- package/dist/icons/frame_source.svg.js +8 -0
- package/dist/icons/frontmatter.svg.js +8 -0
- package/dist/icons/horizontal_rule.svg.js +8 -0
- package/dist/icons/insert_col_left.svg.js +8 -0
- package/dist/icons/insert_col_right.svg.js +8 -0
- package/dist/icons/insert_row_above.svg.js +8 -0
- package/dist/icons/insert_row_below.svg.js +8 -0
- package/dist/icons/link.svg.js +8 -0
- package/dist/icons/link_off.svg.js +8 -0
- package/dist/icons/markdown.svg.js +8 -0
- package/dist/icons/more_horiz.svg.js +8 -0
- package/dist/icons/open_in_new.svg.js +8 -0
- package/dist/icons/redo.svg.js +8 -0
- package/dist/icons/rich_text.svg.js +8 -0
- package/dist/icons/settings.svg.js +8 -0
- package/dist/icons/table.svg.js +8 -0
- package/dist/icons/undo.svg.js +8 -0
- package/dist/importMarkdownToLexical.d.ts +84 -0
- package/dist/importMarkdownToLexical.js +65 -0
- package/dist/index.d.ts +53 -1105
- package/dist/index.js +170 -72
- package/dist/jsx-editors/GenericJsxEditor.d.ts +8 -0
- package/dist/jsx-editors/GenericJsxEditor.js +56 -0
- package/dist/node_modules/react-diff-view/style/index.css.js +4 -0
- package/dist/plugins/codeblock/CodeBlockNode.d.ts +99 -0
- package/dist/plugins/codeblock/CodeBlockNode.js +155 -0
- package/dist/plugins/codeblock/CodeBlockVisitor.d.ts +4 -0
- package/dist/plugins/codeblock/CodeBlockVisitor.js +14 -0
- package/dist/plugins/codeblock/MdastCodeVisitor.d.ts +3 -0
- package/dist/plugins/codeblock/MdastCodeVisitor.js +16 -0
- package/dist/plugins/codeblock/index.d.ts +616 -0
- package/dist/plugins/codeblock/index.js +73 -0
- package/dist/plugins/codemirror/CodeMirrorEditor.d.ts +3 -0
- package/dist/plugins/codemirror/CodeMirrorEditor.js +33 -0
- package/dist/plugins/codemirror/index.d.ts +799 -0
- package/dist/plugins/codemirror/index.js +62 -0
- package/dist/plugins/core/LexicalLinebreakVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalLinebreakVisitor.js +10 -0
- package/dist/plugins/core/LexicalParagraphVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalParagraphVisitor.js +10 -0
- package/dist/plugins/core/LexicalRootVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalRootVisitor.js +10 -0
- package/dist/plugins/core/LexicalTextVisitor.d.ts +5 -0
- package/dist/plugins/core/LexicalTextVisitor.js +85 -0
- package/dist/plugins/core/MdastFormattingVisitor.d.ts +4 -0
- package/dist/plugins/core/MdastFormattingVisitor.js +36 -0
- package/dist/plugins/core/MdastInlineCodeVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastInlineCodeVisitor.js +11 -0
- package/dist/plugins/core/MdastParagraphVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastParagraphVisitor.js +15 -0
- package/dist/plugins/core/MdastRootVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastRootVisitor.js +9 -0
- package/dist/plugins/core/MdastTextVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastTextVisitor.js +10 -0
- package/dist/plugins/core/NestedLexicalEditor.d.ts +96 -0
- package/dist/plugins/core/NestedLexicalEditor.js +181 -0
- package/dist/plugins/core/PropertyPopover.d.ts +23 -0
- package/dist/plugins/core/PropertyPopover.js +36 -0
- package/dist/plugins/core/SharedHistoryPlugin.d.ts +2 -0
- package/dist/plugins/core/SharedHistoryPlugin.js +10 -0
- package/dist/plugins/core/index.d.ts +423 -0
- package/dist/plugins/core/index.js +346 -0
- package/dist/plugins/core/ui/PopoverUtils.d.ts +4 -0
- package/dist/plugins/core/ui/PopoverUtils.js +17 -0
- package/dist/plugins/diff-source/DiffSourceWrapper.d.ts +4 -0
- package/dist/plugins/diff-source/DiffSourceWrapper.js +11 -0
- package/dist/plugins/diff-source/DiffViewer.d.ts +2 -0
- package/dist/plugins/diff-source/DiffViewer.js +18 -0
- package/dist/plugins/diff-source/SourceEditor.d.ts +2 -0
- package/dist/plugins/diff-source/SourceEditor.js +27 -0
- package/dist/plugins/diff-source/index.d.ts +543 -0
- package/dist/plugins/diff-source/index.js +55 -0
- package/dist/plugins/directives/DirectiveNode.d.ts +51 -0
- package/dist/plugins/directives/DirectiveNode.js +92 -0
- package/dist/plugins/directives/DirectiveVisitor.d.ts +4 -0
- package/dist/plugins/directives/DirectiveVisitor.js +10 -0
- package/dist/plugins/directives/MdastDirectiveVisitor.d.ts +3 -0
- package/dist/plugins/directives/MdastDirectiveVisitor.js +13 -0
- package/dist/plugins/directives/index.d.ts +602 -0
- package/dist/plugins/directives/index.js +53 -0
- package/dist/plugins/frontmatter/FrontmatterEditor.d.ts +6 -0
- package/dist/plugins/frontmatter/FrontmatterEditor.js +69 -0
- package/dist/plugins/frontmatter/FrontmatterNode.d.ts +35 -0
- package/dist/plugins/frontmatter/FrontmatterNode.js +71 -0
- package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.d.ts +4 -0
- package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.js +10 -0
- package/dist/plugins/frontmatter/MdastFrontmatterVisitor.d.ts +3 -0
- package/dist/plugins/frontmatter/MdastFrontmatterVisitor.js +10 -0
- package/dist/plugins/frontmatter/index.d.ts +522 -0
- package/dist/plugins/frontmatter/index.js +53 -0
- package/dist/plugins/headings/LexicalHeadingVisitor.d.ts +4 -0
- package/dist/plugins/headings/LexicalHeadingVisitor.js +11 -0
- package/dist/plugins/headings/MdastHeadingVisitor.d.ts +3 -0
- package/dist/plugins/headings/MdastHeadingVisitor.js +10 -0
- package/dist/plugins/headings/index.d.ts +117 -0
- package/dist/plugins/headings/index.js +20 -0
- package/dist/plugins/image/ImageEditor.d.ts +9 -0
- package/dist/{ImageEditor-8db2f131.js → plugins/image/ImageEditor.js} +40 -52
- package/dist/plugins/image/ImageNode.d.ts +63 -0
- package/dist/plugins/image/ImageNode.js +136 -0
- package/dist/plugins/image/ImageResizer.d.ts +18 -0
- package/dist/plugins/image/ImageResizer.js +214 -0
- package/dist/plugins/image/LexicalImageVisitor.d.ts +4 -0
- package/dist/plugins/image/LexicalImageVisitor.js +36 -0
- package/dist/plugins/image/MdastImageVisitor.d.ts +6 -0
- package/dist/plugins/image/MdastImageVisitor.js +87 -0
- package/dist/plugins/image/index.d.ts +556 -0
- package/dist/plugins/image/index.js +249 -0
- package/dist/plugins/jsx/LexicalJsxNode.d.ts +54 -0
- package/dist/plugins/jsx/LexicalJsxNode.js +102 -0
- package/dist/plugins/jsx/LexicalJsxVisitor.d.ts +4 -0
- package/dist/plugins/jsx/LexicalJsxVisitor.js +12 -0
- package/dist/plugins/jsx/MdastMdxJsEsmVisitor.d.ts +3 -0
- package/dist/plugins/jsx/MdastMdxJsEsmVisitor.js +8 -0
- package/dist/plugins/jsx/MdastMdxJsxElementVisitor.d.ts +3 -0
- package/dist/plugins/jsx/MdastMdxJsxElementVisitor.js +12 -0
- package/dist/plugins/jsx/index.d.ts +598 -0
- package/dist/plugins/jsx/index.js +59 -0
- package/dist/plugins/link/LexicalLinkVisitor.d.ts +4 -0
- package/dist/plugins/link/LexicalLinkVisitor.js +10 -0
- package/dist/plugins/link/MdastLinkVisitor.d.ts +3 -0
- package/dist/plugins/link/MdastLinkVisitor.js +14 -0
- package/dist/plugins/link/index.d.ts +67 -0
- package/dist/plugins/link/index.js +22 -0
- package/dist/plugins/link-dialog/LinkDialog.d.ts +12 -0
- package/dist/plugins/link-dialog/LinkDialog.js +174 -0
- package/dist/plugins/link-dialog/index.d.ts +507 -0
- package/dist/plugins/link-dialog/index.js +242 -0
- package/dist/plugins/lists/LexicalListItemVisitor.d.ts +4 -0
- package/dist/plugins/lists/LexicalListItemVisitor.js +22 -0
- package/dist/plugins/lists/LexicalListVisitor.d.ts +4 -0
- package/dist/plugins/lists/LexicalListVisitor.js +13 -0
- package/dist/plugins/lists/MdastListItemVisitor.d.ts +3 -0
- package/dist/plugins/lists/MdastListItemVisitor.js +10 -0
- package/dist/plugins/lists/MdastListVisitor.d.ts +3 -0
- package/dist/plugins/lists/MdastListVisitor.js +18 -0
- package/dist/plugins/lists/index.d.ts +532 -0
- package/dist/plugins/lists/index.js +111 -0
- package/dist/plugins/markdown-shortcut/index.d.ts +62 -0
- package/dist/plugins/markdown-shortcut/index.js +34 -0
- package/dist/plugins/quote/LexicalQuoteVisitor.d.ts +4 -0
- package/dist/plugins/quote/LexicalQuoteVisitor.js +12 -0
- package/dist/plugins/quote/MdastBlockQuoteVisitor.d.ts +3 -0
- package/dist/plugins/quote/MdastBlockQuoteVisitor.js +10 -0
- package/dist/plugins/quote/index.d.ts +360 -0
- package/dist/plugins/quote/index.js +26 -0
- package/dist/plugins/sandpack/SandpackEditor.d.ts +7 -0
- package/dist/plugins/sandpack/SandpackEditor.js +35 -0
- package/dist/plugins/sandpack/index.d.ts +838 -0
- package/dist/plugins/sandpack/index.js +93 -0
- package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
- package/dist/{useCodeMirrorRef-5356dfa5.js → plugins/sandpack/useCodeMirrorRef.js} +22 -10
- package/dist/plugins/table/LexicalTableVisitor.d.ts +4 -0
- package/dist/plugins/table/LexicalTableVisitor.js +10 -0
- package/dist/plugins/table/MdastTableVisitor.d.ts +3 -0
- package/dist/plugins/table/MdastTableVisitor.js +10 -0
- package/dist/plugins/table/TableEditor.d.ts +21 -0
- package/dist/plugins/table/TableEditor.js +384 -0
- package/dist/plugins/table/TableNode.d.ts +52 -0
- package/dist/plugins/table/TableNode.js +147 -0
- package/dist/plugins/table/index.d.ts +522 -0
- package/dist/plugins/table/index.js +59 -0
- package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.d.ts +4 -0
- package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +10 -0
- package/dist/plugins/thematic-break/MdastThematicBreakVisitor.d.ts +3 -0
- package/dist/plugins/thematic-break/MdastThematicBreakVisitor.js +10 -0
- package/dist/plugins/thematic-break/index.d.ts +522 -0
- package/dist/plugins/thematic-break/index.js +39 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +6 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.js +52 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +5 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +35 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +6 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +30 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +7 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +32 -0
- package/dist/plugins/toolbar/components/CodeToggle.d.ts +6 -0
- package/dist/plugins/toolbar/components/CodeToggle.js +20 -0
- package/dist/plugins/toolbar/components/CreateLink.d.ts +6 -0
- package/dist/plugins/toolbar/components/CreateLink.js +11 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +18 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +27 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.js +29 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +7 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.js +20 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.js +11 -0
- package/dist/plugins/toolbar/components/InsertImage.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertImage.js +23 -0
- package/dist/plugins/toolbar/components/InsertSandpack.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertSandpack.js +13 -0
- package/dist/plugins/toolbar/components/InsertTable.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertTable.js +20 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.js +11 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +7 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +58 -0
- package/dist/plugins/toolbar/components/ListsToggle.d.ts +7 -0
- package/dist/plugins/toolbar/components/ListsToggle.js +23 -0
- package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +7 -0
- package/dist/plugins/toolbar/components/ShowSandpackInfo.js +32 -0
- package/dist/plugins/toolbar/components/UndoRedo.d.ts +5 -0
- package/dist/plugins/toolbar/components/UndoRedo.js +59 -0
- package/dist/plugins/toolbar/index.d.ts +427 -0
- package/dist/plugins/toolbar/index.js +39 -0
- package/dist/plugins/toolbar/primitives/DialogButton.d.ts +40 -0
- package/dist/plugins/toolbar/primitives/DialogButton.js +115 -0
- package/dist/plugins/toolbar/primitives/TooltipWrap.d.ts +8 -0
- package/dist/plugins/toolbar/primitives/TooltipWrap.js +12 -0
- package/dist/plugins/toolbar/primitives/select.d.ts +50 -0
- package/dist/plugins/toolbar/primitives/select.js +44 -0
- package/dist/plugins/toolbar/primitives/toolbar.d.ts +160 -0
- package/dist/plugins/toolbar/primitives/toolbar.js +111 -0
- package/dist/style.css +556 -249
- package/dist/styles/globals.css.js +4 -0
- package/dist/styles/lexical-theme.module.css.js +53 -0
- package/dist/styles/lexicalTheme.d.ts +2 -0
- package/dist/styles/lexicalTheme.js +28 -0
- package/dist/styles/ui.module.css.js +254 -0
- package/dist/utils/detectMac.d.ts +2 -0
- package/dist/utils/detectMac.js +6 -0
- package/dist/utils/fp.d.ts +47 -0
- package/dist/utils/fp.js +14 -0
- package/dist/utils/isPartOftheEditorUI.d.ts +1 -0
- package/dist/utils/isPartOftheEditorUI.js +12 -0
- package/dist/utils/lexicalHelpers.d.ts +11 -0
- package/dist/utils/lexicalHelpers.js +49 -0
- package/dist/utils/uuid4.d.ts +1 -0
- package/dist/utils/uuid4.js +10 -0
- package/dist/utils/voidEmitter.d.ts +14 -0
- package/dist/utils/voidEmitter.js +15 -0
- package/package.json +261 -14
- package/dist/CodeBlockEditor-02116cba.js +0 -79
- package/dist/CodeBlockEditor-1c7b46dc.cjs +0 -1
- package/dist/FrontmatterEditor-37a4c091.cjs +0 -1
- package/dist/FrontmatterEditor-988a8fb6.js +0 -118
- package/dist/ImageEditor-524159e9.cjs +0 -1
- package/dist/JsxEditor-606e9d86.js +0 -108
- package/dist/JsxEditor-98a94a9d.cjs +0 -1
- package/dist/LeafDirectiveEditor-38a73f5c.js +0 -59
- package/dist/LeafDirectiveEditor-dfa1ce78.cjs +0 -1
- package/dist/SandpackEditor-90425f26.cjs +0 -1
- package/dist/SandpackEditor-c771b4d0.js +0 -100
- package/dist/SourceEditor-19eb2c9e.js +0 -64
- package/dist/SourceEditor-46ed1f77.cjs +0 -1
- package/dist/TableEditor-4a993dab.cjs +0 -1
- package/dist/TableEditor-c28b3ca2.js +0 -426
- package/dist/index-1ab1a12e.js +0 -4363
- package/dist/index-8217810f.cjs +0 -1
- package/dist/index.cjs +0 -1
- package/dist/useCodeMirrorRef-7055e7de.cjs +0 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
import styles from "../../styles/ui.module.css.js";
|
|
4
|
+
import classNames from "classnames";
|
|
5
|
+
function clamp(value, min, max) {
|
|
6
|
+
return Math.min(Math.max(value, min), max);
|
|
7
|
+
}
|
|
8
|
+
const Direction = {
|
|
9
|
+
east: 1 << 0,
|
|
10
|
+
north: 1 << 3,
|
|
11
|
+
south: 1 << 1,
|
|
12
|
+
west: 1 << 2
|
|
13
|
+
};
|
|
14
|
+
function ImageResizer({
|
|
15
|
+
onResizeStart,
|
|
16
|
+
onResizeEnd,
|
|
17
|
+
imageRef,
|
|
18
|
+
maxWidth,
|
|
19
|
+
editor
|
|
20
|
+
}) {
|
|
21
|
+
const controlWrapperRef = useRef(null);
|
|
22
|
+
const userSelect = useRef({
|
|
23
|
+
priority: "",
|
|
24
|
+
value: "default"
|
|
25
|
+
});
|
|
26
|
+
const positioningRef = useRef({
|
|
27
|
+
currentHeight: 0,
|
|
28
|
+
currentWidth: 0,
|
|
29
|
+
direction: 0,
|
|
30
|
+
isResizing: false,
|
|
31
|
+
ratio: 0,
|
|
32
|
+
startHeight: 0,
|
|
33
|
+
startWidth: 0,
|
|
34
|
+
startX: 0,
|
|
35
|
+
startY: 0
|
|
36
|
+
});
|
|
37
|
+
const editorRootElement = editor.getRootElement();
|
|
38
|
+
const maxWidthContainer = maxWidth ? maxWidth : editorRootElement !== null ? editorRootElement.getBoundingClientRect().width - 20 : 100;
|
|
39
|
+
const maxHeightContainer = editorRootElement !== null ? editorRootElement.getBoundingClientRect().height - 20 : 100;
|
|
40
|
+
const minWidth = 100;
|
|
41
|
+
const minHeight = 100;
|
|
42
|
+
const setStartCursor = (direction) => {
|
|
43
|
+
const ew = direction === Direction.east || direction === Direction.west;
|
|
44
|
+
const ns = direction === Direction.north || direction === Direction.south;
|
|
45
|
+
const nwse = direction & Direction.north && direction & Direction.west || direction & Direction.south && direction & Direction.east;
|
|
46
|
+
const cursorDir = ew ? "ew" : ns ? "ns" : nwse ? "nwse" : "nesw";
|
|
47
|
+
if (editorRootElement !== null) {
|
|
48
|
+
editorRootElement.style.setProperty("cursor", `${cursorDir}-resize`, "important");
|
|
49
|
+
}
|
|
50
|
+
if (document.body !== null) {
|
|
51
|
+
document.body.style.setProperty("cursor", `${cursorDir}-resize`, "important");
|
|
52
|
+
userSelect.current.value = document.body.style.getPropertyValue("-webkit-user-select");
|
|
53
|
+
userSelect.current.priority = document.body.style.getPropertyPriority("-webkit-user-select");
|
|
54
|
+
document.body.style.setProperty("-webkit-user-select", `none`, "important");
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const setEndCursor = () => {
|
|
58
|
+
if (editorRootElement !== null) {
|
|
59
|
+
editorRootElement.style.setProperty("cursor", "text");
|
|
60
|
+
}
|
|
61
|
+
if (document.body !== null) {
|
|
62
|
+
document.body.style.setProperty("cursor", "default");
|
|
63
|
+
document.body.style.setProperty("-webkit-user-select", userSelect.current.value, userSelect.current.priority);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const handlePointerDown = (event, direction) => {
|
|
67
|
+
if (!editor.isEditable()) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const image = imageRef.current;
|
|
71
|
+
const controlWrapper = controlWrapperRef.current;
|
|
72
|
+
if (image !== null && controlWrapper !== null) {
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
const { width, height } = image.getBoundingClientRect();
|
|
75
|
+
const positioning = positioningRef.current;
|
|
76
|
+
positioning.startWidth = width;
|
|
77
|
+
positioning.startHeight = height;
|
|
78
|
+
positioning.ratio = width / height;
|
|
79
|
+
positioning.currentWidth = width;
|
|
80
|
+
positioning.currentHeight = height;
|
|
81
|
+
positioning.startX = event.clientX;
|
|
82
|
+
positioning.startY = event.clientY;
|
|
83
|
+
positioning.isResizing = true;
|
|
84
|
+
positioning.direction = direction;
|
|
85
|
+
setStartCursor(direction);
|
|
86
|
+
onResizeStart();
|
|
87
|
+
controlWrapper.classList.add(styles.imageControlWrapperResizing);
|
|
88
|
+
image.style.height = `${height}px`;
|
|
89
|
+
image.style.width = `${width}px`;
|
|
90
|
+
document.addEventListener("pointermove", handlePointerMove);
|
|
91
|
+
document.addEventListener("pointerup", handlePointerUp);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const handlePointerMove = (event) => {
|
|
95
|
+
const image = imageRef.current;
|
|
96
|
+
const positioning = positioningRef.current;
|
|
97
|
+
const isHorizontal = positioning.direction & (Direction.east | Direction.west);
|
|
98
|
+
const isVertical = positioning.direction & (Direction.south | Direction.north);
|
|
99
|
+
if (image !== null && positioning.isResizing) {
|
|
100
|
+
if (isHorizontal && isVertical) {
|
|
101
|
+
let diff = Math.floor(positioning.startX - event.clientX);
|
|
102
|
+
diff = positioning.direction & Direction.east ? -diff : diff;
|
|
103
|
+
const width = clamp(positioning.startWidth + diff, minWidth, maxWidthContainer);
|
|
104
|
+
const height = width / positioning.ratio;
|
|
105
|
+
image.style.width = `${width}px`;
|
|
106
|
+
image.style.height = `${height}px`;
|
|
107
|
+
positioning.currentHeight = height;
|
|
108
|
+
positioning.currentWidth = width;
|
|
109
|
+
} else if (isVertical) {
|
|
110
|
+
let diff = Math.floor(positioning.startY - event.clientY);
|
|
111
|
+
diff = positioning.direction & Direction.south ? -diff : diff;
|
|
112
|
+
const height = clamp(positioning.startHeight + diff, minHeight, maxHeightContainer);
|
|
113
|
+
image.style.height = `${height}px`;
|
|
114
|
+
positioning.currentHeight = height;
|
|
115
|
+
} else {
|
|
116
|
+
let diff = Math.floor(positioning.startX - event.clientX);
|
|
117
|
+
diff = positioning.direction & Direction.east ? -diff : diff;
|
|
118
|
+
const width = clamp(positioning.startWidth + diff, minWidth, maxWidthContainer);
|
|
119
|
+
image.style.width = `${width}px`;
|
|
120
|
+
positioning.currentWidth = width;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const handlePointerUp = () => {
|
|
125
|
+
const image = imageRef.current;
|
|
126
|
+
const positioning = positioningRef.current;
|
|
127
|
+
const controlWrapper = controlWrapperRef.current;
|
|
128
|
+
if (image !== null && controlWrapper !== null && positioning.isResizing) {
|
|
129
|
+
const width = positioning.currentWidth;
|
|
130
|
+
const height = positioning.currentHeight;
|
|
131
|
+
positioning.startWidth = 0;
|
|
132
|
+
positioning.startHeight = 0;
|
|
133
|
+
positioning.ratio = 0;
|
|
134
|
+
positioning.startX = 0;
|
|
135
|
+
positioning.startY = 0;
|
|
136
|
+
positioning.currentWidth = 0;
|
|
137
|
+
positioning.currentHeight = 0;
|
|
138
|
+
positioning.isResizing = false;
|
|
139
|
+
controlWrapper.classList.remove(styles.imageControlWrapperResizing);
|
|
140
|
+
setEndCursor();
|
|
141
|
+
onResizeEnd(width, height);
|
|
142
|
+
document.removeEventListener("pointermove", handlePointerMove);
|
|
143
|
+
document.removeEventListener("pointerup", handlePointerUp);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
return /* @__PURE__ */ React.createElement("div", { ref: controlWrapperRef }, /* @__PURE__ */ React.createElement(
|
|
147
|
+
"div",
|
|
148
|
+
{
|
|
149
|
+
className: classNames(styles.imageResizer, styles.imageResizerN),
|
|
150
|
+
onPointerDown: (event) => {
|
|
151
|
+
handlePointerDown(event, Direction.north);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
), /* @__PURE__ */ React.createElement(
|
|
155
|
+
"div",
|
|
156
|
+
{
|
|
157
|
+
className: classNames(styles.imageResizer, styles.imageResizerNe),
|
|
158
|
+
onPointerDown: (event) => {
|
|
159
|
+
handlePointerDown(event, Direction.north | Direction.east);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
), /* @__PURE__ */ React.createElement(
|
|
163
|
+
"div",
|
|
164
|
+
{
|
|
165
|
+
className: classNames(styles.imageResizer, styles.imageResizerE),
|
|
166
|
+
onPointerDown: (event) => {
|
|
167
|
+
handlePointerDown(event, Direction.east);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
), /* @__PURE__ */ React.createElement(
|
|
171
|
+
"div",
|
|
172
|
+
{
|
|
173
|
+
className: classNames(styles.imageResizer, styles.imageResizerSe),
|
|
174
|
+
onPointerDown: (event) => {
|
|
175
|
+
handlePointerDown(event, Direction.south | Direction.east);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
), /* @__PURE__ */ React.createElement(
|
|
179
|
+
"div",
|
|
180
|
+
{
|
|
181
|
+
className: classNames(styles.imageResizer, styles.imageResizerS),
|
|
182
|
+
onPointerDown: (event) => {
|
|
183
|
+
handlePointerDown(event, Direction.south);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
), /* @__PURE__ */ React.createElement(
|
|
187
|
+
"div",
|
|
188
|
+
{
|
|
189
|
+
className: classNames(styles.imageResizer, styles.imageResizerSw),
|
|
190
|
+
onPointerDown: (event) => {
|
|
191
|
+
handlePointerDown(event, Direction.south | Direction.west);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
), /* @__PURE__ */ React.createElement(
|
|
195
|
+
"div",
|
|
196
|
+
{
|
|
197
|
+
className: classNames(styles.imageResizer, styles.imageResizerW),
|
|
198
|
+
onPointerDown: (event) => {
|
|
199
|
+
handlePointerDown(event, Direction.west);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
), /* @__PURE__ */ React.createElement(
|
|
203
|
+
"div",
|
|
204
|
+
{
|
|
205
|
+
className: classNames(styles.imageResizer, styles.imageResizerNw),
|
|
206
|
+
onPointerDown: (event) => {
|
|
207
|
+
handlePointerDown(event, Direction.north | Direction.west);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
));
|
|
211
|
+
}
|
|
212
|
+
export {
|
|
213
|
+
ImageResizer as default
|
|
214
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { $isImageNode } from "./ImageNode.js";
|
|
2
|
+
const LexicalImageVisitor = {
|
|
3
|
+
testLexicalNode: $isImageNode,
|
|
4
|
+
visitLexicalNode({ mdastParent, lexicalNode, actions }) {
|
|
5
|
+
if (lexicalNode.hasExplicitDimensions()) {
|
|
6
|
+
const img = new Image();
|
|
7
|
+
if (lexicalNode.getHeight() !== "inherit") {
|
|
8
|
+
img.height = lexicalNode.getHeight();
|
|
9
|
+
}
|
|
10
|
+
if (lexicalNode.getWidth() !== "inherit") {
|
|
11
|
+
img.width = lexicalNode.getWidth();
|
|
12
|
+
}
|
|
13
|
+
img.src = lexicalNode.getSrc();
|
|
14
|
+
if (lexicalNode.getAltText()) {
|
|
15
|
+
img.alt = lexicalNode.getAltText();
|
|
16
|
+
}
|
|
17
|
+
if (lexicalNode.getTitle()) {
|
|
18
|
+
img.title = lexicalNode.getTitle();
|
|
19
|
+
}
|
|
20
|
+
actions.appendToParent(mdastParent, {
|
|
21
|
+
type: "html",
|
|
22
|
+
value: img.outerHTML.replace(/>$/, "/>")
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
actions.appendToParent(mdastParent, {
|
|
26
|
+
type: "image",
|
|
27
|
+
url: lexicalNode.getSrc(),
|
|
28
|
+
alt: lexicalNode.getAltText(),
|
|
29
|
+
title: lexicalNode.getTitle()
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
LexicalImageVisitor
|
|
36
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as Mdast from 'mdast';
|
|
2
|
+
import { MdastImportVisitor } from '../../importMarkdownToLexical';
|
|
3
|
+
import { MdxJsxTextElement, MdxJsxFlowElement } from 'mdast-util-mdx';
|
|
4
|
+
export declare const MdastImageVisitor: MdastImportVisitor<Mdast.Image>;
|
|
5
|
+
export declare const MdastHtmlImageVisitor: MdastImportVisitor<Mdast.HTML>;
|
|
6
|
+
export declare const MdastJsxImageVisitor: MdastImportVisitor<MdxJsxTextElement | MdxJsxFlowElement>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { $createImageNode } from "./ImageNode.js";
|
|
2
|
+
import { $createParagraphNode } from "lexical";
|
|
3
|
+
const MdastImageVisitor = {
|
|
4
|
+
testNode: "image",
|
|
5
|
+
visitNode({ mdastNode, actions }) {
|
|
6
|
+
actions.addAndStepInto(
|
|
7
|
+
$createImageNode({
|
|
8
|
+
src: mdastNode.url,
|
|
9
|
+
altText: mdastNode.alt || "",
|
|
10
|
+
title: mdastNode.title || ""
|
|
11
|
+
})
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const MdastHtmlImageVisitor = {
|
|
16
|
+
testNode: (node) => {
|
|
17
|
+
return node.type === "html" && node.value.trim().startsWith("<img");
|
|
18
|
+
},
|
|
19
|
+
visitNode({ mdastNode, lexicalParent }) {
|
|
20
|
+
const wrapper = document.createElement("div");
|
|
21
|
+
wrapper.innerHTML = mdastNode.value;
|
|
22
|
+
const img = wrapper.querySelector("img");
|
|
23
|
+
if (!img) {
|
|
24
|
+
throw new Error("Invalid HTML image");
|
|
25
|
+
}
|
|
26
|
+
const src = img.src;
|
|
27
|
+
const altText = img.alt;
|
|
28
|
+
const title = img.title;
|
|
29
|
+
const width = img.width;
|
|
30
|
+
const height = img.height;
|
|
31
|
+
const image = $createImageNode({
|
|
32
|
+
src: src || "",
|
|
33
|
+
altText,
|
|
34
|
+
title,
|
|
35
|
+
width,
|
|
36
|
+
height
|
|
37
|
+
});
|
|
38
|
+
if (lexicalParent.getType() === "root") {
|
|
39
|
+
const paragraph = $createParagraphNode();
|
|
40
|
+
paragraph.append(image);
|
|
41
|
+
lexicalParent.append(paragraph);
|
|
42
|
+
} else {
|
|
43
|
+
lexicalParent.append(image);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
function getAttributeValue(node, attributeName) {
|
|
48
|
+
const attribute = node.attributes.find((a) => a.type === "mdxJsxAttribute" && a.name === attributeName);
|
|
49
|
+
if (!attribute) {
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
return attribute.value;
|
|
53
|
+
}
|
|
54
|
+
const MdastJsxImageVisitor = {
|
|
55
|
+
testNode: (node) => {
|
|
56
|
+
return (node.type === "mdxJsxTextElement" || node.type === "mdxJsxFlowElement") && node.name === "img";
|
|
57
|
+
},
|
|
58
|
+
visitNode({ mdastNode, lexicalParent }) {
|
|
59
|
+
const src = getAttributeValue(mdastNode, "src");
|
|
60
|
+
if (!src) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const altText = getAttributeValue(mdastNode, "alt") || "";
|
|
64
|
+
const title = getAttributeValue(mdastNode, "title");
|
|
65
|
+
const height = getAttributeValue(mdastNode, "height");
|
|
66
|
+
const width = getAttributeValue(mdastNode, "width");
|
|
67
|
+
const image = $createImageNode({
|
|
68
|
+
src,
|
|
69
|
+
altText,
|
|
70
|
+
title,
|
|
71
|
+
width: width ? parseInt(width, 10) : void 0,
|
|
72
|
+
height: height ? parseInt(height, 10) : void 0
|
|
73
|
+
});
|
|
74
|
+
if (lexicalParent.getType() === "root") {
|
|
75
|
+
const paragraph = $createParagraphNode();
|
|
76
|
+
paragraph.append(image);
|
|
77
|
+
lexicalParent.append(paragraph);
|
|
78
|
+
} else {
|
|
79
|
+
lexicalParent.append(image);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
export {
|
|
84
|
+
MdastHtmlImageVisitor,
|
|
85
|
+
MdastImageVisitor,
|
|
86
|
+
MdastJsxImageVisitor
|
|
87
|
+
};
|