@mdxeditor/editor 0.0.0-development
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/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/FormatConstants.d.ts +9 -0
- package/dist/FormatConstants.js +10 -0
- package/dist/MDXEditor.d.ts +92 -0
- package/dist/MDXEditor.js +142 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +17 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +28 -0
- package/dist/directive-editors/GenericDirectiveEditor.d.ts +8 -0
- package/dist/directive-editors/GenericDirectiveEditor.js +32 -0
- package/dist/exportMarkdownFromLexical.d.ts +133 -0
- package/dist/exportMarkdownFromLexical.js +202 -0
- package/dist/gurx/index.d.ts +3 -0
- package/dist/gurx/react.d.ts +152 -0
- package/dist/gurx/react.js +206 -0
- package/dist/gurx/realm.d.ts +148 -0
- package/dist/gurx/realm.js +489 -0
- package/dist/gurx/realmFactory.d.ts +79 -0
- package/dist/gurx/realmFactory.js +32 -0
- package/dist/icons/add_column.svg.js +5 -0
- package/dist/icons/add_photo.svg.js +5 -0
- package/dist/icons/add_row.svg.js +5 -0
- package/dist/icons/admonition.svg.js +5 -0
- package/dist/icons/arrow_drop_down.svg.js +5 -0
- package/dist/icons/check.svg.js +5 -0
- package/dist/icons/check_small.svg.js +5 -0
- package/dist/icons/close.svg.js +5 -0
- package/dist/icons/code.svg.js +5 -0
- package/dist/icons/code_block.svg.js +5 -0
- package/dist/icons/content_copy.svg.js +5 -0
- package/dist/icons/delete_big.svg.js +5 -0
- package/dist/icons/delete_small.svg.js +5 -0
- package/dist/icons/difference.svg.js +5 -0
- package/dist/icons/edit.svg.js +5 -0
- package/dist/icons/format_align_center.svg.js +5 -0
- package/dist/icons/format_align_left.svg.js +5 -0
- package/dist/icons/format_align_right.svg.js +5 -0
- package/dist/icons/format_bold.svg.js +5 -0
- package/dist/icons/format_italic.svg.js +5 -0
- package/dist/icons/format_list_bulleted.svg.js +7 -0
- package/dist/icons/format_list_checked.svg.js +5 -0
- package/dist/icons/format_list_numbered.svg.js +5 -0
- package/dist/icons/format_underlined.svg.js +5 -0
- package/dist/icons/frontmatter.svg.js +5 -0
- package/dist/icons/horizontal_rule.svg.js +5 -0
- package/dist/icons/insert_col_left.svg.js +5 -0
- package/dist/icons/insert_col_right.svg.js +5 -0
- package/dist/icons/insert_row_above.svg.js +5 -0
- package/dist/icons/insert_row_below.svg.js +5 -0
- package/dist/icons/link.svg.js +5 -0
- package/dist/icons/link_off.svg.js +5 -0
- package/dist/icons/markdown.svg.js +5 -0
- package/dist/icons/more_horiz.svg.js +5 -0
- package/dist/icons/more_vert.svg.js +5 -0
- package/dist/icons/open_in_new.svg.js +5 -0
- package/dist/icons/redo.svg.js +5 -0
- package/dist/icons/rich_text.svg.js +5 -0
- package/dist/icons/sandpack.svg.js +5 -0
- package/dist/icons/settings.svg.js +7 -0
- package/dist/icons/table.svg.js +5 -0
- package/dist/icons/undo.svg.js +5 -0
- package/dist/importMarkdownToLexical.d.ts +91 -0
- package/dist/importMarkdownToLexical.js +69 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +175 -0
- package/dist/jsx-editors/GenericJsxEditor.d.ts +8 -0
- package/dist/jsx-editors/GenericJsxEditor.js +56 -0
- package/dist/plugins/codeblock/CodeBlockNode.d.ts +100 -0
- package/dist/plugins/codeblock/CodeBlockNode.js +158 -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 +697 -0
- package/dist/plugins/codeblock/index.js +73 -0
- package/dist/plugins/codemirror/CodeMirrorEditor.d.ts +3 -0
- package/dist/plugins/codemirror/CodeMirrorEditor.js +42 -0
- package/dist/plugins/codemirror/index.d.ts +912 -0
- package/dist/plugins/codemirror/index.js +62 -0
- package/dist/plugins/core/Icon.d.ts +6 -0
- package/dist/plugins/core/Icon.js +94 -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/MdastBreakVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastBreakVisitor.js +10 -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 +27 -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 +92 -0
- package/dist/plugins/core/NestedLexicalEditor.js +180 -0
- package/dist/plugins/core/PropertyPopover.d.ts +23 -0
- package/dist/plugins/core/PropertyPopover.js +39 -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 +506 -0
- package/dist/plugins/core/index.js +420 -0
- package/dist/plugins/core/ui/DownshiftAutoComplete.d.ts +15 -0
- package/dist/plugins/core/ui/DownshiftAutoComplete.js +83 -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 +59 -0
- package/dist/plugins/diff-source/SourceEditor.d.ts +4 -0
- package/dist/plugins/diff-source/SourceEditor.js +47 -0
- package/dist/plugins/diff-source/index.d.ts +635 -0
- package/dist/plugins/diff-source/index.js +57 -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 +683 -0
- package/dist/plugins/directives/index.js +53 -0
- package/dist/plugins/frontmatter/FrontmatterEditor.d.ts +6 -0
- package/dist/plugins/frontmatter/FrontmatterEditor.js +85 -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 +627 -0
- package/dist/plugins/frontmatter/index.js +76 -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 +617 -0
- package/dist/plugins/headings/index.js +69 -0
- package/dist/plugins/image/ImageDialog.d.ts +2 -0
- package/dist/plugins/image/ImageDialog.js +70 -0
- package/dist/plugins/image/ImageEditor.d.ts +10 -0
- package/dist/plugins/image/ImageEditor.js +227 -0
- package/dist/plugins/image/ImageNode.d.ts +65 -0
- package/dist/plugins/image/ImageNode.js +152 -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 +35 -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 +714 -0
- package/dist/plugins/image/index.js +300 -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 +688 -0
- package/dist/plugins/jsx/index.js +78 -0
- package/dist/plugins/link/AutoLinkPlugin.d.ts +9 -0
- package/dist/plugins/link/AutoLinkPlugin.js +18 -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 +92 -0
- package/dist/plugins/link/index.js +33 -0
- package/dist/plugins/link-dialog/LinkDialog.d.ts +16 -0
- package/dist/plugins/link-dialog/LinkDialog.js +148 -0
- package/dist/plugins/link-dialog/index.d.ts +595 -0
- package/dist/plugins/link-dialog/index.js +260 -0
- package/dist/plugins/lists/LexicalListItemVisitor.d.ts +4 -0
- package/dist/plugins/lists/LexicalListItemVisitor.js +23 -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 +20 -0
- package/dist/plugins/lists/index.d.ts +613 -0
- package/dist/plugins/lists/index.js +119 -0
- package/dist/plugins/markdown-shortcut/index.d.ts +71 -0
- package/dist/plugins/markdown-shortcut/index.js +90 -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 +417 -0
- package/dist/plugins/quote/index.js +26 -0
- package/dist/plugins/sandpack/SandpackEditor.d.ts +7 -0
- package/dist/plugins/sandpack/SandpackEditor.js +37 -0
- package/dist/plugins/sandpack/index.d.ts +951 -0
- package/dist/plugins/sandpack/index.js +93 -0
- package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
- package/dist/plugins/sandpack/useCodeMirrorRef.js +96 -0
- 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 +388 -0
- package/dist/plugins/table/TableNode.d.ts +52 -0
- package/dist/plugins/table/TableNode.js +152 -0
- package/dist/plugins/table/index.d.ts +614 -0
- package/dist/plugins/table/index.js +69 -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 +603 -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 +54 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +5 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +33 -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 +19 -0
- package/dist/plugins/toolbar/components/CreateLink.d.ts +6 -0
- package/dist/plugins/toolbar/components/CreateLink.js +20 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +18 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +25 -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 +24 -0
- package/dist/plugins/toolbar/components/InsertImage.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertImage.js +14 -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 +31 -0
- package/dist/plugins/toolbar/components/UndoRedo.d.ts +5 -0
- package/dist/plugins/toolbar/components/UndoRedo.js +58 -0
- package/dist/plugins/toolbar/index.d.ts +492 -0
- package/dist/plugins/toolbar/index.js +40 -0
- package/dist/plugins/toolbar/primitives/DialogButton.d.ts +40 -0
- package/dist/plugins/toolbar/primitives/DialogButton.js +114 -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 +55 -0
- package/dist/plugins/toolbar/primitives/toolbar.d.ts +163 -0
- package/dist/plugins/toolbar/primitives/toolbar.js +115 -0
- package/dist/style.css +1715 -0
- package/dist/styles/globals.css.js +4 -0
- package/dist/styles/lexical-theme.module.css.js +62 -0
- package/dist/styles/lexicalTheme.d.ts +2 -0
- package/dist/styles/lexicalTheme.js +31 -0
- package/dist/styles/ui.module.css.js +308 -0
- package/dist/utils/detectMac.d.ts +3 -0
- package/dist/utils/detectMac.js +13 -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 +62 -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 +435 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { coreSystem } from "../core/index.js";
|
|
2
|
+
import { MdastHeadingVisitor } from "./MdastHeadingVisitor.js";
|
|
3
|
+
import { $createHeadingNode, HeadingNode } from "@lexical/rich-text";
|
|
4
|
+
import { LexicalHeadingVisitor } from "./LexicalHeadingVisitor.js";
|
|
5
|
+
import { KEY_DOWN_COMMAND, $createParagraphNode, COMMAND_PRIORITY_LOW } from "lexical";
|
|
6
|
+
import { controlOrMeta } from "../../utils/detectMac.js";
|
|
7
|
+
import { system } from "../../gurx/realmFactory.js";
|
|
8
|
+
import { realmPlugin } from "../../gurx/react.js";
|
|
9
|
+
const FORMATTING_KEYS = [48, 49, 50, 51, 52, 53, 54];
|
|
10
|
+
const ALL_HEADING_LEVELS = [1, 2, 3, 4, 5, 6];
|
|
11
|
+
const CODE_TO_HEADING_LEVEL_MAP = {
|
|
12
|
+
49: 1,
|
|
13
|
+
50: 2,
|
|
14
|
+
51: 3,
|
|
15
|
+
52: 4,
|
|
16
|
+
53: 5,
|
|
17
|
+
54: 6
|
|
18
|
+
};
|
|
19
|
+
const headingsSystem = system(
|
|
20
|
+
(r, [{ createRootEditorSubscription, convertSelectionToNode }]) => {
|
|
21
|
+
const allowedHeadingLevels = r.node(ALL_HEADING_LEVELS);
|
|
22
|
+
r.pub(createRootEditorSubscription, (theRootEditor) => {
|
|
23
|
+
return theRootEditor.registerCommand(
|
|
24
|
+
KEY_DOWN_COMMAND,
|
|
25
|
+
(event) => {
|
|
26
|
+
const { keyCode, ctrlKey, metaKey, altKey } = event;
|
|
27
|
+
if (FORMATTING_KEYS.includes(keyCode) && controlOrMeta(metaKey, ctrlKey) && altKey) {
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
theRootEditor.update(() => {
|
|
30
|
+
if (keyCode === 48) {
|
|
31
|
+
r.pub(convertSelectionToNode, () => $createParagraphNode());
|
|
32
|
+
} else {
|
|
33
|
+
const allowedHeadingLevelsValues = r.getValue(allowedHeadingLevels);
|
|
34
|
+
const requestedHeadingLevel = CODE_TO_HEADING_LEVEL_MAP[keyCode];
|
|
35
|
+
if (!allowedHeadingLevelsValues.includes(requestedHeadingLevel)) {
|
|
36
|
+
r.pub(convertSelectionToNode, () => $createHeadingNode(`h${requestedHeadingLevel}`));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
},
|
|
44
|
+
COMMAND_PRIORITY_LOW
|
|
45
|
+
);
|
|
46
|
+
});
|
|
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
|
+
},
|
|
59
|
+
init: (realm) => {
|
|
60
|
+
realm.pubKey("addImportVisitor", MdastHeadingVisitor);
|
|
61
|
+
realm.pubKey("addLexicalNode", HeadingNode);
|
|
62
|
+
realm.pubKey("addExportVisitor", LexicalHeadingVisitor);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
export {
|
|
66
|
+
headingsPlugin,
|
|
67
|
+
headingsPluginHooks,
|
|
68
|
+
headingsSystem
|
|
69
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as Dialog from "@radix-ui/react-dialog";
|
|
2
|
+
import classNames from "classnames";
|
|
3
|
+
import React__default from "react";
|
|
4
|
+
import { useForm } from "react-hook-form";
|
|
5
|
+
import styles from "../../styles/ui.module.css.js";
|
|
6
|
+
import { corePluginHooks } from "../core/index.js";
|
|
7
|
+
import { imagePluginHooks } from "./index.js";
|
|
8
|
+
import { DownshiftAutoComplete } from "../core/ui/DownshiftAutoComplete.js";
|
|
9
|
+
const ImageDialog = () => {
|
|
10
|
+
const [imageAutocompleteSuggestions, state] = imagePluginHooks.useEmitterValues("imageAutocompleteSuggestions", "imageDialogState");
|
|
11
|
+
const saveImage = imagePluginHooks.usePublisher("saveImage");
|
|
12
|
+
const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
|
|
13
|
+
const closeImageDialog = imagePluginHooks.usePublisher("closeImageDialog");
|
|
14
|
+
const { register, handleSubmit, control, setValue, reset } = useForm({
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
16
|
+
values: state.type === "editing" ? state.initialValues : {}
|
|
17
|
+
});
|
|
18
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
19
|
+
Dialog.Root,
|
|
20
|
+
{
|
|
21
|
+
open: state.type !== "inactive",
|
|
22
|
+
onOpenChange: (open) => {
|
|
23
|
+
if (!open) {
|
|
24
|
+
closeImageDialog(true);
|
|
25
|
+
reset({ src: "", title: "", altText: "" });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
/* @__PURE__ */ React__default.createElement(Dialog.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Dialog.Overlay, { className: styles.dialogOverlay }), /* @__PURE__ */ React__default.createElement(
|
|
30
|
+
Dialog.Content,
|
|
31
|
+
{
|
|
32
|
+
className: styles.dialogContent,
|
|
33
|
+
onOpenAutoFocus: (e) => {
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
/* @__PURE__ */ React__default.createElement(
|
|
38
|
+
"form",
|
|
39
|
+
{
|
|
40
|
+
onSubmit: (e) => {
|
|
41
|
+
void handleSubmit(saveImage)(e);
|
|
42
|
+
reset({ src: "", title: "", altText: "" });
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
e.stopPropagation();
|
|
45
|
+
},
|
|
46
|
+
className: styles.multiFieldForm
|
|
47
|
+
},
|
|
48
|
+
/* @__PURE__ */ React__default.createElement("div", { className: styles.formField }, /* @__PURE__ */ React__default.createElement("label", { htmlFor: "file" }, "Upload an image from your device:"), /* @__PURE__ */ React__default.createElement("input", { type: "file", ...register("file") })),
|
|
49
|
+
/* @__PURE__ */ React__default.createElement("div", { className: styles.formField }, /* @__PURE__ */ React__default.createElement("label", { htmlFor: "src" }, "Or add an image from an URL:"), /* @__PURE__ */ React__default.createElement(
|
|
50
|
+
DownshiftAutoComplete,
|
|
51
|
+
{
|
|
52
|
+
register,
|
|
53
|
+
initialInputValue: state.type === "editing" ? state.initialValues.src || "" : "",
|
|
54
|
+
inputName: "src",
|
|
55
|
+
suggestions: imageAutocompleteSuggestions,
|
|
56
|
+
setValue,
|
|
57
|
+
control,
|
|
58
|
+
placeholder: "Select or paste an image src"
|
|
59
|
+
}
|
|
60
|
+
)),
|
|
61
|
+
/* @__PURE__ */ React__default.createElement("div", { className: styles.formField }, /* @__PURE__ */ React__default.createElement("label", { htmlFor: "alt" }, "Alt:"), /* @__PURE__ */ React__default.createElement("input", { type: "text", ...register("altText"), className: styles.textInput })),
|
|
62
|
+
/* @__PURE__ */ React__default.createElement("div", { className: styles.formField }, /* @__PURE__ */ React__default.createElement("label", { htmlFor: "title" }, "Title:"), /* @__PURE__ */ React__default.createElement("input", { type: "text", ...register("title"), className: styles.textInput })),
|
|
63
|
+
/* @__PURE__ */ React__default.createElement("div", { style: { display: "flex", justifyContent: "flex-end", gap: "var(--spacing-2)" } }, /* @__PURE__ */ React__default.createElement("button", { type: "submit", title: "Save", "aria-label": "Save", className: classNames(styles.primaryButton) }, "Save"), /* @__PURE__ */ React__default.createElement(Dialog.Close, { asChild: true }, /* @__PURE__ */ React__default.createElement("button", { type: "reset", title: "Cancel", "aria-label": "Cancel", className: classNames(styles.secondaryButton) }, "Cancel")))
|
|
64
|
+
)
|
|
65
|
+
))
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
export {
|
|
69
|
+
ImageDialog
|
|
70
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface ImageEditorProps {
|
|
3
|
+
nodeKey: string;
|
|
4
|
+
src: string;
|
|
5
|
+
alt?: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
width: number | 'inherit';
|
|
8
|
+
height: number | 'inherit';
|
|
9
|
+
}
|
|
10
|
+
export declare function ImageEditor({ src, title, alt, nodeKey, width, height }: ImageEditorProps): JSX.Element | null;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import React__default from "react";
|
|
2
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext.js";
|
|
3
|
+
import { useLexicalNodeSelection } from "@lexical/react/useLexicalNodeSelection.js";
|
|
4
|
+
import { mergeRegister } from "@lexical/utils";
|
|
5
|
+
import classNames from "classnames";
|
|
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 { imagePluginHooks } from "./index.js";
|
|
8
|
+
import styles from "../../styles/ui.module.css.js";
|
|
9
|
+
import { corePluginHooks } from "../core/index.js";
|
|
10
|
+
import { $isImageNode } from "./ImageNode.js";
|
|
11
|
+
import ImageResizer from "./ImageResizer.js";
|
|
12
|
+
const imageCache = /* @__PURE__ */ new Set();
|
|
13
|
+
function useSuspenseImage(src) {
|
|
14
|
+
if (!imageCache.has(src)) {
|
|
15
|
+
throw new Promise((resolve) => {
|
|
16
|
+
const img = new Image();
|
|
17
|
+
img.src = src;
|
|
18
|
+
img.onerror = img.onload = () => {
|
|
19
|
+
imageCache.add(src);
|
|
20
|
+
resolve(null);
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function LazyImage({
|
|
26
|
+
title,
|
|
27
|
+
alt,
|
|
28
|
+
className,
|
|
29
|
+
imageRef,
|
|
30
|
+
src,
|
|
31
|
+
width,
|
|
32
|
+
height
|
|
33
|
+
}) {
|
|
34
|
+
useSuspenseImage(src);
|
|
35
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
36
|
+
"img",
|
|
37
|
+
{
|
|
38
|
+
className: className || void 0,
|
|
39
|
+
alt,
|
|
40
|
+
src,
|
|
41
|
+
title,
|
|
42
|
+
ref: imageRef,
|
|
43
|
+
draggable: "false",
|
|
44
|
+
width,
|
|
45
|
+
height
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
function ImageEditor({ src, title, alt, nodeKey, width, height }) {
|
|
50
|
+
const imageRef = React__default.useRef(null);
|
|
51
|
+
const buttonRef = React__default.useRef(null);
|
|
52
|
+
const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
|
|
53
|
+
const [editor] = useLexicalComposerContext();
|
|
54
|
+
const [selection, setSelection] = React__default.useState(null);
|
|
55
|
+
const activeEditorRef = React__default.useRef(null);
|
|
56
|
+
const [isResizing, setIsResizing] = React__default.useState(false);
|
|
57
|
+
const [disableImageResize] = imagePluginHooks.useEmitterValues("disableImageResize");
|
|
58
|
+
const [imagePreviewHandler] = imagePluginHooks.useEmitterValues("imagePreviewHandler");
|
|
59
|
+
const [imageSource, setImageSource] = React__default.useState(null);
|
|
60
|
+
const openEditImageDialog = imagePluginHooks.usePublisher("openEditImageDialog");
|
|
61
|
+
const [iconComponentFor] = corePluginHooks.useEmitterValues("iconComponentFor");
|
|
62
|
+
const onDelete = React__default.useCallback(
|
|
63
|
+
(payload) => {
|
|
64
|
+
if (isSelected && $isNodeSelection($getSelection())) {
|
|
65
|
+
const event = payload;
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
const node = $getNodeByKey(nodeKey);
|
|
68
|
+
if ($isImageNode(node)) {
|
|
69
|
+
node.remove();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
},
|
|
74
|
+
[isSelected, nodeKey]
|
|
75
|
+
);
|
|
76
|
+
const onEnter = React__default.useCallback(
|
|
77
|
+
(event) => {
|
|
78
|
+
const latestSelection = $getSelection();
|
|
79
|
+
const buttonElem = buttonRef.current;
|
|
80
|
+
if (isSelected && $isNodeSelection(latestSelection) && latestSelection.getNodes().length === 1) {
|
|
81
|
+
if (buttonElem !== null && buttonElem !== document.activeElement) {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
buttonElem.focus();
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
},
|
|
89
|
+
[isSelected]
|
|
90
|
+
);
|
|
91
|
+
const onEscape = React__default.useCallback(
|
|
92
|
+
(event) => {
|
|
93
|
+
if (buttonRef.current === event.target) {
|
|
94
|
+
$setSelection(null);
|
|
95
|
+
editor.update(() => {
|
|
96
|
+
setSelected(true);
|
|
97
|
+
const parentRootElement = editor.getRootElement();
|
|
98
|
+
if (parentRootElement !== null) {
|
|
99
|
+
parentRootElement.focus();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
},
|
|
106
|
+
[editor, setSelected]
|
|
107
|
+
);
|
|
108
|
+
React__default.useEffect(() => {
|
|
109
|
+
if (imagePreviewHandler) {
|
|
110
|
+
const callPreviewHandler = async () => {
|
|
111
|
+
const updatedSrc = await imagePreviewHandler(src);
|
|
112
|
+
setImageSource(updatedSrc);
|
|
113
|
+
};
|
|
114
|
+
callPreviewHandler().catch(console.error);
|
|
115
|
+
} else {
|
|
116
|
+
setImageSource(src);
|
|
117
|
+
}
|
|
118
|
+
}, [src, imagePreviewHandler]);
|
|
119
|
+
React__default.useEffect(() => {
|
|
120
|
+
let isMounted = true;
|
|
121
|
+
const unregister = mergeRegister(
|
|
122
|
+
editor.registerUpdateListener(({ editorState }) => {
|
|
123
|
+
if (isMounted) {
|
|
124
|
+
setSelection(editorState.read(() => $getSelection()));
|
|
125
|
+
}
|
|
126
|
+
}),
|
|
127
|
+
editor.registerCommand(
|
|
128
|
+
SELECTION_CHANGE_COMMAND,
|
|
129
|
+
(_, activeEditor) => {
|
|
130
|
+
activeEditorRef.current = activeEditor;
|
|
131
|
+
return false;
|
|
132
|
+
},
|
|
133
|
+
COMMAND_PRIORITY_LOW
|
|
134
|
+
),
|
|
135
|
+
editor.registerCommand(
|
|
136
|
+
CLICK_COMMAND,
|
|
137
|
+
(payload) => {
|
|
138
|
+
const event = payload;
|
|
139
|
+
if (isResizing) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
if (event.target === imageRef.current) {
|
|
143
|
+
if (event.shiftKey) {
|
|
144
|
+
setSelected(!isSelected);
|
|
145
|
+
} else {
|
|
146
|
+
clearSelection();
|
|
147
|
+
setSelected(true);
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
},
|
|
153
|
+
COMMAND_PRIORITY_LOW
|
|
154
|
+
),
|
|
155
|
+
editor.registerCommand(
|
|
156
|
+
DRAGSTART_COMMAND,
|
|
157
|
+
(event) => {
|
|
158
|
+
if (event.target === imageRef.current) {
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
},
|
|
164
|
+
COMMAND_PRIORITY_LOW
|
|
165
|
+
),
|
|
166
|
+
editor.registerCommand(KEY_DELETE_COMMAND, onDelete, COMMAND_PRIORITY_LOW),
|
|
167
|
+
editor.registerCommand(KEY_BACKSPACE_COMMAND, onDelete, COMMAND_PRIORITY_LOW),
|
|
168
|
+
editor.registerCommand(KEY_ENTER_COMMAND, onEnter, COMMAND_PRIORITY_LOW),
|
|
169
|
+
editor.registerCommand(KEY_ESCAPE_COMMAND, onEscape, COMMAND_PRIORITY_LOW)
|
|
170
|
+
);
|
|
171
|
+
return () => {
|
|
172
|
+
isMounted = false;
|
|
173
|
+
unregister();
|
|
174
|
+
};
|
|
175
|
+
}, [clearSelection, editor, isResizing, isSelected, nodeKey, onDelete, onEnter, onEscape, setSelected]);
|
|
176
|
+
const onResizeEnd = (nextWidth, nextHeight) => {
|
|
177
|
+
setTimeout(() => {
|
|
178
|
+
setIsResizing(false);
|
|
179
|
+
}, 200);
|
|
180
|
+
editor.update(() => {
|
|
181
|
+
const node = $getNodeByKey(nodeKey);
|
|
182
|
+
if ($isImageNode(node)) {
|
|
183
|
+
node.setWidthAndHeight(nextWidth, nextHeight);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
const onResizeStart = () => {
|
|
188
|
+
setIsResizing(true);
|
|
189
|
+
};
|
|
190
|
+
const draggable = $isNodeSelection(selection);
|
|
191
|
+
const isFocused = isSelected;
|
|
192
|
+
return imageSource !== null ? /* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: null }, /* @__PURE__ */ React__default.createElement("div", { className: styles.imageWrapper, "data-editor-block-type": "image" }, /* @__PURE__ */ React__default.createElement("div", { draggable }, /* @__PURE__ */ React__default.createElement(
|
|
193
|
+
LazyImage,
|
|
194
|
+
{
|
|
195
|
+
width,
|
|
196
|
+
height,
|
|
197
|
+
className: classNames({
|
|
198
|
+
[styles.focusedImage]: isFocused
|
|
199
|
+
}),
|
|
200
|
+
src: imageSource,
|
|
201
|
+
title: title || "",
|
|
202
|
+
alt: alt || "",
|
|
203
|
+
imageRef
|
|
204
|
+
}
|
|
205
|
+
)), draggable && isFocused && !disableImageResize && /* @__PURE__ */ React__default.createElement(ImageResizer, { editor, imageRef, onResizeStart, onResizeEnd }), /* @__PURE__ */ React__default.createElement(
|
|
206
|
+
"button",
|
|
207
|
+
{
|
|
208
|
+
type: "button",
|
|
209
|
+
className: classNames(styles.iconButton, styles.editImageButton),
|
|
210
|
+
title: "Edit image",
|
|
211
|
+
onClick: () => {
|
|
212
|
+
openEditImageDialog({
|
|
213
|
+
nodeKey,
|
|
214
|
+
initialValues: {
|
|
215
|
+
src: imageSource,
|
|
216
|
+
title: title || "",
|
|
217
|
+
altText: alt || ""
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
iconComponentFor("settings")
|
|
223
|
+
))) : null;
|
|
224
|
+
}
|
|
225
|
+
export {
|
|
226
|
+
ImageEditor
|
|
227
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { DOMConversionMap, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
|
|
3
|
+
import { DecoratorNode } from 'lexical';
|
|
4
|
+
/**
|
|
5
|
+
* A serialized representation of an {@link ImageNode}.
|
|
6
|
+
*/
|
|
7
|
+
export type SerializedImageNode = Spread<{
|
|
8
|
+
altText: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
width?: number;
|
|
11
|
+
height?: number;
|
|
12
|
+
src: string;
|
|
13
|
+
type: 'image';
|
|
14
|
+
version: 1;
|
|
15
|
+
}, SerializedLexicalNode>;
|
|
16
|
+
/**
|
|
17
|
+
* A lexical node that represents an image. Use {@link "$createImageNode"} to construct one.
|
|
18
|
+
*/
|
|
19
|
+
export declare class ImageNode extends DecoratorNode<JSX.Element> {
|
|
20
|
+
__src: string;
|
|
21
|
+
__altText: string;
|
|
22
|
+
__title: string | undefined;
|
|
23
|
+
__width: 'inherit' | number;
|
|
24
|
+
__height: 'inherit' | number;
|
|
25
|
+
static getType(): string;
|
|
26
|
+
static clone(node: ImageNode): ImageNode;
|
|
27
|
+
static importJSON(serializedNode: SerializedImageNode): ImageNode;
|
|
28
|
+
exportDOM(): DOMExportOutput;
|
|
29
|
+
static importDOM(): DOMConversionMap | null;
|
|
30
|
+
constructor(src: string, altText: string, title: string | undefined, width?: 'inherit' | number, height?: 'inherit' | number, key?: NodeKey);
|
|
31
|
+
exportJSON(): SerializedImageNode;
|
|
32
|
+
setWidthAndHeight(width: 'inherit' | number, height: 'inherit' | number): void;
|
|
33
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
34
|
+
updateDOM(): false;
|
|
35
|
+
getSrc(): string;
|
|
36
|
+
getAltText(): string;
|
|
37
|
+
getTitle(): string | undefined;
|
|
38
|
+
getHeight(): 'inherit' | number;
|
|
39
|
+
getWidth(): 'inherit' | number;
|
|
40
|
+
hasExplicitDimensions(): boolean;
|
|
41
|
+
setTitle(title: string | undefined): void;
|
|
42
|
+
setSrc(src: string): void;
|
|
43
|
+
setAltText(altText: string | undefined): void;
|
|
44
|
+
decorate(_parentEditor: LexicalEditor): JSX.Element;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The payload to create an {@link ImageNode}.
|
|
48
|
+
*/
|
|
49
|
+
export interface CreateImageNodeOptions {
|
|
50
|
+
altText: string;
|
|
51
|
+
width?: number;
|
|
52
|
+
height?: number;
|
|
53
|
+
title?: string;
|
|
54
|
+
key?: NodeKey;
|
|
55
|
+
src: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Creates an {@link ImageNode}.
|
|
59
|
+
* @param options - The payload to create an image. The keys map to the img tag attributes.
|
|
60
|
+
*/
|
|
61
|
+
export declare function $createImageNode(options: CreateImageNodeOptions): ImageNode;
|
|
62
|
+
/**
|
|
63
|
+
* Retruns true if the node is an {@link ImageNode}.
|
|
64
|
+
*/
|
|
65
|
+
export declare function $isImageNode(node: LexicalNode | null | undefined): node is ImageNode;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import React__default from "react";
|
|
8
|
+
import { DecoratorNode } from "lexical";
|
|
9
|
+
import { ImageEditor } from "./ImageEditor.js";
|
|
10
|
+
function convertImageElement(domNode) {
|
|
11
|
+
if (domNode instanceof HTMLImageElement) {
|
|
12
|
+
const { alt: altText, src, title, width, height } = domNode;
|
|
13
|
+
const node = $createImageNode({ altText, src, title, width, height });
|
|
14
|
+
return { node };
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
class ImageNode extends DecoratorNode {
|
|
19
|
+
constructor(src, altText, title, width, height, key) {
|
|
20
|
+
super(key);
|
|
21
|
+
__publicField(this, "__src");
|
|
22
|
+
__publicField(this, "__altText");
|
|
23
|
+
__publicField(this, "__title");
|
|
24
|
+
__publicField(this, "__width");
|
|
25
|
+
__publicField(this, "__height");
|
|
26
|
+
this.__src = src;
|
|
27
|
+
this.__title = title;
|
|
28
|
+
this.__altText = altText;
|
|
29
|
+
this.__width = width || "inherit";
|
|
30
|
+
this.__height = height || "inherit";
|
|
31
|
+
}
|
|
32
|
+
static getType() {
|
|
33
|
+
return "image";
|
|
34
|
+
}
|
|
35
|
+
static clone(node) {
|
|
36
|
+
return new ImageNode(node.__src, node.__altText, node.__title, node.__width, node.__height, node.__key);
|
|
37
|
+
}
|
|
38
|
+
static importJSON(serializedNode) {
|
|
39
|
+
const { altText, title, src, width, height } = serializedNode;
|
|
40
|
+
const node = $createImageNode({
|
|
41
|
+
altText,
|
|
42
|
+
title,
|
|
43
|
+
src,
|
|
44
|
+
height,
|
|
45
|
+
width
|
|
46
|
+
});
|
|
47
|
+
return node;
|
|
48
|
+
}
|
|
49
|
+
exportDOM() {
|
|
50
|
+
const element = document.createElement("img");
|
|
51
|
+
element.setAttribute("src", this.__src);
|
|
52
|
+
element.setAttribute("alt", this.__altText);
|
|
53
|
+
if (this.__title) {
|
|
54
|
+
element.setAttribute("title", this.__title);
|
|
55
|
+
}
|
|
56
|
+
if (this.__width) {
|
|
57
|
+
element.setAttribute("width", this.__width.toString());
|
|
58
|
+
}
|
|
59
|
+
if (this.__height) {
|
|
60
|
+
element.setAttribute("height", this.__height.toString());
|
|
61
|
+
}
|
|
62
|
+
return { element };
|
|
63
|
+
}
|
|
64
|
+
static importDOM() {
|
|
65
|
+
return {
|
|
66
|
+
img: () => ({
|
|
67
|
+
conversion: convertImageElement,
|
|
68
|
+
priority: 0
|
|
69
|
+
})
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
exportJSON() {
|
|
73
|
+
return {
|
|
74
|
+
altText: this.getAltText(),
|
|
75
|
+
title: this.getTitle(),
|
|
76
|
+
height: this.__height === "inherit" ? 0 : this.__height,
|
|
77
|
+
width: this.__width === "inherit" ? 0 : this.__width,
|
|
78
|
+
src: this.getSrc(),
|
|
79
|
+
type: "image",
|
|
80
|
+
version: 1
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
setWidthAndHeight(width, height) {
|
|
84
|
+
const writable = this.getWritable();
|
|
85
|
+
writable.__width = width;
|
|
86
|
+
writable.__height = height;
|
|
87
|
+
}
|
|
88
|
+
createDOM(config) {
|
|
89
|
+
const span = document.createElement("span");
|
|
90
|
+
const theme = config.theme;
|
|
91
|
+
const className = theme.image;
|
|
92
|
+
if (className !== void 0) {
|
|
93
|
+
span.className = className;
|
|
94
|
+
}
|
|
95
|
+
return span;
|
|
96
|
+
}
|
|
97
|
+
updateDOM() {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
getSrc() {
|
|
101
|
+
return this.__src;
|
|
102
|
+
}
|
|
103
|
+
getAltText() {
|
|
104
|
+
return this.__altText;
|
|
105
|
+
}
|
|
106
|
+
getTitle() {
|
|
107
|
+
return this.__title;
|
|
108
|
+
}
|
|
109
|
+
getHeight() {
|
|
110
|
+
return this.__height;
|
|
111
|
+
}
|
|
112
|
+
getWidth() {
|
|
113
|
+
return this.__width;
|
|
114
|
+
}
|
|
115
|
+
hasExplicitDimensions() {
|
|
116
|
+
return this.__width !== "inherit" || this.__height !== "inherit";
|
|
117
|
+
}
|
|
118
|
+
setTitle(title) {
|
|
119
|
+
this.getWritable().__title = title;
|
|
120
|
+
}
|
|
121
|
+
setSrc(src) {
|
|
122
|
+
this.getWritable().__src = src;
|
|
123
|
+
}
|
|
124
|
+
setAltText(altText) {
|
|
125
|
+
this.getWritable().__altText = altText ?? "";
|
|
126
|
+
}
|
|
127
|
+
decorate(_parentEditor) {
|
|
128
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
129
|
+
ImageEditor,
|
|
130
|
+
{
|
|
131
|
+
src: this.getSrc(),
|
|
132
|
+
title: this.getTitle(),
|
|
133
|
+
nodeKey: this.getKey(),
|
|
134
|
+
width: this.__width,
|
|
135
|
+
height: this.__height,
|
|
136
|
+
alt: this.__altText
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function $createImageNode(options) {
|
|
142
|
+
const { altText, title, src, key, width, height } = options;
|
|
143
|
+
return new ImageNode(src, altText, title, width, height, key);
|
|
144
|
+
}
|
|
145
|
+
function $isImageNode(node) {
|
|
146
|
+
return node instanceof ImageNode;
|
|
147
|
+
}
|
|
148
|
+
export {
|
|
149
|
+
$createImageNode,
|
|
150
|
+
$isImageNode,
|
|
151
|
+
ImageNode
|
|
152
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
/// <reference types="react" />
|
|
9
|
+
import type { LexicalEditor } from 'lexical';
|
|
10
|
+
export default function ImageResizer({ onResizeStart, onResizeEnd, imageRef, maxWidth, editor }: {
|
|
11
|
+
editor: LexicalEditor;
|
|
12
|
+
imageRef: {
|
|
13
|
+
current: null | HTMLElement;
|
|
14
|
+
};
|
|
15
|
+
maxWidth?: number;
|
|
16
|
+
onResizeEnd: (width: 'inherit' | number, height: 'inherit' | number) => void;
|
|
17
|
+
onResizeStart: () => void;
|
|
18
|
+
}): JSX.Element;
|