@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,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
|
+
}
|
|
@@ -2,100 +2,30 @@ import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
|
2
2
|
import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
|
|
3
3
|
import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
|
|
4
4
|
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
5
|
-
import { $createParagraphNode, createEditor, KEY_TAB_COMMAND, COMMAND_PRIORITY_CRITICAL, KEY_ENTER_COMMAND, BLUR_COMMAND, $getRoot } from "lexical";
|
|
6
|
-
import * as React from "react";
|
|
7
|
-
import React__default, { useEffect } from "react";
|
|
8
|
-
import { s as styles, u as useEmitterValues, t as theme, i as importMdastTreeToLexical, S as SharedHistoryPlugin, e as exportLexicalTreeToMdast } from "./index-470693d8.js";
|
|
9
|
-
import { toHast } from "mdast-util-to-hast";
|
|
10
|
-
import { raw } from "hast-util-raw";
|
|
11
|
-
import { sanitize } from "hast-util-sanitize";
|
|
12
|
-
import { toHtml } from "hast-util-to-html";
|
|
13
5
|
import * as RadixPopover from "@radix-ui/react-popover";
|
|
14
|
-
import
|
|
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";
|
|
15
22
|
import * as RadixToolbar from "@radix-ui/react-toolbar";
|
|
16
|
-
import "
|
|
17
|
-
import "
|
|
18
|
-
import "
|
|
19
|
-
import "@lexical/react/
|
|
20
|
-
import "@lexical/
|
|
21
|
-
import "
|
|
22
|
-
import "@lexical/link";
|
|
23
|
-
import "@lexical/list";
|
|
24
|
-
import "@lexical/react/LexicalHorizontalRuleNode";
|
|
25
|
-
import "@lexical/rich-text";
|
|
26
|
-
import "mdast-util-directive";
|
|
27
|
-
import "mdast-util-from-markdown";
|
|
28
|
-
import "mdast-util-frontmatter";
|
|
29
|
-
import "mdast-util-gfm-table";
|
|
30
|
-
import "mdast-util-mdx";
|
|
31
|
-
import "micromark-extension-directive";
|
|
32
|
-
import "micromark-extension-frontmatter";
|
|
33
|
-
import "micromark-extension-gfm-table";
|
|
34
|
-
import "micromark-extension-mdxjs";
|
|
35
|
-
import "@lexical/utils";
|
|
36
|
-
import "@lexical/react/LexicalComposerContext";
|
|
37
|
-
import "@lexical/selection";
|
|
38
|
-
import "@lexical/react/LexicalHistoryPlugin";
|
|
39
|
-
import "mdast-util-to-markdown";
|
|
40
|
-
import "@radix-ui/react-tooltip";
|
|
41
|
-
import "downshift";
|
|
42
|
-
import "@lexical/markdown";
|
|
43
|
-
import "@lexical/react/LexicalMarkdownShortcutPlugin";
|
|
44
|
-
import "react-diff-view";
|
|
45
|
-
import "unidiff";
|
|
46
|
-
import "@radix-ui/react-select";
|
|
47
|
-
import "@radix-ui/react-dialog";
|
|
48
|
-
const MarkdownAstRenderer = (props) => {
|
|
49
|
-
const root = { type: "root", children: props.mdastChildren };
|
|
50
|
-
const hast = raw(toHast(root, { allowDangerousHtml: true }));
|
|
51
|
-
const safeHast = sanitize(hast);
|
|
52
|
-
const html = toHtml(safeHast);
|
|
53
|
-
return /* @__PURE__ */ React__default.createElement("span", { dangerouslySetInnerHTML: { __html: html || " " } });
|
|
54
|
-
};
|
|
55
|
-
const SvgMoreHoriz = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
56
|
-
maskType: "alpha"
|
|
57
|
-
} }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M6 14c-.55 0-1.02-.196-1.412-.588A1.926 1.926 0 0 1 4 12c0-.55.196-1.02.588-1.412A1.926 1.926 0 0 1 6 10c.55 0 1.02.196 1.412.588.392.391.588.862.588 1.412 0 .55-.196 1.02-.588 1.412A1.926 1.926 0 0 1 6 14Zm6 0c-.55 0-1.02-.196-1.412-.588A1.926 1.926 0 0 1 10 12c0-.55.196-1.02.588-1.412A1.926 1.926 0 0 1 12 10c.55 0 1.02.196 1.412.588.392.391.588.862.588 1.412 0 .55-.196 1.02-.588 1.412A1.926 1.926 0 0 1 12 14Zm6 0c-.55 0-1.02-.196-1.413-.588A1.926 1.926 0 0 1 16 12c0-.55.196-1.02.587-1.412A1.926 1.926 0 0 1 18 10c.55 0 1.02.196 1.413.588.391.391.587.862.587 1.412 0 .55-.196 1.02-.587 1.412A1.926 1.926 0 0 1 18 14Z" })));
|
|
58
|
-
const MoreHorizIcon = SvgMoreHoriz;
|
|
59
|
-
const SvgFormatAlignLeft = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
60
|
-
maskType: "alpha"
|
|
61
|
-
} }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M3 17v-1.5h14V17H3Zm0-3.125v-1.5h10v1.5H3Zm0-3.125v-1.5h14v1.5H3Zm0-3.125v-1.5h10v1.5H3ZM3 4.5V3h14v1.5H3Z" })));
|
|
62
|
-
const AlignLeftIcon = SvgFormatAlignLeft;
|
|
63
|
-
const SvgFormatAlignCenter = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
64
|
-
maskType: "alpha"
|
|
65
|
-
} }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M3 17v-1.5h14V17H3Zm3-3.125v-1.5h8v1.5H6ZM3 10.75v-1.5h14v1.5H3Zm3-3.125v-1.5h8v1.5H6ZM3 4.5V3h14v1.5H3Z" })));
|
|
66
|
-
const AlignCenterIcon = SvgFormatAlignCenter;
|
|
67
|
-
const SvgFormatAlignRight = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
68
|
-
maskType: "alpha"
|
|
69
|
-
} }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M3 17v-1.5h14V17H3Zm4-3.125v-1.5h10v1.5H7ZM3 10.75v-1.5h14v1.5H3Zm4-3.125v-1.5h10v1.5H7ZM3 4.5V3h14v1.5H3Z" })));
|
|
70
|
-
const AlignRightIcon = SvgFormatAlignRight;
|
|
71
|
-
const SvgInsertColLeft = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
72
|
-
maskType: "alpha"
|
|
73
|
-
} }, /* @__PURE__ */ React.createElement("path", { d: "M0 20h20v20H0z", transform: "rotate(-90 0 20)" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M15.75 4.5H13v2.75h-1.5V4.5H8.75V3h2.75V.25H13V3h2.75v1.5ZM13 17H5V3h2.25v1.5H6.5v11h5V8.75H13V17Z" })));
|
|
74
|
-
const InsertColLeftIcon = SvgInsertColLeft;
|
|
75
|
-
const SvgInsertColRight = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
76
|
-
maskType: "alpha"
|
|
77
|
-
} }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z", transform: "matrix(0 -1 -1 0 20 20)" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M4.25 4.5H7v2.75h1.5V4.5h2.75V3H8.5V.25H7V3H4.25v1.5ZM7 17h8V3h-2.25v1.5h.75v11h-5V8.75H7V17Z" })));
|
|
78
|
-
const InsertColRightIcon = SvgInsertColRight;
|
|
79
|
-
const SvgDeleteSmall = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
80
|
-
maskType: "alpha"
|
|
81
|
-
} }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M6.5 17a1.45 1.45 0 0 1-1.06-.44A1.445 1.445 0 0 1 5 15.5v-10H4V4h4V3h4v1h4v1.5h-1v9.991c0 .423-.147.78-.44 1.072A1.45 1.45 0 0 1 13.5 17h-7Zm7-11.5h-7v10h7v-10ZM8 14h1.5V7H8v7Zm2.5 0H12V7h-1.5v7Z" })));
|
|
82
|
-
const DeleteSmallIcon = SvgDeleteSmall;
|
|
83
|
-
const SvgInsertRowAbove = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
84
|
-
maskType: "alpha"
|
|
85
|
-
} }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z", transform: "matrix(-1 0 0 1 20 0)" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M4.5 16.75V14h2.75v-1.5H4.5V9.75H3v2.75H.25V14H3v2.75h1.5ZM17 14V6H3v2.25h1.5V7.5h11v5H8.75V14H17Z" })));
|
|
86
|
-
const InsertRowAboveIcon = SvgInsertRowAbove;
|
|
87
|
-
const SvgInsertRowBelow = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
88
|
-
maskType: "alpha"
|
|
89
|
-
} }, /* @__PURE__ */ React.createElement("path", { d: "M20 20h20v20H20z", transform: "rotate(180 20 20)" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M4.5 3.25V6h2.75v1.5H4.5v2.75H3V7.5H.25V6H3V3.25h1.5ZM17 6v8H3v-2.25h1.5v.75h11v-5H8.75V6H17Z" })));
|
|
90
|
-
const InsertRowBelowIcon = SvgInsertRowBelow;
|
|
91
|
-
const SvgAddRow = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
92
|
-
maskType: "alpha"
|
|
93
|
-
} }, /* @__PURE__ */ React.createElement("path", { d: "M20 20h20v20H20z", transform: "rotate(180 20 20)" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M10.5 3.25V6h2.75v1.5H10.5v2.75H9V7.5H6.25V6H9V3.25h1.5ZM17 6v8H3V6h2.5v1.5h-1v5h11v-5H14V6h3Z" })));
|
|
94
|
-
const AddRowIcon = SvgAddRow;
|
|
95
|
-
const SvgAddColumn = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
|
|
96
|
-
maskType: "alpha"
|
|
97
|
-
} }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z", transform: "matrix(0 -1 -1 0 20 20)" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M3.25 10.5H6v2.75h1.5V10.5h2.75V9H7.5V6.25H6V9H3.25v1.5ZM6 17h8V3H6v2.5h1.5v-1h5v11h-5V14H6v3Z" })));
|
|
98
|
-
const AddColumnIcon = SvgAddColumn;
|
|
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";
|
|
99
29
|
const AlignToTailwindClassMap = {
|
|
100
30
|
center: styles.centeredCell,
|
|
101
31
|
left: styles.leftAlignedCell,
|
|
@@ -144,7 +74,7 @@ const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
|
|
|
144
74
|
},
|
|
145
75
|
[lexicalTable, parentEditor]
|
|
146
76
|
);
|
|
147
|
-
useEffect(() => {
|
|
77
|
+
React__default.useEffect(() => {
|
|
148
78
|
lexicalTable.focusEmitter.subscribe(setActiveCellWithBoundaries);
|
|
149
79
|
}, [lexicalTable, setActiveCellWithBoundaries]);
|
|
150
80
|
const addRowToBottom = React__default.useCallback(() => {
|
|
@@ -218,15 +148,22 @@ const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
|
|
|
218
148
|
align: (_a = mdastNode.align) == null ? void 0 : _a[colIndex],
|
|
219
149
|
key: colIndex,
|
|
220
150
|
contents: mdastCell.children,
|
|
221
|
-
|
|
151
|
+
setActiveCell: setActiveCellWithBoundaries,
|
|
152
|
+
...{
|
|
153
|
+
rowIndex,
|
|
154
|
+
colIndex,
|
|
155
|
+
lexicalTable,
|
|
156
|
+
parentEditor,
|
|
157
|
+
activeCell
|
|
158
|
+
}
|
|
222
159
|
}
|
|
223
160
|
);
|
|
224
161
|
}), rowIndex === 0 && /* @__PURE__ */ React__default.createElement("th", { rowSpan: lexicalTable.getRowCount(), "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement("button", { className: styles.addColumnButton, onClick: addColumnToRight }, /* @__PURE__ */ React__default.createElement(AddColumnIcon, null))));
|
|
225
162
|
})), /* @__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", { className: styles.addRowButton, onClick: addRowToBottom }, /* @__PURE__ */ React__default.createElement(AddRowIcon, null))), /* @__PURE__ */ React__default.createElement("th", null))));
|
|
226
163
|
};
|
|
227
164
|
const Cell = ({ align, ...props }) => {
|
|
228
|
-
const
|
|
229
|
-
const isActive = activeCell && activeCell[0] === props.colIndex && activeCell[1] === props.rowIndex;
|
|
165
|
+
const { activeCell, setActiveCell } = props;
|
|
166
|
+
const isActive = Boolean(activeCell && activeCell[0] === props.colIndex && activeCell[1] === props.rowIndex);
|
|
230
167
|
const className = AlignToTailwindClassMap[align || "left"];
|
|
231
168
|
return /* @__PURE__ */ React__default.createElement(
|
|
232
169
|
"td",
|
|
@@ -237,86 +174,97 @@ const Cell = ({ align, ...props }) => {
|
|
|
237
174
|
setActiveCell([props.colIndex, props.rowIndex]);
|
|
238
175
|
}
|
|
239
176
|
},
|
|
240
|
-
|
|
177
|
+
/* @__PURE__ */ React__default.createElement(CellEditor, { ...props, focus: isActive })
|
|
241
178
|
);
|
|
242
179
|
};
|
|
243
|
-
const CellEditor = ({
|
|
244
|
-
const [
|
|
245
|
-
"
|
|
246
|
-
"
|
|
180
|
+
const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents, colIndex, rowIndex }) => {
|
|
181
|
+
const [importVisitors, exportVisitors, usedLexicalNodes, jsxComponentDescriptors, jsxIsAvailable, rootEditor] = corePluginHooks.useEmitterValues(
|
|
182
|
+
"importVisitors",
|
|
183
|
+
"exportVisitors",
|
|
184
|
+
"usedLexicalNodes",
|
|
247
185
|
"jsxComponentDescriptors",
|
|
248
|
-
"
|
|
186
|
+
"jsxIsAvailable",
|
|
187
|
+
"rootEditor"
|
|
249
188
|
);
|
|
250
189
|
const [editor] = React__default.useState(() => {
|
|
251
|
-
let disposed = false;
|
|
252
190
|
const editor2 = createEditor({
|
|
253
|
-
nodes:
|
|
254
|
-
theme
|
|
191
|
+
nodes: usedLexicalNodes,
|
|
192
|
+
theme: lexicalTheme
|
|
255
193
|
});
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
194
|
+
editor2.update(() => {
|
|
195
|
+
importMdastTreeToLexical({
|
|
196
|
+
root: $getRoot(),
|
|
197
|
+
mdastRoot: { type: "root", children: [{ type: "paragraph", children: contents }] },
|
|
198
|
+
visitors: importVisitors
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
return editor2;
|
|
202
|
+
});
|
|
203
|
+
const saveAndFocus = React__default.useCallback(
|
|
204
|
+
(nextCell) => {
|
|
205
|
+
editor.getEditorState().read(() => {
|
|
262
206
|
const mdast = exportLexicalTreeToMdast({
|
|
263
207
|
root: $getRoot(),
|
|
264
208
|
jsxComponentDescriptors,
|
|
265
|
-
|
|
209
|
+
visitors: exportVisitors,
|
|
210
|
+
jsxIsAvailable
|
|
266
211
|
});
|
|
267
212
|
parentEditor.update(() => {
|
|
268
213
|
lexicalTable.updateCellContents(colIndex, rowIndex, mdast.children[0].children);
|
|
269
214
|
});
|
|
270
215
|
});
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
COMMAND_PRIORITY_CRITICAL
|
|
292
|
-
);
|
|
293
|
-
editor2.registerCommand(
|
|
294
|
-
BLUR_COMMAND,
|
|
295
|
-
(payload) => {
|
|
296
|
-
const relatedTarget = payload.relatedTarget;
|
|
297
|
-
if ((relatedTarget == null ? void 0 : relatedTarget.dataset["editorDialog"]) !== void 0 || (relatedTarget == null ? void 0 : relatedTarget.dataset["toolbarItem"]) !== void 0) {
|
|
216
|
+
setActiveCell(nextCell);
|
|
217
|
+
},
|
|
218
|
+
[colIndex, editor, exportVisitors, jsxComponentDescriptors, jsxIsAvailable, lexicalTable, parentEditor, rowIndex, setActiveCell]
|
|
219
|
+
);
|
|
220
|
+
React__default.useEffect(() => {
|
|
221
|
+
return mergeRegister(
|
|
222
|
+
editor.registerCommand(
|
|
223
|
+
KEY_TAB_COMMAND,
|
|
224
|
+
(payload) => {
|
|
225
|
+
payload.preventDefault();
|
|
226
|
+
const nextCell = payload.shiftKey ? [colIndex - 1, rowIndex] : [colIndex + 1, rowIndex];
|
|
227
|
+
saveAndFocus(nextCell);
|
|
228
|
+
return true;
|
|
229
|
+
},
|
|
230
|
+
COMMAND_PRIORITY_CRITICAL
|
|
231
|
+
),
|
|
232
|
+
editor.registerCommand(
|
|
233
|
+
FOCUS_COMMAND,
|
|
234
|
+
() => {
|
|
235
|
+
setActiveCell([colIndex, rowIndex]);
|
|
298
236
|
return false;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
237
|
+
},
|
|
238
|
+
COMMAND_PRIORITY_LOW
|
|
239
|
+
),
|
|
240
|
+
editor.registerCommand(
|
|
241
|
+
KEY_ENTER_COMMAND,
|
|
242
|
+
(payload) => {
|
|
243
|
+
payload == null ? void 0 : payload.preventDefault();
|
|
244
|
+
const nextCell = (payload == null ? void 0 : payload.shiftKey) ? [colIndex, rowIndex - 1] : [colIndex, rowIndex + 1];
|
|
245
|
+
saveAndFocus(nextCell);
|
|
246
|
+
return true;
|
|
247
|
+
},
|
|
248
|
+
COMMAND_PRIORITY_CRITICAL
|
|
249
|
+
),
|
|
250
|
+
editor.registerCommand(
|
|
251
|
+
BLUR_COMMAND,
|
|
252
|
+
(payload) => {
|
|
253
|
+
const relatedTarget = payload.relatedTarget;
|
|
254
|
+
if (isPartOftheEditorUI(relatedTarget, rootEditor.getRootElement())) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
saveAndFocus(null);
|
|
258
|
+
return true;
|
|
259
|
+
},
|
|
260
|
+
COMMAND_PRIORITY_CRITICAL
|
|
261
|
+
)
|
|
304
262
|
);
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
editor2.update(() => {
|
|
311
|
-
importMdastTreeToLexical({
|
|
312
|
-
root: $getRoot(),
|
|
313
|
-
mdastRoot: { type: "root", children: [{ type: "paragraph", children: contents }] },
|
|
314
|
-
visitors: markdownParseOptions.visitors
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
return editor2;
|
|
318
|
-
});
|
|
319
|
-
return /* @__PURE__ */ React__default.createElement(LexicalNestedComposer, { initialEditor: editor }, /* @__PURE__ */ React__default.createElement(RichTextPlugin, { contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, { autoFocus: true }), placeholder: /* @__PURE__ */ React__default.createElement("div", null), ErrorBoundary: LexicalErrorBoundary }), /* @__PURE__ */ React__default.createElement(SharedHistoryPlugin, null));
|
|
263
|
+
}, [colIndex, editor, rootEditor, rowIndex, saveAndFocus, setActiveCell]);
|
|
264
|
+
React__default.useEffect(() => {
|
|
265
|
+
focus && (editor == null ? void 0 : editor.focus());
|
|
266
|
+
}, [focus, editor]);
|
|
267
|
+
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));
|
|
320
268
|
};
|
|
321
269
|
const ColumnEditor = ({
|
|
322
270
|
parentEditor,
|
|
@@ -326,7 +274,7 @@ const ColumnEditor = ({
|
|
|
326
274
|
colIndex,
|
|
327
275
|
setActiveCellWithBoundaries
|
|
328
276
|
}) => {
|
|
329
|
-
const [editorRootElementRef] = useEmitterValues("editorRootElementRef");
|
|
277
|
+
const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
|
|
330
278
|
const insertColumnAt = React__default.useCallback(
|
|
331
279
|
(colIndex2) => {
|
|
332
280
|
parentEditor.update(() => {
|
|
@@ -392,7 +340,7 @@ const RowEditor = ({
|
|
|
392
340
|
rowIndex,
|
|
393
341
|
setActiveCellWithBoundaries
|
|
394
342
|
}) => {
|
|
395
|
-
const [editorRootElementRef] = useEmitterValues("editorRootElementRef");
|
|
343
|
+
const [editorRootElementRef] = corePluginHooks.useEmitterValues("editorRootElementRef");
|
|
396
344
|
const insertRowAt = React__default.useCallback(
|
|
397
345
|
(rowIndex2) => {
|
|
398
346
|
parentEditor.update(() => {
|
|
@@ -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 {};
|