@mdxeditor/editor 0.8.0 → 0.10.0-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 +2 -2
- package/dist/FormatConstants.d.ts +9 -0
- package/dist/FormatConstants.js +10 -0
- package/dist/MDXEditor.d.ts +31 -0
- package/dist/MDXEditor.js +105 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +4 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +29 -0
- package/dist/directive-editors/GenericDirectiveEditor.d.ts +3 -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 +112 -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 +28 -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 +49 -973
- package/dist/index.js +133 -66
- package/dist/jsx-editors/GenericJsxEditor.d.ts +3 -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 +604 -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 +786 -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 +69 -0
- package/dist/plugins/core/NestedLexicalEditor.js +181 -0
- package/dist/plugins/core/PropertyPopover.d.ts +8 -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 +419 -0
- package/dist/plugins/core/index.js +343 -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 +25 -0
- package/dist/plugins/diff-source/index.d.ts +530 -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 +591 -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 +510 -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 +105 -0
- package/dist/plugins/headings/index.js +20 -0
- package/dist/plugins/image/ImageEditor.d.ts +7 -0
- package/dist/{ImageEditor-5f203a1c.js → plugins/image/ImageEditor.js} +12 -46
- package/dist/plugins/image/ImageNode.d.ts +53 -0
- package/dist/plugins/image/ImageNode.js +108 -0
- package/dist/plugins/image/LexicalImageVisitor.d.ts +4 -0
- package/dist/plugins/image/LexicalImageVisitor.js +15 -0
- package/dist/plugins/image/MdastImageVisitor.d.ts +3 -0
- package/dist/plugins/image/MdastImageVisitor.js +16 -0
- package/dist/plugins/image/index.d.ts +541 -0
- package/dist/plugins/image/index.js +244 -0
- package/dist/plugins/jsx/LexicalJsxNode.d.ts +54 -0
- package/dist/plugins/jsx/LexicalJsxNode.js +99 -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 +461 -0
- package/dist/plugins/jsx/index.js +37 -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 +108 -0
- package/dist/plugins/link/index.js +24 -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 +496 -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 +14 -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 +521 -0
- package/dist/plugins/lists/index.js +111 -0
- package/dist/plugins/markdown-shortcut/index.d.ts +51 -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 +14 -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 +348 -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 +826 -0
- package/dist/plugins/sandpack/index.js +93 -0
- package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
- package/dist/{useCodeMirrorRef-ff0c2781.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/{TableEditor-bb94be2b.js → plugins/table/TableEditor.js} +109 -161
- package/dist/plugins/table/TableNode.d.ts +52 -0
- package/dist/plugins/table/TableNode.js +147 -0
- package/dist/plugins/table/index.d.ts +511 -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 +510 -0
- package/dist/plugins/thematic-break/index.js +39 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +2 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.js +52 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +2 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +35 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +2 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +30 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +2 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +32 -0
- package/dist/plugins/toolbar/components/CodeToggle.d.ts +2 -0
- package/dist/plugins/toolbar/components/CodeToggle.js +20 -0
- package/dist/plugins/toolbar/components/CreateLink.d.ts +2 -0
- package/dist/plugins/toolbar/components/CreateLink.js +11 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +4 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +27 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +2 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.js +29 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +2 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.js +20 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +2 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.js +11 -0
- package/dist/plugins/toolbar/components/InsertImage.d.ts +2 -0
- package/dist/plugins/toolbar/components/InsertImage.js +23 -0
- package/dist/plugins/toolbar/components/InsertSandpack.d.ts +2 -0
- package/dist/plugins/toolbar/components/InsertSandpack.js +13 -0
- package/dist/plugins/toolbar/components/InsertTable.d.ts +2 -0
- package/dist/plugins/toolbar/components/InsertTable.js +20 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +2 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.js +11 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +2 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +58 -0
- package/dist/plugins/toolbar/components/ListsToggle.d.ts +2 -0
- package/dist/plugins/toolbar/components/ListsToggle.js +23 -0
- package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +2 -0
- package/dist/plugins/toolbar/components/ShowSandpackInfo.js +32 -0
- package/dist/plugins/toolbar/components/UndoRedo.d.ts +2 -0
- package/dist/plugins/toolbar/components/UndoRedo.js +59 -0
- package/dist/plugins/toolbar/index.d.ts +416 -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 +5 -0
- package/dist/plugins/toolbar/primitives/TooltipWrap.js +12 -0
- package/dist/plugins/toolbar/primitives/select.d.ts +31 -0
- package/dist/plugins/toolbar/primitives/select.js +44 -0
- package/dist/plugins/toolbar/primitives/toolbar.d.ts +85 -0
- package/dist/plugins/toolbar/primitives/toolbar.js +111 -0
- package/dist/style.css +480 -240
- 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 +227 -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 +10 -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 +184 -14
- package/dist/CodeBlockEditor-59b65408.js +0 -78
- package/dist/CodeBlockEditor-5ae8b0a9.cjs +0 -1
- package/dist/FrontmatterEditor-2b27f5a7.js +0 -117
- package/dist/FrontmatterEditor-74ad4eb7.cjs +0 -1
- package/dist/ImageEditor-e5fd6b26.cjs +0 -1
- package/dist/JsxEditor-95724372.cjs +0 -1
- package/dist/JsxEditor-f061cc75.js +0 -108
- package/dist/SandpackEditor-37261889.cjs +0 -1
- package/dist/SandpackEditor-ce901c3c.js +0 -98
- package/dist/SourceEditor-6135bf63.cjs +0 -1
- package/dist/SourceEditor-e499b8bb.js +0 -63
- package/dist/TableEditor-4d00f956.cjs +0 -1
- package/dist/index-383c60bb.cjs +0 -1
- package/dist/index-470693d8.js +0 -4095
- package/dist/index.cjs +0 -1
- package/dist/useCodeMirrorRef-72d8430b.cjs +0 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { coreSystem } from "../core/index.js";
|
|
2
|
+
import { codeBlockSystem } from "../codeblock/index.js";
|
|
3
|
+
import { CodeMirrorEditor } from "./CodeMirrorEditor.js";
|
|
4
|
+
import { system } from "../../gurx/realmFactory.js";
|
|
5
|
+
import { realmPlugin } from "../../gurx/react.js";
|
|
6
|
+
const defaultCodeBlockLanguages = {
|
|
7
|
+
js: "JavaScript",
|
|
8
|
+
ts: "TypeScript",
|
|
9
|
+
tsx: "TypeScript (React)",
|
|
10
|
+
jsx: "JavaScript (React)",
|
|
11
|
+
css: "CSS"
|
|
12
|
+
};
|
|
13
|
+
const codeMirrorSystem = system(
|
|
14
|
+
(r, [, { insertCodeBlock }]) => {
|
|
15
|
+
const codeBlockLanguages = r.node(defaultCodeBlockLanguages);
|
|
16
|
+
const insertCodeMirror = r.node();
|
|
17
|
+
r.link(
|
|
18
|
+
r.pipe(
|
|
19
|
+
insertCodeMirror,
|
|
20
|
+
r.o.map(({ language, code }) => {
|
|
21
|
+
return {
|
|
22
|
+
code,
|
|
23
|
+
language,
|
|
24
|
+
meta: ""
|
|
25
|
+
};
|
|
26
|
+
})
|
|
27
|
+
),
|
|
28
|
+
insertCodeBlock
|
|
29
|
+
);
|
|
30
|
+
return {
|
|
31
|
+
codeBlockLanguages,
|
|
32
|
+
insertCodeMirror
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
[coreSystem, codeBlockSystem]
|
|
36
|
+
);
|
|
37
|
+
const [
|
|
38
|
+
/** @internal */
|
|
39
|
+
codeMirrorPlugin,
|
|
40
|
+
/** @internal */
|
|
41
|
+
codeMirrorHooks
|
|
42
|
+
] = realmPlugin({
|
|
43
|
+
id: "codemirror",
|
|
44
|
+
systemSpec: codeMirrorSystem,
|
|
45
|
+
applyParamsToSystem(r, params) {
|
|
46
|
+
r.pubKey("codeBlockLanguages", params.codeBlockLanguages);
|
|
47
|
+
},
|
|
48
|
+
init(r, { codeBlockLanguages }) {
|
|
49
|
+
r.pubKey("appendCodeBlockEditorDescriptor", {
|
|
50
|
+
match(language, meta) {
|
|
51
|
+
return codeBlockLanguages.hasOwnProperty(language) && meta === "";
|
|
52
|
+
},
|
|
53
|
+
priority: 1,
|
|
54
|
+
Editor: CodeMirrorEditor
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
export {
|
|
59
|
+
codeMirrorHooks,
|
|
60
|
+
codeMirrorPlugin,
|
|
61
|
+
codeMirrorSystem
|
|
62
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { $isLineBreakNode } from "lexical";
|
|
2
|
+
const LexicalLinebreakVisitor = {
|
|
3
|
+
testLexicalNode: $isLineBreakNode,
|
|
4
|
+
visitLexicalNode: ({ mdastParent, actions }) => {
|
|
5
|
+
actions.appendToParent(mdastParent, { type: "text", value: "\n" });
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
LexicalLinebreakVisitor
|
|
10
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TextNode } from 'lexical';
|
|
2
|
+
import * as Mdast from 'mdast';
|
|
3
|
+
import { LexicalExportVisitor } from '../../exportMarkdownFromLexical';
|
|
4
|
+
export declare function isMdastText(mdastNode: Mdast.Content): mdastNode is Mdast.Text;
|
|
5
|
+
export declare const LexicalTextVisitor: LexicalExportVisitor<TextNode, Mdast.Text>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { $isTextNode } from "lexical";
|
|
2
|
+
import { IS_CODE, IS_ITALIC, IS_BOLD, IS_UNDERLINE } from "../../FormatConstants.js";
|
|
3
|
+
function isMdastText(mdastNode) {
|
|
4
|
+
return mdastNode.type === "text";
|
|
5
|
+
}
|
|
6
|
+
const LexicalTextVisitor = {
|
|
7
|
+
shouldJoin: (prevNode, currentNode) => {
|
|
8
|
+
return ["text", "emphasis", "strong", "mdxJsxTextElement"].includes(prevNode.type) && prevNode.type === currentNode.type;
|
|
9
|
+
},
|
|
10
|
+
join(prevNode, currentNode) {
|
|
11
|
+
if (isMdastText(prevNode) && isMdastText(currentNode)) {
|
|
12
|
+
return {
|
|
13
|
+
type: "text",
|
|
14
|
+
value: prevNode.value + currentNode.value
|
|
15
|
+
};
|
|
16
|
+
} else {
|
|
17
|
+
return {
|
|
18
|
+
...prevNode,
|
|
19
|
+
children: [...prevNode.children, ...currentNode.children]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
testLexicalNode: $isTextNode,
|
|
24
|
+
visitLexicalNode: ({ lexicalNode, mdastParent, actions }) => {
|
|
25
|
+
const previousSibling = lexicalNode.getPreviousSibling();
|
|
26
|
+
const prevFormat = $isTextNode(previousSibling) ? previousSibling.getFormat() : 0;
|
|
27
|
+
const textContent = lexicalNode.getTextContent();
|
|
28
|
+
const format = lexicalNode.getFormat() ?? 0;
|
|
29
|
+
if (format & IS_CODE) {
|
|
30
|
+
actions.addAndStepInto("inlineCode", {
|
|
31
|
+
value: textContent
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
let localParentNode = mdastParent;
|
|
36
|
+
if (prevFormat & format & IS_ITALIC) {
|
|
37
|
+
localParentNode = actions.appendToParent(localParentNode, {
|
|
38
|
+
type: "emphasis",
|
|
39
|
+
children: []
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (prevFormat & format & IS_BOLD) {
|
|
43
|
+
localParentNode = actions.appendToParent(localParentNode, {
|
|
44
|
+
type: "strong",
|
|
45
|
+
children: []
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (prevFormat & format & IS_UNDERLINE) {
|
|
49
|
+
localParentNode = actions.appendToParent(localParentNode, {
|
|
50
|
+
type: "mdxJsxTextElement",
|
|
51
|
+
name: "u",
|
|
52
|
+
children: [],
|
|
53
|
+
attributes: []
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (format & IS_ITALIC && !(prevFormat & IS_ITALIC)) {
|
|
57
|
+
localParentNode = actions.appendToParent(localParentNode, {
|
|
58
|
+
type: "emphasis",
|
|
59
|
+
children: []
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (format & IS_BOLD && !(prevFormat & IS_BOLD)) {
|
|
63
|
+
localParentNode = actions.appendToParent(localParentNode, {
|
|
64
|
+
type: "strong",
|
|
65
|
+
children: []
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (format & IS_UNDERLINE && !(prevFormat & IS_UNDERLINE)) {
|
|
69
|
+
localParentNode = actions.appendToParent(localParentNode, {
|
|
70
|
+
type: "mdxJsxTextElement",
|
|
71
|
+
name: "u",
|
|
72
|
+
children: [],
|
|
73
|
+
attributes: []
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
actions.appendToParent(localParentNode, {
|
|
77
|
+
type: "text",
|
|
78
|
+
value: textContent
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
export {
|
|
83
|
+
LexicalTextVisitor,
|
|
84
|
+
isMdastText
|
|
85
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IS_UNDERLINE, IS_ITALIC, IS_BOLD } from "../../FormatConstants.js";
|
|
2
|
+
function isOpeningUnderlineNode(node) {
|
|
3
|
+
return node.type === "html" && node.value === "<u>";
|
|
4
|
+
}
|
|
5
|
+
function isClosingUnderlineNode(node) {
|
|
6
|
+
return node.type === "html" && node.value === "</u>";
|
|
7
|
+
}
|
|
8
|
+
function isJsxUnderlineNode(node) {
|
|
9
|
+
return node.type === "mdxJsxTextElement" && node.name === "u";
|
|
10
|
+
}
|
|
11
|
+
const MdastFormattingVisitor = {
|
|
12
|
+
testNode(mdastNode) {
|
|
13
|
+
return mdastNode.type === "emphasis" || mdastNode.type === "strong" || isJsxUnderlineNode(mdastNode) || isOpeningUnderlineNode(mdastNode) || isClosingUnderlineNode(mdastNode);
|
|
14
|
+
},
|
|
15
|
+
visitNode({ mdastNode, lexicalParent, actions, mdastParent }) {
|
|
16
|
+
if (isOpeningUnderlineNode(mdastNode)) {
|
|
17
|
+
actions.addFormatting(IS_UNDERLINE, mdastParent);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (isClosingUnderlineNode(mdastNode)) {
|
|
21
|
+
actions.removeFormatting(IS_UNDERLINE, mdastParent);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (mdastNode.type === "emphasis") {
|
|
25
|
+
actions.addFormatting(IS_ITALIC);
|
|
26
|
+
} else if (mdastNode.type === "strong") {
|
|
27
|
+
actions.addFormatting(IS_BOLD);
|
|
28
|
+
} else if (isJsxUnderlineNode(mdastNode)) {
|
|
29
|
+
actions.addFormatting(IS_UNDERLINE);
|
|
30
|
+
}
|
|
31
|
+
actions.visitChildren(mdastNode, lexicalParent);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
MdastFormattingVisitor
|
|
36
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { $createTextNode } from "lexical";
|
|
2
|
+
import { IS_CODE } from "../../FormatConstants.js";
|
|
3
|
+
const MdastInlineCodeVisitor = {
|
|
4
|
+
testNode: "inlineCode",
|
|
5
|
+
visitNode({ mdastNode, actions }) {
|
|
6
|
+
actions.addAndStepInto($createTextNode(mdastNode.value).setFormat(IS_CODE));
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
MdastInlineCodeVisitor
|
|
11
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { $createParagraphNode } from "lexical";
|
|
2
|
+
const lexicalTypesThatShouldSkipParagraphs = ["listitem", "quote", "admonition"];
|
|
3
|
+
const MdastParagraphVisitor = {
|
|
4
|
+
testNode: "paragraph",
|
|
5
|
+
visitNode: function({ mdastNode, lexicalParent, actions }) {
|
|
6
|
+
if (lexicalTypesThatShouldSkipParagraphs.includes(lexicalParent.getType())) {
|
|
7
|
+
actions.visitChildren(mdastNode, lexicalParent);
|
|
8
|
+
} else {
|
|
9
|
+
actions.addAndStepInto($createParagraphNode());
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
MdastParagraphVisitor
|
|
15
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { $createTextNode } from "lexical";
|
|
2
|
+
const MdastTextVisitor = {
|
|
3
|
+
testNode: "text",
|
|
4
|
+
visitNode({ mdastNode, actions }) {
|
|
5
|
+
actions.addAndStepInto($createTextNode(mdastNode.value).setFormat(actions.getParentFormatting()));
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
MdastTextVisitor
|
|
10
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { DecoratorNode, EditorConfig, LexicalEditor } from 'lexical';
|
|
2
|
+
import * as Mdast from 'mdast';
|
|
3
|
+
import { Node } from 'unist';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
|
6
|
+
import { VoidEmitter } from '../../utils/voidEmitter';
|
|
7
|
+
interface NestedEditorsContextValue<T extends Node> {
|
|
8
|
+
parentEditor: LexicalEditor;
|
|
9
|
+
config: EditorConfig;
|
|
10
|
+
mdastNode: T;
|
|
11
|
+
lexicalNode: DecoratorNode<any> & {
|
|
12
|
+
setMdastNode: (mdastNode: any) => void;
|
|
13
|
+
};
|
|
14
|
+
focusEmitter: VoidEmitter;
|
|
15
|
+
}
|
|
16
|
+
export declare const NestedEditorsContext: React.Context<NestedEditorsContextValue<Node<import("unist").Data>> | undefined>;
|
|
17
|
+
export declare const useNestedEditorContext: <T extends Mdast.Content>() => NestedEditorsContextValue<T>;
|
|
18
|
+
/**
|
|
19
|
+
* A hook that returns a function that can be used to update the mdast node. Use this in your custom editor components.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useMdastNodeUpdater<T extends Mdast.Content>(): (node: Partial<T>) => void;
|
|
22
|
+
/**
|
|
23
|
+
* A hook that returns a function that removes the lexical node from the editor.
|
|
24
|
+
*/
|
|
25
|
+
export declare function useLexicalNodeRemove(): () => void;
|
|
26
|
+
/**
|
|
27
|
+
* The properties of the {@link NestedEditor} React Component.
|
|
28
|
+
* @typeParam T - The type of the mdast node of the editor.
|
|
29
|
+
*/
|
|
30
|
+
export interface NestedEditorProps<T extends Mdast.Content> {
|
|
31
|
+
/**
|
|
32
|
+
* A function that returns the phrasing content of the mdast node. In most cases, this will be the `children` property of the mdast node, but you can also have multiple nested nodes with their own children.
|
|
33
|
+
*/
|
|
34
|
+
getContent: (mdastNode: T) => Mdast.Content[];
|
|
35
|
+
/**
|
|
36
|
+
* A function that should return the updated mdast node based on the original mdast node and the new content (serialized as mdast tree) produced by the editor.
|
|
37
|
+
*/
|
|
38
|
+
getUpdatedMdastNode: (mdastNode: T, children: Mdast.Content[]) => T;
|
|
39
|
+
/**
|
|
40
|
+
* Props passed to the {@link https://github.com/facebook/lexical/blob/main/packages/lexical-react/src/LexicalContentEditable.tsx | ContentEditable} component.
|
|
41
|
+
*/
|
|
42
|
+
contentEditableProps?: React.ComponentProps<typeof ContentEditable>;
|
|
43
|
+
/**
|
|
44
|
+
* Whether or not the editor edits blocks (multiple paragraphs)
|
|
45
|
+
*/
|
|
46
|
+
block?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* An emitter (usually constructed in the lexical node) that will activate the editor when the node is focused.
|
|
49
|
+
*/
|
|
50
|
+
focusEmitter?: VoidEmitter;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A nested editor React component that allows editing of the contents of complex markdown nodes that have nested markdown content (for example, custom directives or JSX elements). See the {@link NestedEditorProps} for more details on the compoment props.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* You can use a type param to specify the type of the mdast node
|
|
57
|
+
*
|
|
58
|
+
* ```tsx
|
|
59
|
+
*
|
|
60
|
+
* interface CalloutDirectiveNode extends LeafDirective {
|
|
61
|
+
* name: 'callout'
|
|
62
|
+
* children: Mdast.PhrasingContent[]
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* return <NestedEditor<CalloutDirectiveNode> getContent={node => node.children} getUpdatedMdastNode={(node, children) => ({ ...node, children })} />
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare const NestedLexicalEditor: <T extends Mdast.Content>(props: NestedEditorProps<T>) => React.JSX.Element;
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { $addUpdateTag, $getNodeByKey, createEditor, $getRoot, BLUR_COMMAND, COMMAND_PRIORITY_EDITOR, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_HIGH, KEY_BACKSPACE_COMMAND, COMMAND_PRIORITY_CRITICAL } from "lexical";
|
|
2
|
+
import React__default from "react";
|
|
3
|
+
import { corePluginHooks, NESTED_EDITOR_UPDATED_COMMAND } from "./index.js";
|
|
4
|
+
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
5
|
+
import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
|
|
6
|
+
import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
|
|
7
|
+
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
8
|
+
import { lexicalTheme } from "../../styles/lexicalTheme.js";
|
|
9
|
+
import { exportLexicalTreeToMdast } from "../../exportMarkdownFromLexical.js";
|
|
10
|
+
import { importMdastTreeToLexical } from "../../importMarkdownToLexical.js";
|
|
11
|
+
import styles from "../../styles/ui.module.css.js";
|
|
12
|
+
import { SharedHistoryPlugin } from "./SharedHistoryPlugin.js";
|
|
13
|
+
import { mergeRegister } from "@lexical/utils";
|
|
14
|
+
import { isPartOftheEditorUI } from "../../utils/isPartOftheEditorUI.js";
|
|
15
|
+
const NestedEditorsContext = React__default.createContext(void 0);
|
|
16
|
+
const useNestedEditorContext = () => {
|
|
17
|
+
const context = React__default.useContext(NestedEditorsContext);
|
|
18
|
+
if (!context) {
|
|
19
|
+
throw new Error("useNestedEditor must be used within a NestedEditorsProvider");
|
|
20
|
+
}
|
|
21
|
+
return context;
|
|
22
|
+
};
|
|
23
|
+
function useMdastNodeUpdater() {
|
|
24
|
+
const { parentEditor, lexicalNode } = useNestedEditorContext();
|
|
25
|
+
return function updateMdastNode(node) {
|
|
26
|
+
parentEditor.update(() => {
|
|
27
|
+
$addUpdateTag("history-push");
|
|
28
|
+
const currentNode = $getNodeByKey(lexicalNode.getKey());
|
|
29
|
+
if (currentNode) {
|
|
30
|
+
currentNode.setMdastNode(node);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function useLexicalNodeRemove() {
|
|
36
|
+
const { parentEditor, lexicalNode } = useNestedEditorContext();
|
|
37
|
+
return () => {
|
|
38
|
+
parentEditor.update(() => {
|
|
39
|
+
const node = $getNodeByKey(lexicalNode.getKey());
|
|
40
|
+
node.selectNext();
|
|
41
|
+
node.remove();
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const NestedLexicalEditor = function(props) {
|
|
46
|
+
const { getContent, getUpdatedMdastNode, contentEditableProps, block = false } = props;
|
|
47
|
+
const { mdastNode, lexicalNode } = useNestedEditorContext();
|
|
48
|
+
const updateMdastNode = useMdastNodeUpdater();
|
|
49
|
+
const removeNode = useLexicalNodeRemove();
|
|
50
|
+
const content = getContent(mdastNode);
|
|
51
|
+
const [rootEditor] = corePluginHooks.useEmitterValues("rootEditor");
|
|
52
|
+
const [importVisitors, exportVisitors, usedLexicalNodes, jsxComponentDescriptors, jsxIsAvailable, nestedEditorChildren] = corePluginHooks.useEmitterValues(
|
|
53
|
+
"importVisitors",
|
|
54
|
+
"exportVisitors",
|
|
55
|
+
"usedLexicalNodes",
|
|
56
|
+
"jsxComponentDescriptors",
|
|
57
|
+
"jsxIsAvailable",
|
|
58
|
+
"nestedEditorChildren"
|
|
59
|
+
);
|
|
60
|
+
const setEditorInFocus = corePluginHooks.usePublisher("editorInFocus");
|
|
61
|
+
const [editor] = React__default.useState(() => {
|
|
62
|
+
const editor2 = createEditor({
|
|
63
|
+
nodes: usedLexicalNodes,
|
|
64
|
+
theme: lexicalTheme
|
|
65
|
+
});
|
|
66
|
+
return editor2;
|
|
67
|
+
});
|
|
68
|
+
React__default.useEffect(() => {
|
|
69
|
+
var _a;
|
|
70
|
+
(_a = props.focusEmitter) == null ? void 0 : _a.subscribe(() => {
|
|
71
|
+
editor.focus();
|
|
72
|
+
});
|
|
73
|
+
}, [editor, props.focusEmitter]);
|
|
74
|
+
React__default.useEffect(() => {
|
|
75
|
+
editor.update(() => {
|
|
76
|
+
$getRoot().clear();
|
|
77
|
+
let theContent = content;
|
|
78
|
+
if (block) {
|
|
79
|
+
if (theContent.length === 0) {
|
|
80
|
+
theContent = [{ type: "paragraph", children: [] }];
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
theContent = [{ type: "paragraph", children: content }];
|
|
84
|
+
}
|
|
85
|
+
importMdastTreeToLexical({
|
|
86
|
+
root: $getRoot(),
|
|
87
|
+
mdastRoot: {
|
|
88
|
+
type: "root",
|
|
89
|
+
children: theContent
|
|
90
|
+
},
|
|
91
|
+
visitors: importVisitors
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}, [editor, block, importVisitors]);
|
|
95
|
+
React__default.useEffect(() => {
|
|
96
|
+
function updateParentNode() {
|
|
97
|
+
editor.getEditorState().read(() => {
|
|
98
|
+
const mdast = exportLexicalTreeToMdast({
|
|
99
|
+
root: $getRoot(),
|
|
100
|
+
visitors: exportVisitors,
|
|
101
|
+
jsxComponentDescriptors,
|
|
102
|
+
jsxIsAvailable
|
|
103
|
+
});
|
|
104
|
+
const content2 = block ? mdast.children : mdast.children[0].children;
|
|
105
|
+
updateMdastNode(getUpdatedMdastNode(structuredClone(mdastNode), content2));
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return mergeRegister(
|
|
109
|
+
editor.registerCommand(
|
|
110
|
+
BLUR_COMMAND,
|
|
111
|
+
(payload) => {
|
|
112
|
+
const relatedTarget = payload.relatedTarget;
|
|
113
|
+
if (isPartOftheEditorUI(relatedTarget, rootEditor.getRootElement())) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
updateParentNode();
|
|
117
|
+
setEditorInFocus(null);
|
|
118
|
+
return true;
|
|
119
|
+
},
|
|
120
|
+
COMMAND_PRIORITY_EDITOR
|
|
121
|
+
),
|
|
122
|
+
// triggered by codemirror
|
|
123
|
+
editor.registerCommand(
|
|
124
|
+
NESTED_EDITOR_UPDATED_COMMAND,
|
|
125
|
+
() => {
|
|
126
|
+
updateParentNode();
|
|
127
|
+
return true;
|
|
128
|
+
},
|
|
129
|
+
COMMAND_PRIORITY_EDITOR
|
|
130
|
+
),
|
|
131
|
+
editor.registerCommand(
|
|
132
|
+
SELECTION_CHANGE_COMMAND,
|
|
133
|
+
() => {
|
|
134
|
+
setEditorInFocus({ editorType: "lexical", rootNode: lexicalNode });
|
|
135
|
+
return false;
|
|
136
|
+
},
|
|
137
|
+
COMMAND_PRIORITY_HIGH
|
|
138
|
+
),
|
|
139
|
+
editor.registerCommand(
|
|
140
|
+
KEY_BACKSPACE_COMMAND,
|
|
141
|
+
(_, editor2) => {
|
|
142
|
+
const editorElement = editor2.getRootElement();
|
|
143
|
+
if ((editorElement == null ? void 0 : editorElement.innerText) === "\n") {
|
|
144
|
+
removeNode();
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
148
|
+
},
|
|
149
|
+
COMMAND_PRIORITY_CRITICAL
|
|
150
|
+
)
|
|
151
|
+
);
|
|
152
|
+
}, [
|
|
153
|
+
block,
|
|
154
|
+
editor,
|
|
155
|
+
exportVisitors,
|
|
156
|
+
getUpdatedMdastNode,
|
|
157
|
+
jsxComponentDescriptors,
|
|
158
|
+
jsxIsAvailable,
|
|
159
|
+
lexicalNode,
|
|
160
|
+
mdastNode,
|
|
161
|
+
removeNode,
|
|
162
|
+
setEditorInFocus,
|
|
163
|
+
updateMdastNode,
|
|
164
|
+
rootEditor
|
|
165
|
+
]);
|
|
166
|
+
return /* @__PURE__ */ React__default.createElement(LexicalNestedComposer, { initialEditor: editor }, /* @__PURE__ */ React__default.createElement(
|
|
167
|
+
RichTextPlugin,
|
|
168
|
+
{
|
|
169
|
+
contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, { ...contentEditableProps, className: styles.nestedEditor }),
|
|
170
|
+
placeholder: null,
|
|
171
|
+
ErrorBoundary: LexicalErrorBoundary
|
|
172
|
+
}
|
|
173
|
+
), /* @__PURE__ */ React__default.createElement(SharedHistoryPlugin, null), nestedEditorChildren.map((Child, index) => /* @__PURE__ */ React__default.createElement(Child, { key: index })));
|
|
174
|
+
};
|
|
175
|
+
export {
|
|
176
|
+
NestedEditorsContext,
|
|
177
|
+
NestedLexicalEditor,
|
|
178
|
+
useLexicalNodeRemove,
|
|
179
|
+
useMdastNodeUpdater,
|
|
180
|
+
useNestedEditorContext
|
|
181
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as RadixPopover from "@radix-ui/react-popover";
|
|
2
|
+
import React__default from "react";
|
|
3
|
+
import { useForm } from "react-hook-form";
|
|
4
|
+
import SettingsIcon from "../../icons/settings.svg.js";
|
|
5
|
+
import styles from "../../styles/ui.module.css.js";
|
|
6
|
+
import { PopoverPortal, PopoverContent } from "./ui/PopoverUtils.js";
|
|
7
|
+
const PropertyPopover = ({ title, properties, onChange }) => {
|
|
8
|
+
const [open, setOpen] = React__default.useState(false);
|
|
9
|
+
const { register, handleSubmit, reset } = useForm({ defaultValues: properties });
|
|
10
|
+
return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, { open, onOpenChange: (v) => setOpen(v) }, /* @__PURE__ */ React__default.createElement(RadixPopover.Trigger, { className: styles.iconButton }, /* @__PURE__ */ React__default.createElement(SettingsIcon, { style: { display: "block" } })), /* @__PURE__ */ React__default.createElement(PopoverPortal, null, /* @__PURE__ */ React__default.createElement(PopoverContent, null, /* @__PURE__ */ React__default.createElement(
|
|
11
|
+
"form",
|
|
12
|
+
{
|
|
13
|
+
onSubmit: handleSubmit((values) => {
|
|
14
|
+
onChange(values);
|
|
15
|
+
setOpen(false);
|
|
16
|
+
})
|
|
17
|
+
},
|
|
18
|
+
/* @__PURE__ */ React__default.createElement("h3", { className: styles.propertyPanelTitle }, title, " Attributes"),
|
|
19
|
+
/* @__PURE__ */ React__default.createElement("table", { className: styles.propertyEditorTable }, /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", { className: styles.readOnlyColumnCell }, "Attribute"), /* @__PURE__ */ React__default.createElement("th", null, "Value"))), /* @__PURE__ */ React__default.createElement("tbody", null, Object.keys(properties).map((propName) => /* @__PURE__ */ React__default.createElement("tr", { key: propName }, /* @__PURE__ */ React__default.createElement("th", { className: styles.readOnlyColumnCell }, " ", propName, " "), /* @__PURE__ */ React__default.createElement("td", null, /* @__PURE__ */ React__default.createElement("input", { ...register(propName), className: styles.propertyEditorInput }))))), /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("td", { colSpan: 2 }, /* @__PURE__ */ React__default.createElement("div", { className: styles.buttonsFooter }, /* @__PURE__ */ React__default.createElement("button", { type: "submit", className: styles.primaryButton }, "Save"), /* @__PURE__ */ React__default.createElement(
|
|
20
|
+
"button",
|
|
21
|
+
{
|
|
22
|
+
type: "reset",
|
|
23
|
+
className: styles.secondaryButton,
|
|
24
|
+
onClick: (e) => {
|
|
25
|
+
e.preventDefault();
|
|
26
|
+
reset(properties);
|
|
27
|
+
setOpen(false);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"Cancel"
|
|
31
|
+
))))))
|
|
32
|
+
))));
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
PropertyPopover
|
|
36
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
|
|
2
|
+
import React__default from "react";
|
|
3
|
+
import { corePluginHooks } from "./index.js";
|
|
4
|
+
const SharedHistoryPlugin = () => {
|
|
5
|
+
const [historyState] = corePluginHooks.useEmitterValues("historyState");
|
|
6
|
+
return /* @__PURE__ */ React__default.createElement(HistoryPlugin, { externalHistoryState: historyState });
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
SharedHistoryPlugin
|
|
10
|
+
};
|