@mdxeditor/editor 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +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 -1105
- package/dist/index.js +140 -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 +617 -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 +800 -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 +544 -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 +603 -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 +523 -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 +118 -0
- package/dist/plugins/headings/index.js +20 -0
- package/dist/plugins/image/ImageEditor.d.ts +9 -0
- package/dist/{ImageEditor-3725ebef.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 +557 -0
- package/dist/plugins/image/index.js +246 -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 +599 -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 +68 -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 +508 -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 +533 -0
- package/dist/plugins/lists/index.js +111 -0
- package/dist/plugins/markdown-shortcut/index.d.ts +63 -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 +361 -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 +839 -0
- package/dist/plugins/sandpack/index.js +93 -0
- package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
- package/dist/{useCodeMirrorRef-0def7994.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 +523 -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 +523 -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 +428 -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 +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 +246 -14
- package/dist/CodeBlockEditor-6488d3ea.cjs +0 -1
- package/dist/CodeBlockEditor-884743e8.js +0 -79
- package/dist/FrontmatterEditor-435d0430.js +0 -118
- package/dist/FrontmatterEditor-95b69d31.cjs +0 -1
- package/dist/ImageEditor-43997418.cjs +0 -1
- package/dist/JsxEditor-1b8aa6c6.cjs +0 -1
- package/dist/JsxEditor-b2e4afc2.js +0 -108
- package/dist/LeafDirectiveEditor-792cbb83.js +0 -59
- package/dist/LeafDirectiveEditor-c0daefa4.cjs +0 -1
- package/dist/SandpackEditor-56a51f80.js +0 -100
- package/dist/SandpackEditor-a09311db.cjs +0 -1
- package/dist/SourceEditor-1fc83319.cjs +0 -1
- package/dist/SourceEditor-32f2b4d8.js +0 -64
- package/dist/TableEditor-616848bc.cjs +0 -1
- package/dist/TableEditor-777ac58a.js +0 -426
- package/dist/index-51585eed.cjs +0 -1
- package/dist/index-d34aa66b.js +0 -4361
- package/dist/index.cjs +0 -1
- package/dist/useCodeMirrorRef-8f68c999.cjs +0 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React__default from "react";
|
|
2
|
+
import { coreSystem } from "../core/index.js";
|
|
3
|
+
import { codeBlockSystem } from "../codeblock/index.js";
|
|
4
|
+
import { SandpackEditor } from "./SandpackEditor.js";
|
|
5
|
+
import { system } from "../../gurx/realmFactory.js";
|
|
6
|
+
import { realmPlugin } from "../../gurx/react.js";
|
|
7
|
+
const defaultSnippetContent = `
|
|
8
|
+
export default function App() {
|
|
9
|
+
return (
|
|
10
|
+
<div className="App">
|
|
11
|
+
<h1>Hello CodeSandbox</h1>
|
|
12
|
+
<h2>Start editing to see some magic happen!</h2>
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
const defaultSandpackConfig = {
|
|
18
|
+
defaultPreset: "react",
|
|
19
|
+
presets: [
|
|
20
|
+
{
|
|
21
|
+
name: "react",
|
|
22
|
+
meta: "live react",
|
|
23
|
+
label: "React",
|
|
24
|
+
sandpackTemplate: "react",
|
|
25
|
+
sandpackTheme: "light",
|
|
26
|
+
snippetFileName: "/App.js",
|
|
27
|
+
snippetLanguage: "jsx",
|
|
28
|
+
initialSnippetContent: defaultSnippetContent
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
const sandpackSystem = system(
|
|
33
|
+
(r, [, { insertCodeBlock }]) => {
|
|
34
|
+
const sandpackConfig = r.node(defaultSandpackConfig);
|
|
35
|
+
const insertSandpack = r.node();
|
|
36
|
+
r.link(
|
|
37
|
+
r.pipe(
|
|
38
|
+
insertSandpack,
|
|
39
|
+
r.o.withLatestFrom(sandpackConfig),
|
|
40
|
+
r.o.map(([presetName, sandpackConfig2]) => {
|
|
41
|
+
const preset = presetName ? sandpackConfig2.presets.find((preset2) => preset2.name === presetName) : sandpackConfig2.presets.find((preset2) => preset2.name == sandpackConfig2.defaultPreset);
|
|
42
|
+
if (!preset) {
|
|
43
|
+
throw new Error(`No sandpack preset found with name ${presetName}`);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
code: preset.initialSnippetContent || "",
|
|
47
|
+
language: preset.snippetLanguage || "jsx",
|
|
48
|
+
meta: preset.meta
|
|
49
|
+
};
|
|
50
|
+
})
|
|
51
|
+
),
|
|
52
|
+
insertCodeBlock
|
|
53
|
+
);
|
|
54
|
+
return {
|
|
55
|
+
insertSandpack,
|
|
56
|
+
sandpackConfig
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
[coreSystem, codeBlockSystem]
|
|
60
|
+
);
|
|
61
|
+
const [
|
|
62
|
+
/** @internal */
|
|
63
|
+
sandpackPlugin,
|
|
64
|
+
/** @internal */
|
|
65
|
+
sandpackPluginHooks
|
|
66
|
+
] = realmPlugin({
|
|
67
|
+
id: "sandpack",
|
|
68
|
+
systemSpec: sandpackSystem,
|
|
69
|
+
applyParamsToSystem(r, params) {
|
|
70
|
+
r.pubKey("sandpackConfig", params.sandpackConfig);
|
|
71
|
+
},
|
|
72
|
+
init(r) {
|
|
73
|
+
r.pubKey("appendCodeBlockEditorDescriptor", {
|
|
74
|
+
match(_language, meta) {
|
|
75
|
+
return meta == null ? void 0 : meta.startsWith("live");
|
|
76
|
+
},
|
|
77
|
+
priority: 1,
|
|
78
|
+
Editor(props) {
|
|
79
|
+
const [config] = sandpackPluginHooks.useEmitterValues("sandpackConfig");
|
|
80
|
+
const preset = config.presets.find((preset2) => preset2.meta === props.meta);
|
|
81
|
+
if (!preset) {
|
|
82
|
+
throw new Error(`No sandpack preset found with ${props.meta}`);
|
|
83
|
+
}
|
|
84
|
+
return /* @__PURE__ */ React__default.createElement(SandpackEditor, { ...props, preset });
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
export {
|
|
90
|
+
sandpackPlugin,
|
|
91
|
+
sandpackPluginHooks,
|
|
92
|
+
sandpackSystem
|
|
93
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CodeMirrorRef } from '@codesandbox/sandpack-react/dist/components/CodeEditor/CodeMirror';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { VoidEmitter } from '../../utils/voidEmitter';
|
|
4
|
+
export declare function useCodeMirrorRef(nodeKey: string, editorType: 'codeblock' | 'sandpack', language: string, focusEmitter: VoidEmitter): React.RefObject<CodeMirrorRef>;
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { $getNodeByKey, $createParagraphNode } from "lexical";
|
|
2
2
|
import React__default from "react";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
3
|
+
import { useCodeBlockEditorContext } from "../codeblock/CodeBlockNode.js";
|
|
4
|
+
import { corePluginHooks } from "../core/index.js";
|
|
5
|
+
function useCodeMirrorRef(nodeKey, editorType, language, focusEmitter) {
|
|
6
|
+
const [theEditor] = corePluginHooks.useEmitterValues("activeEditor");
|
|
7
|
+
const setEditorInFocus = corePluginHooks.usePublisher("editorInFocus");
|
|
7
8
|
const codeMirrorRef = React__default.useRef(null);
|
|
9
|
+
const { lexicalNode } = useCodeBlockEditorContext();
|
|
8
10
|
const atBottom = React__default.useRef(false);
|
|
9
11
|
const atTop = React__default.useRef(false);
|
|
10
12
|
const onFocusHandler = React__default.useCallback(() => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
setEditorInFocus({
|
|
14
|
+
editorType,
|
|
15
|
+
rootNode: lexicalNode
|
|
16
|
+
});
|
|
17
|
+
}, [editorType, lexicalNode, setEditorInFocus]);
|
|
13
18
|
const onKeyDownHandler = React__default.useCallback(
|
|
14
19
|
(e) => {
|
|
15
20
|
var _a, _b, _c, _d;
|
|
@@ -22,7 +27,7 @@ function useCodeMirrorRef(nodeKey, editorType, language) {
|
|
|
22
27
|
if (!atBottom.current) {
|
|
23
28
|
atBottom.current = true;
|
|
24
29
|
} else {
|
|
25
|
-
|
|
30
|
+
theEditor == null ? void 0 : theEditor.update(() => {
|
|
26
31
|
var _a2, _b2;
|
|
27
32
|
const node = $getNodeByKey(nodeKey);
|
|
28
33
|
const nextSibling = node.getNextSibling();
|
|
@@ -45,7 +50,7 @@ function useCodeMirrorRef(nodeKey, editorType, language) {
|
|
|
45
50
|
if (!atTop.current) {
|
|
46
51
|
atTop.current = true;
|
|
47
52
|
} else {
|
|
48
|
-
|
|
53
|
+
theEditor == null ? void 0 : theEditor.update(() => {
|
|
49
54
|
var _a2, _b2;
|
|
50
55
|
const node = $getNodeByKey(nodeKey);
|
|
51
56
|
const previousSibling = node.getPreviousSibling();
|
|
@@ -62,7 +67,7 @@ function useCodeMirrorRef(nodeKey, editorType, language) {
|
|
|
62
67
|
e.stopPropagation();
|
|
63
68
|
}
|
|
64
69
|
},
|
|
65
|
-
[
|
|
70
|
+
[theEditor, nodeKey]
|
|
66
71
|
);
|
|
67
72
|
React__default.useEffect(() => {
|
|
68
73
|
const codeMirror = codeMirrorRef.current;
|
|
@@ -77,8 +82,15 @@ function useCodeMirrorRef(nodeKey, editorType, language) {
|
|
|
77
82
|
(_b = codeMirror == null ? void 0 : codeMirror.getCodemirror()) == null ? void 0 : _b.contentDOM.removeEventListener("keydown", onKeyDownHandler);
|
|
78
83
|
};
|
|
79
84
|
}, [codeMirrorRef, onFocusHandler, onKeyDownHandler, language]);
|
|
85
|
+
React__default.useEffect(() => {
|
|
86
|
+
focusEmitter.subscribe(() => {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
(_b = (_a = codeMirrorRef == null ? void 0 : codeMirrorRef.current) == null ? void 0 : _a.getCodemirror()) == null ? void 0 : _b.focus();
|
|
89
|
+
onFocusHandler();
|
|
90
|
+
});
|
|
91
|
+
}, [focusEmitter, codeMirrorRef, nodeKey, onFocusHandler]);
|
|
80
92
|
return codeMirrorRef;
|
|
81
93
|
}
|
|
82
94
|
export {
|
|
83
|
-
useCodeMirrorRef
|
|
95
|
+
useCodeMirrorRef
|
|
84
96
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { $isTableNode } from "./TableNode.js";
|
|
2
|
+
const LexicalTableVisitor = {
|
|
3
|
+
testLexicalNode: $isTableNode,
|
|
4
|
+
visitLexicalNode({ actions, mdastParent, lexicalNode }) {
|
|
5
|
+
actions.appendToParent(mdastParent, lexicalNode.getMdastNode());
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
LexicalTableVisitor
|
|
10
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LexicalEditor } from 'lexical';
|
|
2
|
+
import * as Mdast from 'mdast';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { TableNode } from './TableNode';
|
|
5
|
+
export interface TableEditorProps {
|
|
6
|
+
parentEditor: LexicalEditor;
|
|
7
|
+
lexicalTable: TableNode;
|
|
8
|
+
mdastNode: Mdast.Table;
|
|
9
|
+
}
|
|
10
|
+
export declare const TableEditor: React.FC<TableEditorProps>;
|
|
11
|
+
export interface CellProps {
|
|
12
|
+
parentEditor: LexicalEditor;
|
|
13
|
+
lexicalTable: TableNode;
|
|
14
|
+
contents: Mdast.PhrasingContent[];
|
|
15
|
+
colIndex: number;
|
|
16
|
+
rowIndex: number;
|
|
17
|
+
align?: Mdast.AlignType;
|
|
18
|
+
activeCell: [number, number] | null;
|
|
19
|
+
setActiveCell: (cell: [number, number] | null) => void;
|
|
20
|
+
focus: boolean;
|
|
21
|
+
}
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
2
|
+
import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
|
|
3
|
+
import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
|
|
4
|
+
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
5
|
+
import * as RadixPopover from "@radix-ui/react-popover";
|
|
6
|
+
import { $createParagraphNode, createEditor, $getRoot, KEY_TAB_COMMAND, COMMAND_PRIORITY_CRITICAL, FOCUS_COMMAND, COMMAND_PRIORITY_LOW, KEY_ENTER_COMMAND, BLUR_COMMAND } from "lexical";
|
|
7
|
+
import React__default from "react";
|
|
8
|
+
import { lexicalTheme } from "../../styles/lexicalTheme.js";
|
|
9
|
+
import { exportLexicalTreeToMdast } from "../../exportMarkdownFromLexical.js";
|
|
10
|
+
import { importMdastTreeToLexical } from "../../importMarkdownToLexical.js";
|
|
11
|
+
import AddColumnIcon from "../../icons/add_column.svg.js";
|
|
12
|
+
import AddRowIcon from "../../icons/add_row.svg.js";
|
|
13
|
+
import DeleteSmallIcon from "../../icons/delete_small.svg.js";
|
|
14
|
+
import AlignCenterIcon from "../../icons/format_align_center.svg.js";
|
|
15
|
+
import AlignLeftIcon from "../../icons/format_align_left.svg.js";
|
|
16
|
+
import AlignRightIcon from "../../icons/format_align_right.svg.js";
|
|
17
|
+
import InsertColLeftIcon from "../../icons/insert_col_left.svg.js";
|
|
18
|
+
import InsertColRightIcon from "../../icons/insert_col_right.svg.js";
|
|
19
|
+
import InsertRowAboveIcon from "../../icons/insert_row_above.svg.js";
|
|
20
|
+
import InsertRowBelowIcon from "../../icons/insert_row_below.svg.js";
|
|
21
|
+
import MoreHorizIcon from "../../icons/more_horiz.svg.js";
|
|
22
|
+
import * as RadixToolbar from "@radix-ui/react-toolbar";
|
|
23
|
+
import classNames from "classnames";
|
|
24
|
+
import styles from "../../styles/ui.module.css.js";
|
|
25
|
+
import { corePluginHooks } from "../core/index.js";
|
|
26
|
+
import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
|
|
27
|
+
import { mergeRegister } from "@lexical/utils";
|
|
28
|
+
import { isPartOftheEditorUI } from "../../utils/isPartOftheEditorUI.js";
|
|
29
|
+
const AlignToTailwindClassMap = {
|
|
30
|
+
center: styles.centeredCell,
|
|
31
|
+
left: styles.leftAlignedCell,
|
|
32
|
+
right: styles.rightAlignedCell
|
|
33
|
+
};
|
|
34
|
+
const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
|
|
35
|
+
const [activeCell, setActiveCell] = React__default.useState(null);
|
|
36
|
+
const setActiveCellWithBoundaries = React__default.useCallback(
|
|
37
|
+
(cell) => {
|
|
38
|
+
const colCount = lexicalTable.getColCount();
|
|
39
|
+
if (cell === null) {
|
|
40
|
+
setActiveCell(null);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
let [colIndex, rowIndex] = cell;
|
|
44
|
+
if (colIndex > colCount - 1) {
|
|
45
|
+
colIndex = 0;
|
|
46
|
+
rowIndex++;
|
|
47
|
+
}
|
|
48
|
+
if (colIndex < 0) {
|
|
49
|
+
colIndex = colCount - 1;
|
|
50
|
+
rowIndex -= 1;
|
|
51
|
+
}
|
|
52
|
+
if (rowIndex > lexicalTable.getRowCount() - 1) {
|
|
53
|
+
setActiveCell(null);
|
|
54
|
+
parentEditor.update(() => {
|
|
55
|
+
const nextSibling = lexicalTable.getLatest().getNextSibling();
|
|
56
|
+
if (nextSibling) {
|
|
57
|
+
lexicalTable.getLatest().selectNext();
|
|
58
|
+
} else {
|
|
59
|
+
const newParagraph = $createParagraphNode();
|
|
60
|
+
lexicalTable.insertAfter(newParagraph);
|
|
61
|
+
newParagraph.select();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (rowIndex < 0) {
|
|
67
|
+
setActiveCell(null);
|
|
68
|
+
parentEditor.update(() => {
|
|
69
|
+
lexicalTable.getLatest().selectPrevious();
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
setActiveCell([colIndex, rowIndex]);
|
|
74
|
+
},
|
|
75
|
+
[lexicalTable, parentEditor]
|
|
76
|
+
);
|
|
77
|
+
React__default.useEffect(() => {
|
|
78
|
+
lexicalTable.focusEmitter.subscribe(setActiveCellWithBoundaries);
|
|
79
|
+
}, [lexicalTable, setActiveCellWithBoundaries]);
|
|
80
|
+
const addRowToBottom = React__default.useCallback(
|
|
81
|
+
(e) => {
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
parentEditor.update(() => {
|
|
84
|
+
lexicalTable.addRowToBottom();
|
|
85
|
+
setActiveCell([0, lexicalTable.getRowCount()]);
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
[parentEditor, lexicalTable]
|
|
89
|
+
);
|
|
90
|
+
const addColumnToRight = React__default.useCallback(
|
|
91
|
+
(e) => {
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
parentEditor.update(() => {
|
|
94
|
+
lexicalTable.addColumnToRight();
|
|
95
|
+
setActiveCell([lexicalTable.getColCount(), 0]);
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
[parentEditor, lexicalTable]
|
|
99
|
+
);
|
|
100
|
+
const [highlightedCoordinates, setHighlightedCoordinates] = React__default.useState([-1, -1]);
|
|
101
|
+
const onTableMouseOver = React__default.useCallback((e) => {
|
|
102
|
+
let tableCell = e.target;
|
|
103
|
+
while (tableCell && !["TH", "TD"].includes(tableCell.tagName)) {
|
|
104
|
+
if (tableCell === e.currentTarget) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
tableCell = tableCell.parentElement;
|
|
108
|
+
}
|
|
109
|
+
if (tableCell === null) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const tableRow = tableCell.parentElement;
|
|
113
|
+
const tableContainer = tableRow.parentElement;
|
|
114
|
+
const colIndex = tableContainer.tagName === "TFOOT" ? -1 : Array.from(tableRow.children).indexOf(tableCell);
|
|
115
|
+
const rowIndex = tableCell.tagName === "TH" ? -1 : Array.from(tableRow.parentElement.children).indexOf(tableRow);
|
|
116
|
+
setHighlightedCoordinates([colIndex, rowIndex]);
|
|
117
|
+
}, []);
|
|
118
|
+
return /* @__PURE__ */ React__default.createElement("table", { className: styles.tableEditor, onMouseOver: onTableMouseOver, onMouseLeave: () => setHighlightedCoordinates([-1, -1]) }, /* @__PURE__ */ React__default.createElement("colgroup", null, /* @__PURE__ */ React__default.createElement("col", null), Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => {
|
|
119
|
+
const align = mdastNode.align || [];
|
|
120
|
+
const currentColumnAlign = align[colIndex] || "left";
|
|
121
|
+
const className = AlignToTailwindClassMap[currentColumnAlign];
|
|
122
|
+
return /* @__PURE__ */ React__default.createElement("col", { key: colIndex, className });
|
|
123
|
+
}), /* @__PURE__ */ React__default.createElement("col", null)), /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", { className: styles.tableToolsColumn, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(
|
|
124
|
+
"button",
|
|
125
|
+
{
|
|
126
|
+
className: styles.iconButton,
|
|
127
|
+
type: "button",
|
|
128
|
+
title: "Delete table",
|
|
129
|
+
onClick: (e) => {
|
|
130
|
+
e.preventDefault();
|
|
131
|
+
parentEditor.update(() => {
|
|
132
|
+
lexicalTable.selectNext();
|
|
133
|
+
lexicalTable.remove();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
/* @__PURE__ */ React__default.createElement(DeleteSmallIcon, null)
|
|
138
|
+
)), Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => {
|
|
139
|
+
return /* @__PURE__ */ React__default.createElement("th", { key: colIndex, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(
|
|
140
|
+
ColumnEditor,
|
|
141
|
+
{
|
|
142
|
+
...{
|
|
143
|
+
setActiveCellWithBoundaries,
|
|
144
|
+
parentEditor,
|
|
145
|
+
colIndex,
|
|
146
|
+
highlightedCoordinates,
|
|
147
|
+
lexicalTable,
|
|
148
|
+
align: (mdastNode.align || [])[colIndex]
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
));
|
|
152
|
+
}), /* @__PURE__ */ React__default.createElement("th", { className: styles.tableToolsColumn }))), /* @__PURE__ */ React__default.createElement("tbody", null, mdastNode.children.map((row, rowIndex) => {
|
|
153
|
+
return /* @__PURE__ */ React__default.createElement("tr", { key: rowIndex }, /* @__PURE__ */ React__default.createElement("td", { className: styles.toolCell, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(RowEditor, { ...{ setActiveCellWithBoundaries, parentEditor, rowIndex, highlightedCoordinates, lexicalTable } })), row.children.map((mdastCell, colIndex) => {
|
|
154
|
+
var _a;
|
|
155
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
156
|
+
Cell,
|
|
157
|
+
{
|
|
158
|
+
align: (_a = mdastNode.align) == null ? void 0 : _a[colIndex],
|
|
159
|
+
key: colIndex,
|
|
160
|
+
contents: mdastCell.children,
|
|
161
|
+
setActiveCell: setActiveCellWithBoundaries,
|
|
162
|
+
...{
|
|
163
|
+
rowIndex,
|
|
164
|
+
colIndex,
|
|
165
|
+
lexicalTable,
|
|
166
|
+
parentEditor,
|
|
167
|
+
activeCell
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
}), rowIndex === 0 && /* @__PURE__ */ React__default.createElement("th", { rowSpan: lexicalTable.getRowCount(), "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addColumnButton, onClick: addColumnToRight }, /* @__PURE__ */ React__default.createElement(AddColumnIcon, null))));
|
|
172
|
+
})), /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null), /* @__PURE__ */ React__default.createElement("th", { colSpan: lexicalTable.getColCount() }, /* @__PURE__ */ React__default.createElement("button", { type: "button", className: styles.addRowButton, onClick: addRowToBottom }, /* @__PURE__ */ React__default.createElement(AddRowIcon, null))), /* @__PURE__ */ React__default.createElement("th", null))));
|
|
173
|
+
};
|
|
174
|
+
const Cell = ({ align, ...props }) => {
|
|
175
|
+
const { activeCell, setActiveCell } = props;
|
|
176
|
+
const isActive = Boolean(activeCell && activeCell[0] === props.colIndex && activeCell[1] === props.rowIndex);
|
|
177
|
+
const className = AlignToTailwindClassMap[align || "left"];
|
|
178
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
179
|
+
"td",
|
|
180
|
+
{
|
|
181
|
+
className,
|
|
182
|
+
"data-active": isActive,
|
|
183
|
+
onClick: () => {
|
|
184
|
+
setActiveCell([props.colIndex, props.rowIndex]);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
/* @__PURE__ */ React__default.createElement(CellEditor, { ...props, focus: isActive })
|
|
188
|
+
);
|
|
189
|
+
};
|
|
190
|
+
const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents, colIndex, rowIndex }) => {
|
|
191
|
+
const [importVisitors, exportVisitors, usedLexicalNodes, jsxComponentDescriptors, jsxIsAvailable, rootEditor] = corePluginHooks.useEmitterValues(
|
|
192
|
+
"importVisitors",
|
|
193
|
+
"exportVisitors",
|
|
194
|
+
"usedLexicalNodes",
|
|
195
|
+
"jsxComponentDescriptors",
|
|
196
|
+
"jsxIsAvailable",
|
|
197
|
+
"rootEditor"
|
|
198
|
+
);
|
|
199
|
+
const [editor] = React__default.useState(() => {
|
|
200
|
+
const editor2 = createEditor({
|
|
201
|
+
nodes: usedLexicalNodes,
|
|
202
|
+
theme: lexicalTheme
|
|
203
|
+
});
|
|
204
|
+
editor2.update(() => {
|
|
205
|
+
importMdastTreeToLexical({
|
|
206
|
+
root: $getRoot(),
|
|
207
|
+
mdastRoot: { type: "root", children: [{ type: "paragraph", children: contents }] },
|
|
208
|
+
visitors: importVisitors
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
return editor2;
|
|
212
|
+
});
|
|
213
|
+
const saveAndFocus = React__default.useCallback(
|
|
214
|
+
(nextCell) => {
|
|
215
|
+
editor.getEditorState().read(() => {
|
|
216
|
+
const mdast = exportLexicalTreeToMdast({
|
|
217
|
+
root: $getRoot(),
|
|
218
|
+
jsxComponentDescriptors,
|
|
219
|
+
visitors: exportVisitors,
|
|
220
|
+
jsxIsAvailable
|
|
221
|
+
});
|
|
222
|
+
parentEditor.update(() => {
|
|
223
|
+
lexicalTable.updateCellContents(colIndex, rowIndex, mdast.children[0].children);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
setActiveCell(nextCell);
|
|
227
|
+
},
|
|
228
|
+
[colIndex, editor, exportVisitors, jsxComponentDescriptors, jsxIsAvailable, lexicalTable, parentEditor, rowIndex, setActiveCell]
|
|
229
|
+
);
|
|
230
|
+
React__default.useEffect(() => {
|
|
231
|
+
return mergeRegister(
|
|
232
|
+
editor.registerCommand(
|
|
233
|
+
KEY_TAB_COMMAND,
|
|
234
|
+
(payload) => {
|
|
235
|
+
payload.preventDefault();
|
|
236
|
+
const nextCell = payload.shiftKey ? [colIndex - 1, rowIndex] : [colIndex + 1, rowIndex];
|
|
237
|
+
saveAndFocus(nextCell);
|
|
238
|
+
return true;
|
|
239
|
+
},
|
|
240
|
+
COMMAND_PRIORITY_CRITICAL
|
|
241
|
+
),
|
|
242
|
+
editor.registerCommand(
|
|
243
|
+
FOCUS_COMMAND,
|
|
244
|
+
() => {
|
|
245
|
+
setActiveCell([colIndex, rowIndex]);
|
|
246
|
+
return false;
|
|
247
|
+
},
|
|
248
|
+
COMMAND_PRIORITY_LOW
|
|
249
|
+
),
|
|
250
|
+
editor.registerCommand(
|
|
251
|
+
KEY_ENTER_COMMAND,
|
|
252
|
+
(payload) => {
|
|
253
|
+
payload == null ? void 0 : payload.preventDefault();
|
|
254
|
+
const nextCell = (payload == null ? void 0 : payload.shiftKey) ? [colIndex, rowIndex - 1] : [colIndex, rowIndex + 1];
|
|
255
|
+
saveAndFocus(nextCell);
|
|
256
|
+
return true;
|
|
257
|
+
},
|
|
258
|
+
COMMAND_PRIORITY_CRITICAL
|
|
259
|
+
),
|
|
260
|
+
editor.registerCommand(
|
|
261
|
+
BLUR_COMMAND,
|
|
262
|
+
(payload) => {
|
|
263
|
+
const relatedTarget = payload.relatedTarget;
|
|
264
|
+
if (isPartOftheEditorUI(relatedTarget, rootEditor.getRootElement())) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
saveAndFocus(null);
|
|
268
|
+
return true;
|
|
269
|
+
},
|
|
270
|
+
COMMAND_PRIORITY_CRITICAL
|
|
271
|
+
)
|
|
272
|
+
);
|
|
273
|
+
}, [colIndex, editor, rootEditor, rowIndex, saveAndFocus, setActiveCell]);
|
|
274
|
+
React__default.useEffect(() => {
|
|
275
|
+
focus && (editor == null ? void 0 : editor.focus());
|
|
276
|
+
}, [focus, editor]);
|
|
277
|
+
return /* @__PURE__ */ React__default.createElement(LexicalNestedComposer, { initialEditor: editor }, /* @__PURE__ */ React__default.createElement(RichTextPlugin, { contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, null), placeholder: /* @__PURE__ */ React__default.createElement("div", null), ErrorBoundary: LexicalErrorBoundary }), /* @__PURE__ */ React__default.createElement(HistoryPlugin, null));
|
|
278
|
+
};
|
|
279
|
+
const ColumnEditor = ({
|
|
280
|
+
parentEditor,
|
|
281
|
+
highlightedCoordinates,
|
|
282
|
+
align,
|
|
283
|
+
lexicalTable,
|
|
284
|
+
colIndex,
|
|
285
|
+
setActiveCellWithBoundaries
|
|
286
|
+
}) => {
|
|
287
|
+
const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
|
|
288
|
+
const insertColumnAt = React__default.useCallback(
|
|
289
|
+
(colIndex2) => {
|
|
290
|
+
parentEditor.update(() => {
|
|
291
|
+
lexicalTable.insertColumnAt(colIndex2);
|
|
292
|
+
});
|
|
293
|
+
setActiveCellWithBoundaries([colIndex2, 0]);
|
|
294
|
+
},
|
|
295
|
+
[parentEditor, lexicalTable, setActiveCellWithBoundaries]
|
|
296
|
+
);
|
|
297
|
+
const deleteColumnAt = React__default.useCallback(
|
|
298
|
+
(colIndex2) => {
|
|
299
|
+
parentEditor.update(() => {
|
|
300
|
+
lexicalTable.deleteColumnAt(colIndex2);
|
|
301
|
+
});
|
|
302
|
+
},
|
|
303
|
+
[parentEditor, lexicalTable]
|
|
304
|
+
);
|
|
305
|
+
const setColumnAlign = React__default.useCallback(
|
|
306
|
+
(colIndex2, align2) => {
|
|
307
|
+
parentEditor.update(() => {
|
|
308
|
+
lexicalTable.setColumnAlign(colIndex2, align2);
|
|
309
|
+
});
|
|
310
|
+
},
|
|
311
|
+
[parentEditor, lexicalTable]
|
|
312
|
+
);
|
|
313
|
+
return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, null, /* @__PURE__ */ React__default.createElement(
|
|
314
|
+
RadixPopover.PopoverTrigger,
|
|
315
|
+
{
|
|
316
|
+
className: styles.tableColumnEditorTrigger,
|
|
317
|
+
"data-active": highlightedCoordinates[0] === colIndex + 1,
|
|
318
|
+
title: "Column menu"
|
|
319
|
+
},
|
|
320
|
+
/* @__PURE__ */ React__default.createElement(MoreHorizIcon, null)
|
|
321
|
+
), /* @__PURE__ */ React__default.createElement(RadixPopover.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(
|
|
322
|
+
RadixPopover.PopoverContent,
|
|
323
|
+
{
|
|
324
|
+
className: classNames(styles.tableColumnEditorPopoverContent),
|
|
325
|
+
onOpenAutoFocus: (e) => e.preventDefault(),
|
|
326
|
+
sideOffset: 5,
|
|
327
|
+
side: "top"
|
|
328
|
+
},
|
|
329
|
+
/* @__PURE__ */ React__default.createElement(RadixToolbar.Root, { className: styles.tableColumnEditorToolbar }, /* @__PURE__ */ React__default.createElement(
|
|
330
|
+
RadixToolbar.ToggleGroup,
|
|
331
|
+
{
|
|
332
|
+
className: styles.toggleGroupRoot,
|
|
333
|
+
onValueChange: (value) => {
|
|
334
|
+
setColumnAlign(colIndex, value);
|
|
335
|
+
},
|
|
336
|
+
value: align || "left",
|
|
337
|
+
type: "single",
|
|
338
|
+
"aria-label": "Text alignment"
|
|
339
|
+
},
|
|
340
|
+
/* @__PURE__ */ React__default.createElement(RadixToolbar.ToggleItem, { value: "left", title: "Align left" }, /* @__PURE__ */ React__default.createElement(AlignLeftIcon, null)),
|
|
341
|
+
/* @__PURE__ */ React__default.createElement(RadixToolbar.ToggleItem, { value: "center", title: "Align center" }, /* @__PURE__ */ React__default.createElement(AlignCenterIcon, null)),
|
|
342
|
+
/* @__PURE__ */ React__default.createElement(RadixToolbar.ToggleItem, { value: "right", title: "Align right" }, /* @__PURE__ */ React__default.createElement(AlignRightIcon, null))
|
|
343
|
+
), /* @__PURE__ */ React__default.createElement(RadixToolbar.Separator, null), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: insertColumnAt.bind(null, colIndex), title: "Insert a column to the left of this one" }, /* @__PURE__ */ React__default.createElement(InsertColLeftIcon, null)), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: insertColumnAt.bind(null, colIndex + 1), title: "Insert a column to the right of this one" }, /* @__PURE__ */ React__default.createElement(InsertColRightIcon, null)), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: deleteColumnAt.bind(null, colIndex), title: "Delete this column" }, /* @__PURE__ */ React__default.createElement(DeleteSmallIcon, null)))
|
|
344
|
+
)));
|
|
345
|
+
};
|
|
346
|
+
const RowEditor = ({
|
|
347
|
+
parentEditor,
|
|
348
|
+
highlightedCoordinates,
|
|
349
|
+
lexicalTable,
|
|
350
|
+
rowIndex,
|
|
351
|
+
setActiveCellWithBoundaries
|
|
352
|
+
}) => {
|
|
353
|
+
const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
|
|
354
|
+
const insertRowAt = React__default.useCallback(
|
|
355
|
+
(rowIndex2) => {
|
|
356
|
+
parentEditor.update(() => {
|
|
357
|
+
lexicalTable.insertRowAt(rowIndex2);
|
|
358
|
+
});
|
|
359
|
+
setActiveCellWithBoundaries([0, rowIndex2]);
|
|
360
|
+
},
|
|
361
|
+
[parentEditor, lexicalTable, setActiveCellWithBoundaries]
|
|
362
|
+
);
|
|
363
|
+
const deleteRowAt = React__default.useCallback(
|
|
364
|
+
(rowIndex2) => {
|
|
365
|
+
parentEditor.update(() => {
|
|
366
|
+
lexicalTable.deleteRowAt(rowIndex2);
|
|
367
|
+
});
|
|
368
|
+
},
|
|
369
|
+
[parentEditor, lexicalTable]
|
|
370
|
+
);
|
|
371
|
+
return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, null, /* @__PURE__ */ React__default.createElement(RadixPopover.PopoverTrigger, { className: styles.tableColumnEditorTrigger, "data-active": highlightedCoordinates[1] === rowIndex }, /* @__PURE__ */ React__default.createElement(MoreHorizIcon, null)), /* @__PURE__ */ React__default.createElement(RadixPopover.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(
|
|
372
|
+
RadixPopover.PopoverContent,
|
|
373
|
+
{
|
|
374
|
+
className: classNames(styles.tableColumnEditorPopoverContent),
|
|
375
|
+
onOpenAutoFocus: (e) => e.preventDefault(),
|
|
376
|
+
sideOffset: 5,
|
|
377
|
+
side: "bottom"
|
|
378
|
+
},
|
|
379
|
+
/* @__PURE__ */ React__default.createElement(RadixToolbar.Root, { className: styles.tableColumnEditorToolbar }, /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: insertRowAt.bind(null, rowIndex), title: "Insert a row above this one" }, /* @__PURE__ */ React__default.createElement(InsertRowAboveIcon, null)), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: insertRowAt.bind(null, rowIndex + 1), title: "Insert a row below this one" }, /* @__PURE__ */ React__default.createElement(InsertRowBelowIcon, null)), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: deleteRowAt.bind(null, rowIndex), title: "Delete this row" }, /* @__PURE__ */ React__default.createElement(DeleteSmallIcon, null)))
|
|
380
|
+
)));
|
|
381
|
+
};
|
|
382
|
+
export {
|
|
383
|
+
TableEditor
|
|
384
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { DecoratorNode, LexicalEditor, LexicalNode, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
|
|
3
|
+
import * as Mdast from 'mdast';
|
|
4
|
+
/**
|
|
5
|
+
* A serialized representation of a {@link TableNode}.
|
|
6
|
+
*/
|
|
7
|
+
export type SerializedTableNode = Spread<{
|
|
8
|
+
mdastNode: Mdast.Table;
|
|
9
|
+
}, SerializedLexicalNode>;
|
|
10
|
+
type CoordinatesSubscription = (coords: [colIndex: number, rowIndex: number]) => void;
|
|
11
|
+
/**
|
|
12
|
+
* A lexical node that represents a table, with features specific to the markdown tables.
|
|
13
|
+
* Use {@link "$createTableNode"} to construct one.
|
|
14
|
+
*/
|
|
15
|
+
export declare class TableNode extends DecoratorNode<JSX.Element> {
|
|
16
|
+
__mdastNode: Mdast.Table;
|
|
17
|
+
focusEmitter: {
|
|
18
|
+
publish: (coords: [colIndex: number, rowIndex: number]) => void;
|
|
19
|
+
subscribe: (cb: CoordinatesSubscription) => void;
|
|
20
|
+
};
|
|
21
|
+
static getType(): string;
|
|
22
|
+
static clone(node: TableNode): TableNode;
|
|
23
|
+
static importJSON(serializedNode: SerializedTableNode): TableNode;
|
|
24
|
+
exportJSON(): SerializedTableNode;
|
|
25
|
+
getMdastNode(): Mdast.Table;
|
|
26
|
+
getRowCount(): number;
|
|
27
|
+
getColCount(): number;
|
|
28
|
+
constructor(mdastNode?: Mdast.Table, key?: NodeKey);
|
|
29
|
+
createDOM(): HTMLElement;
|
|
30
|
+
updateDOM(): false;
|
|
31
|
+
updateCellContents(colIndex: number, rowIndex: number, children: Mdast.PhrasingContent[]): void;
|
|
32
|
+
insertColumnAt(colIndex: number): void;
|
|
33
|
+
deleteColumnAt(colIndex: number): void;
|
|
34
|
+
insertRowAt(y: number): void;
|
|
35
|
+
deleteRowAt(rowIndex: number): void;
|
|
36
|
+
addRowToBottom(): void;
|
|
37
|
+
addColumnToRight(): void;
|
|
38
|
+
setColumnAlign(colIndex: number, align: Mdast.AlignType): void;
|
|
39
|
+
decorate(parentEditor: LexicalEditor): JSX.Element;
|
|
40
|
+
select(coords?: [colIndex: number, rowIndex: number]): void;
|
|
41
|
+
isInline(): false;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Retruns true if the given node is a {@link TableNode}.
|
|
45
|
+
*/
|
|
46
|
+
export declare function $isTableNode(node: LexicalNode | null | undefined): node is TableNode;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a {@link TableNode}
|
|
49
|
+
* @param mdastNode - The mdast node to create the {@link TableNode} from.
|
|
50
|
+
*/
|
|
51
|
+
export declare function $createTableNode(mdastNode: Mdast.Table): TableNode;
|
|
52
|
+
export {};
|