@mdxeditor/editor 0.0.0-development
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/FormatConstants.d.ts +9 -0
- package/dist/FormatConstants.js +10 -0
- package/dist/MDXEditor.d.ts +92 -0
- package/dist/MDXEditor.js +142 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +17 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +28 -0
- package/dist/directive-editors/GenericDirectiveEditor.d.ts +8 -0
- package/dist/directive-editors/GenericDirectiveEditor.js +32 -0
- package/dist/exportMarkdownFromLexical.d.ts +133 -0
- package/dist/exportMarkdownFromLexical.js +202 -0
- package/dist/gurx/index.d.ts +3 -0
- package/dist/gurx/react.d.ts +152 -0
- package/dist/gurx/react.js +206 -0
- package/dist/gurx/realm.d.ts +148 -0
- package/dist/gurx/realm.js +489 -0
- package/dist/gurx/realmFactory.d.ts +79 -0
- package/dist/gurx/realmFactory.js +32 -0
- package/dist/icons/add_column.svg.js +5 -0
- package/dist/icons/add_photo.svg.js +5 -0
- package/dist/icons/add_row.svg.js +5 -0
- package/dist/icons/admonition.svg.js +5 -0
- package/dist/icons/arrow_drop_down.svg.js +5 -0
- package/dist/icons/check.svg.js +5 -0
- package/dist/icons/check_small.svg.js +5 -0
- package/dist/icons/close.svg.js +5 -0
- package/dist/icons/code.svg.js +5 -0
- package/dist/icons/code_block.svg.js +5 -0
- package/dist/icons/content_copy.svg.js +5 -0
- package/dist/icons/delete_big.svg.js +5 -0
- package/dist/icons/delete_small.svg.js +5 -0
- package/dist/icons/difference.svg.js +5 -0
- package/dist/icons/edit.svg.js +5 -0
- package/dist/icons/format_align_center.svg.js +5 -0
- package/dist/icons/format_align_left.svg.js +5 -0
- package/dist/icons/format_align_right.svg.js +5 -0
- package/dist/icons/format_bold.svg.js +5 -0
- package/dist/icons/format_italic.svg.js +5 -0
- package/dist/icons/format_list_bulleted.svg.js +7 -0
- package/dist/icons/format_list_checked.svg.js +5 -0
- package/dist/icons/format_list_numbered.svg.js +5 -0
- package/dist/icons/format_underlined.svg.js +5 -0
- package/dist/icons/frontmatter.svg.js +5 -0
- package/dist/icons/horizontal_rule.svg.js +5 -0
- package/dist/icons/insert_col_left.svg.js +5 -0
- package/dist/icons/insert_col_right.svg.js +5 -0
- package/dist/icons/insert_row_above.svg.js +5 -0
- package/dist/icons/insert_row_below.svg.js +5 -0
- package/dist/icons/link.svg.js +5 -0
- package/dist/icons/link_off.svg.js +5 -0
- package/dist/icons/markdown.svg.js +5 -0
- package/dist/icons/more_horiz.svg.js +5 -0
- package/dist/icons/more_vert.svg.js +5 -0
- package/dist/icons/open_in_new.svg.js +5 -0
- package/dist/icons/redo.svg.js +5 -0
- package/dist/icons/rich_text.svg.js +5 -0
- package/dist/icons/sandpack.svg.js +5 -0
- package/dist/icons/settings.svg.js +7 -0
- package/dist/icons/table.svg.js +5 -0
- package/dist/icons/undo.svg.js +5 -0
- package/dist/importMarkdownToLexical.d.ts +91 -0
- package/dist/importMarkdownToLexical.js +69 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +175 -0
- package/dist/jsx-editors/GenericJsxEditor.d.ts +8 -0
- package/dist/jsx-editors/GenericJsxEditor.js +56 -0
- package/dist/plugins/codeblock/CodeBlockNode.d.ts +100 -0
- package/dist/plugins/codeblock/CodeBlockNode.js +158 -0
- package/dist/plugins/codeblock/CodeBlockVisitor.d.ts +4 -0
- package/dist/plugins/codeblock/CodeBlockVisitor.js +14 -0
- package/dist/plugins/codeblock/MdastCodeVisitor.d.ts +3 -0
- package/dist/plugins/codeblock/MdastCodeVisitor.js +16 -0
- package/dist/plugins/codeblock/index.d.ts +697 -0
- package/dist/plugins/codeblock/index.js +73 -0
- package/dist/plugins/codemirror/CodeMirrorEditor.d.ts +3 -0
- package/dist/plugins/codemirror/CodeMirrorEditor.js +42 -0
- package/dist/plugins/codemirror/index.d.ts +912 -0
- package/dist/plugins/codemirror/index.js +62 -0
- package/dist/plugins/core/Icon.d.ts +6 -0
- package/dist/plugins/core/Icon.js +94 -0
- package/dist/plugins/core/LexicalLinebreakVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalLinebreakVisitor.js +10 -0
- package/dist/plugins/core/LexicalParagraphVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalParagraphVisitor.js +10 -0
- package/dist/plugins/core/LexicalRootVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalRootVisitor.js +10 -0
- package/dist/plugins/core/LexicalTextVisitor.d.ts +5 -0
- package/dist/plugins/core/LexicalTextVisitor.js +85 -0
- package/dist/plugins/core/MdastBreakVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastBreakVisitor.js +10 -0
- package/dist/plugins/core/MdastFormattingVisitor.d.ts +4 -0
- package/dist/plugins/core/MdastFormattingVisitor.js +36 -0
- package/dist/plugins/core/MdastInlineCodeVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastInlineCodeVisitor.js +27 -0
- package/dist/plugins/core/MdastParagraphVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastParagraphVisitor.js +15 -0
- package/dist/plugins/core/MdastRootVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastRootVisitor.js +9 -0
- package/dist/plugins/core/MdastTextVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastTextVisitor.js +10 -0
- package/dist/plugins/core/NestedLexicalEditor.d.ts +92 -0
- package/dist/plugins/core/NestedLexicalEditor.js +180 -0
- package/dist/plugins/core/PropertyPopover.d.ts +23 -0
- package/dist/plugins/core/PropertyPopover.js +39 -0
- package/dist/plugins/core/SharedHistoryPlugin.d.ts +2 -0
- package/dist/plugins/core/SharedHistoryPlugin.js +10 -0
- package/dist/plugins/core/index.d.ts +506 -0
- package/dist/plugins/core/index.js +420 -0
- package/dist/plugins/core/ui/DownshiftAutoComplete.d.ts +15 -0
- package/dist/plugins/core/ui/DownshiftAutoComplete.js +83 -0
- package/dist/plugins/core/ui/PopoverUtils.d.ts +4 -0
- package/dist/plugins/core/ui/PopoverUtils.js +17 -0
- package/dist/plugins/diff-source/DiffSourceWrapper.d.ts +4 -0
- package/dist/plugins/diff-source/DiffSourceWrapper.js +11 -0
- package/dist/plugins/diff-source/DiffViewer.d.ts +2 -0
- package/dist/plugins/diff-source/DiffViewer.js +59 -0
- package/dist/plugins/diff-source/SourceEditor.d.ts +4 -0
- package/dist/plugins/diff-source/SourceEditor.js +47 -0
- package/dist/plugins/diff-source/index.d.ts +635 -0
- package/dist/plugins/diff-source/index.js +57 -0
- package/dist/plugins/directives/DirectiveNode.d.ts +51 -0
- package/dist/plugins/directives/DirectiveNode.js +92 -0
- package/dist/plugins/directives/DirectiveVisitor.d.ts +4 -0
- package/dist/plugins/directives/DirectiveVisitor.js +10 -0
- package/dist/plugins/directives/MdastDirectiveVisitor.d.ts +3 -0
- package/dist/plugins/directives/MdastDirectiveVisitor.js +13 -0
- package/dist/plugins/directives/index.d.ts +683 -0
- package/dist/plugins/directives/index.js +53 -0
- package/dist/plugins/frontmatter/FrontmatterEditor.d.ts +6 -0
- package/dist/plugins/frontmatter/FrontmatterEditor.js +85 -0
- package/dist/plugins/frontmatter/FrontmatterNode.d.ts +35 -0
- package/dist/plugins/frontmatter/FrontmatterNode.js +71 -0
- package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.d.ts +4 -0
- package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.js +10 -0
- package/dist/plugins/frontmatter/MdastFrontmatterVisitor.d.ts +3 -0
- package/dist/plugins/frontmatter/MdastFrontmatterVisitor.js +10 -0
- package/dist/plugins/frontmatter/index.d.ts +627 -0
- package/dist/plugins/frontmatter/index.js +76 -0
- package/dist/plugins/headings/LexicalHeadingVisitor.d.ts +4 -0
- package/dist/plugins/headings/LexicalHeadingVisitor.js +11 -0
- package/dist/plugins/headings/MdastHeadingVisitor.d.ts +3 -0
- package/dist/plugins/headings/MdastHeadingVisitor.js +10 -0
- package/dist/plugins/headings/index.d.ts +617 -0
- package/dist/plugins/headings/index.js +69 -0
- package/dist/plugins/image/ImageDialog.d.ts +2 -0
- package/dist/plugins/image/ImageDialog.js +70 -0
- package/dist/plugins/image/ImageEditor.d.ts +10 -0
- package/dist/plugins/image/ImageEditor.js +227 -0
- package/dist/plugins/image/ImageNode.d.ts +65 -0
- package/dist/plugins/image/ImageNode.js +152 -0
- package/dist/plugins/image/ImageResizer.d.ts +18 -0
- package/dist/plugins/image/ImageResizer.js +214 -0
- package/dist/plugins/image/LexicalImageVisitor.d.ts +4 -0
- package/dist/plugins/image/LexicalImageVisitor.js +35 -0
- package/dist/plugins/image/MdastImageVisitor.d.ts +6 -0
- package/dist/plugins/image/MdastImageVisitor.js +87 -0
- package/dist/plugins/image/index.d.ts +714 -0
- package/dist/plugins/image/index.js +300 -0
- package/dist/plugins/jsx/LexicalJsxNode.d.ts +54 -0
- package/dist/plugins/jsx/LexicalJsxNode.js +102 -0
- package/dist/plugins/jsx/LexicalJsxVisitor.d.ts +4 -0
- package/dist/plugins/jsx/LexicalJsxVisitor.js +12 -0
- package/dist/plugins/jsx/MdastMdxJsEsmVisitor.d.ts +3 -0
- package/dist/plugins/jsx/MdastMdxJsEsmVisitor.js +8 -0
- package/dist/plugins/jsx/MdastMdxJsxElementVisitor.d.ts +3 -0
- package/dist/plugins/jsx/MdastMdxJsxElementVisitor.js +12 -0
- package/dist/plugins/jsx/index.d.ts +688 -0
- package/dist/plugins/jsx/index.js +78 -0
- package/dist/plugins/link/AutoLinkPlugin.d.ts +9 -0
- package/dist/plugins/link/AutoLinkPlugin.js +18 -0
- package/dist/plugins/link/LexicalLinkVisitor.d.ts +4 -0
- package/dist/plugins/link/LexicalLinkVisitor.js +10 -0
- package/dist/plugins/link/MdastLinkVisitor.d.ts +3 -0
- package/dist/plugins/link/MdastLinkVisitor.js +14 -0
- package/dist/plugins/link/index.d.ts +92 -0
- package/dist/plugins/link/index.js +33 -0
- package/dist/plugins/link-dialog/LinkDialog.d.ts +16 -0
- package/dist/plugins/link-dialog/LinkDialog.js +148 -0
- package/dist/plugins/link-dialog/index.d.ts +595 -0
- package/dist/plugins/link-dialog/index.js +260 -0
- package/dist/plugins/lists/LexicalListItemVisitor.d.ts +4 -0
- package/dist/plugins/lists/LexicalListItemVisitor.js +23 -0
- package/dist/plugins/lists/LexicalListVisitor.d.ts +4 -0
- package/dist/plugins/lists/LexicalListVisitor.js +13 -0
- package/dist/plugins/lists/MdastListItemVisitor.d.ts +3 -0
- package/dist/plugins/lists/MdastListItemVisitor.js +10 -0
- package/dist/plugins/lists/MdastListVisitor.d.ts +3 -0
- package/dist/plugins/lists/MdastListVisitor.js +20 -0
- package/dist/plugins/lists/index.d.ts +613 -0
- package/dist/plugins/lists/index.js +119 -0
- package/dist/plugins/markdown-shortcut/index.d.ts +71 -0
- package/dist/plugins/markdown-shortcut/index.js +90 -0
- package/dist/plugins/quote/LexicalQuoteVisitor.d.ts +4 -0
- package/dist/plugins/quote/LexicalQuoteVisitor.js +12 -0
- package/dist/plugins/quote/MdastBlockQuoteVisitor.d.ts +3 -0
- package/dist/plugins/quote/MdastBlockQuoteVisitor.js +10 -0
- package/dist/plugins/quote/index.d.ts +417 -0
- package/dist/plugins/quote/index.js +26 -0
- package/dist/plugins/sandpack/SandpackEditor.d.ts +7 -0
- package/dist/plugins/sandpack/SandpackEditor.js +37 -0
- package/dist/plugins/sandpack/index.d.ts +951 -0
- package/dist/plugins/sandpack/index.js +93 -0
- package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
- package/dist/plugins/sandpack/useCodeMirrorRef.js +96 -0
- package/dist/plugins/table/LexicalTableVisitor.d.ts +4 -0
- package/dist/plugins/table/LexicalTableVisitor.js +10 -0
- package/dist/plugins/table/MdastTableVisitor.d.ts +3 -0
- package/dist/plugins/table/MdastTableVisitor.js +10 -0
- package/dist/plugins/table/TableEditor.d.ts +21 -0
- package/dist/plugins/table/TableEditor.js +388 -0
- package/dist/plugins/table/TableNode.d.ts +52 -0
- package/dist/plugins/table/TableNode.js +152 -0
- package/dist/plugins/table/index.d.ts +614 -0
- package/dist/plugins/table/index.js +69 -0
- package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.d.ts +4 -0
- package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +10 -0
- package/dist/plugins/thematic-break/MdastThematicBreakVisitor.d.ts +3 -0
- package/dist/plugins/thematic-break/MdastThematicBreakVisitor.js +10 -0
- package/dist/plugins/thematic-break/index.d.ts +603 -0
- package/dist/plugins/thematic-break/index.js +39 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +6 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.js +54 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +5 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +33 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +6 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +30 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +7 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +32 -0
- package/dist/plugins/toolbar/components/CodeToggle.d.ts +6 -0
- package/dist/plugins/toolbar/components/CodeToggle.js +19 -0
- package/dist/plugins/toolbar/components/CreateLink.d.ts +6 -0
- package/dist/plugins/toolbar/components/CreateLink.js +20 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +18 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +25 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.js +29 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +7 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.js +20 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.js +24 -0
- package/dist/plugins/toolbar/components/InsertImage.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertImage.js +14 -0
- package/dist/plugins/toolbar/components/InsertSandpack.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertSandpack.js +13 -0
- package/dist/plugins/toolbar/components/InsertTable.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertTable.js +20 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.js +11 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +7 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +58 -0
- package/dist/plugins/toolbar/components/ListsToggle.d.ts +7 -0
- package/dist/plugins/toolbar/components/ListsToggle.js +23 -0
- package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +7 -0
- package/dist/plugins/toolbar/components/ShowSandpackInfo.js +31 -0
- package/dist/plugins/toolbar/components/UndoRedo.d.ts +5 -0
- package/dist/plugins/toolbar/components/UndoRedo.js +58 -0
- package/dist/plugins/toolbar/index.d.ts +492 -0
- package/dist/plugins/toolbar/index.js +40 -0
- package/dist/plugins/toolbar/primitives/DialogButton.d.ts +40 -0
- package/dist/plugins/toolbar/primitives/DialogButton.js +114 -0
- package/dist/plugins/toolbar/primitives/TooltipWrap.d.ts +8 -0
- package/dist/plugins/toolbar/primitives/TooltipWrap.js +12 -0
- package/dist/plugins/toolbar/primitives/select.d.ts +50 -0
- package/dist/plugins/toolbar/primitives/select.js +55 -0
- package/dist/plugins/toolbar/primitives/toolbar.d.ts +163 -0
- package/dist/plugins/toolbar/primitives/toolbar.js +115 -0
- package/dist/style.css +1715 -0
- package/dist/styles/globals.css.js +4 -0
- package/dist/styles/lexical-theme.module.css.js +62 -0
- package/dist/styles/lexicalTheme.d.ts +2 -0
- package/dist/styles/lexicalTheme.js +31 -0
- package/dist/styles/ui.module.css.js +308 -0
- package/dist/utils/detectMac.d.ts +3 -0
- package/dist/utils/detectMac.js +13 -0
- package/dist/utils/fp.d.ts +47 -0
- package/dist/utils/fp.js +14 -0
- package/dist/utils/isPartOftheEditorUI.d.ts +1 -0
- package/dist/utils/isPartOftheEditorUI.js +12 -0
- package/dist/utils/lexicalHelpers.d.ts +11 -0
- package/dist/utils/lexicalHelpers.js +62 -0
- package/dist/utils/uuid4.d.ts +1 -0
- package/dist/utils/uuid4.js +10 -0
- package/dist/utils/voidEmitter.d.ts +14 -0
- package/dist/utils/voidEmitter.js +15 -0
- package/package.json +435 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { coreSystem } from "../core/index.js";
|
|
2
|
+
import { MdastListVisitor } from "./MdastListVisitor.js";
|
|
3
|
+
import { MdastListItemVisitor } from "./MdastListItemVisitor.js";
|
|
4
|
+
import { LexicalListVisitor } from "./LexicalListVisitor.js";
|
|
5
|
+
import { LexicalListItemVisitor } from "./LexicalListItemVisitor.js";
|
|
6
|
+
import { $isListNode, ListNode, INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, INSERT_CHECK_LIST_COMMAND, REMOVE_LIST_COMMAND, ListItemNode, $getListDepth, $isListItemNode } from "@lexical/list";
|
|
7
|
+
import { $isRootOrShadowRoot, INDENT_CONTENT_COMMAND, COMMAND_PRIORITY_CRITICAL, $getSelection, $isRangeSelection, $isElementNode } from "lexical";
|
|
8
|
+
import { TabIndentationPlugin } from "@lexical/react/LexicalTabIndentationPlugin.js";
|
|
9
|
+
import { CheckListPlugin } from "@lexical/react/LexicalCheckListPlugin.js";
|
|
10
|
+
import { ListPlugin } from "@lexical/react/LexicalListPlugin.js";
|
|
11
|
+
import { $findMatchingParent, $getNearestNodeOfType } from "@lexical/utils";
|
|
12
|
+
import { gfmTaskListItem } from "micromark-extension-gfm-task-list-item";
|
|
13
|
+
import { gfmTaskListItemFromMarkdown, gfmTaskListItemToMarkdown } from "mdast-util-gfm-task-list-item";
|
|
14
|
+
import { system } from "../../gurx/realmFactory.js";
|
|
15
|
+
import { realmPlugin } from "../../gurx/react.js";
|
|
16
|
+
const ListTypeCommandMap = /* @__PURE__ */ new Map([
|
|
17
|
+
["number", INSERT_ORDERED_LIST_COMMAND],
|
|
18
|
+
["bullet", INSERT_UNORDERED_LIST_COMMAND],
|
|
19
|
+
["check", INSERT_CHECK_LIST_COMMAND],
|
|
20
|
+
["", REMOVE_LIST_COMMAND]
|
|
21
|
+
]);
|
|
22
|
+
const listsSystem = system(
|
|
23
|
+
(r, [{ activeEditor, currentSelection }]) => {
|
|
24
|
+
const currentListType = r.node("");
|
|
25
|
+
const applyListType = r.node();
|
|
26
|
+
r.sub(r.pipe(applyListType, r.o.withLatestFrom(activeEditor)), ([listType, theEditor]) => {
|
|
27
|
+
theEditor == null ? void 0 : theEditor.dispatchCommand(ListTypeCommandMap.get(listType), void 0);
|
|
28
|
+
});
|
|
29
|
+
r.sub(r.pipe(currentSelection, r.o.withLatestFrom(activeEditor)), ([selection, theEditor]) => {
|
|
30
|
+
if (!selection || !theEditor) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const anchorNode = selection.anchor.getNode();
|
|
34
|
+
let element = anchorNode.getKey() === "root" ? anchorNode : $findMatchingParent(anchorNode, (e) => {
|
|
35
|
+
const parent = e.getParent();
|
|
36
|
+
return parent !== null && $isRootOrShadowRoot(parent);
|
|
37
|
+
});
|
|
38
|
+
if (element === null) {
|
|
39
|
+
element = anchorNode.getTopLevelElementOrThrow();
|
|
40
|
+
}
|
|
41
|
+
const elementKey = element.getKey();
|
|
42
|
+
const elementDOM = theEditor.getElementByKey(elementKey);
|
|
43
|
+
if (elementDOM !== null) {
|
|
44
|
+
if ($isListNode(element)) {
|
|
45
|
+
const parentList = $getNearestNodeOfType(anchorNode, ListNode);
|
|
46
|
+
const type = parentList ? parentList.getListType() : element.getListType();
|
|
47
|
+
r.pub(currentListType, type);
|
|
48
|
+
} else {
|
|
49
|
+
r.pub(currentListType, null);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return { currentListType, applyListType };
|
|
54
|
+
},
|
|
55
|
+
[coreSystem]
|
|
56
|
+
);
|
|
57
|
+
const [
|
|
58
|
+
/** @internal */
|
|
59
|
+
listsPlugin,
|
|
60
|
+
/** @internal */
|
|
61
|
+
listsPluginHooks
|
|
62
|
+
] = realmPlugin({
|
|
63
|
+
id: "lists",
|
|
64
|
+
systemSpec: listsSystem,
|
|
65
|
+
init: (realm) => {
|
|
66
|
+
var _a;
|
|
67
|
+
realm.pubKey("addMdastExtension", gfmTaskListItemFromMarkdown);
|
|
68
|
+
realm.pubKey("addSyntaxExtension", gfmTaskListItem);
|
|
69
|
+
realm.pubKey("addImportVisitor", MdastListVisitor);
|
|
70
|
+
realm.pubKey("addImportVisitor", MdastListItemVisitor);
|
|
71
|
+
realm.pubKey("addLexicalNode", ListItemNode);
|
|
72
|
+
realm.pubKey("addLexicalNode", ListNode);
|
|
73
|
+
realm.pubKey("addExportVisitor", LexicalListVisitor);
|
|
74
|
+
realm.pubKey("addExportVisitor", LexicalListItemVisitor);
|
|
75
|
+
realm.pubKey("addToMarkdownExtension", gfmTaskListItemToMarkdown);
|
|
76
|
+
(_a = realm.getKeyValue("rootEditor")) == null ? void 0 : _a.registerCommand(INDENT_CONTENT_COMMAND, () => !isIndentPermitted(7), COMMAND_PRIORITY_CRITICAL);
|
|
77
|
+
realm.pubKey("addComposerChild", TabIndentationPlugin);
|
|
78
|
+
realm.pubKey("addComposerChild", ListPlugin);
|
|
79
|
+
realm.pubKey("addComposerChild", CheckListPlugin);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
function getElementNodesInSelection(selection) {
|
|
83
|
+
const nodesInSelection = selection.getNodes();
|
|
84
|
+
if (nodesInSelection.length === 0) {
|
|
85
|
+
return /* @__PURE__ */ new Set([selection.anchor.getNode().getParentOrThrow(), selection.focus.getNode().getParentOrThrow()]);
|
|
86
|
+
}
|
|
87
|
+
return new Set(nodesInSelection.map((n) => $isElementNode(n) ? n : n.getParentOrThrow()));
|
|
88
|
+
}
|
|
89
|
+
function isIndentPermitted(maxDepth) {
|
|
90
|
+
const selection = $getSelection();
|
|
91
|
+
if (!$isRangeSelection(selection)) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
const elementNodesInSelection = getElementNodesInSelection(selection);
|
|
95
|
+
let totalDepth = 0;
|
|
96
|
+
for (const elementNode of elementNodesInSelection) {
|
|
97
|
+
if ($isListNode(elementNode)) {
|
|
98
|
+
totalDepth = Math.max($getListDepth(elementNode) + 1, totalDepth);
|
|
99
|
+
} else if ($isListItemNode(elementNode)) {
|
|
100
|
+
const parent = elementNode.getParent();
|
|
101
|
+
if ((parent == null ? void 0 : parent.getChildren().length) === 1) {
|
|
102
|
+
const grandParentListItem = parent == null ? void 0 : parent.getParent();
|
|
103
|
+
if ($isListItemNode(grandParentListItem) && grandParentListItem.getChildren().length === 1) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (!$isListNode(parent)) {
|
|
108
|
+
throw new Error("ListMaxIndentLevelPlugin: A ListItemNode must have a ListNode for a parent.");
|
|
109
|
+
}
|
|
110
|
+
totalDepth = Math.max($getListDepth(parent) + 1, totalDepth);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return totalDepth <= maxDepth;
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
listsPlugin,
|
|
117
|
+
listsPluginHooks,
|
|
118
|
+
listsSystem
|
|
119
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { IconKey } from '../core/Icon';
|
|
2
|
+
import type { Options } from 'mdast-util-to-markdown';
|
|
3
|
+
import type { Config } from 'mdast-util-from-markdown/lib';
|
|
4
|
+
import type { Extension } from 'micromark-util-types';
|
|
5
|
+
import type { Content } from 'mdast';
|
|
6
|
+
import type { MdastImportVisitor, LexicalVisitor } from '../..';
|
|
7
|
+
import type { EditorSubscription, EditorInFocus, BlockType } from '../core';
|
|
8
|
+
import type { InitialEditorStateType } from '@lexical/react/LexicalComposer';
|
|
9
|
+
import type { JsxComponentDescriptor } from '../jsx';
|
|
10
|
+
import type { HistoryState } from '@lexical/history';
|
|
11
|
+
import type { PluginConstructor, SystemSpec, Realm, RealmNode } from '../../gurx';
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import type { LexicalEditor, RangeSelection, Klass, LexicalNode, TextFormatType, DecoratorNode, ElementNode } from 'lexical';
|
|
14
|
+
/** @internal */
|
|
15
|
+
export declare const markdownShortcutPlugin: PluginConstructor<SystemSpec<[SystemSpec<[], (r: Realm) => {
|
|
16
|
+
activeEditor: RealmNode<LexicalEditor | null>;
|
|
17
|
+
inFocus: RealmNode<boolean>;
|
|
18
|
+
historyState: RealmNode<HistoryState>;
|
|
19
|
+
currentSelection: RealmNode<RangeSelection | null>;
|
|
20
|
+
jsxIsAvailable: RealmNode<boolean>;
|
|
21
|
+
jsxComponentDescriptors: RealmNode<JsxComponentDescriptor[]>;
|
|
22
|
+
initialRootEditorState: RealmNode<InitialEditorStateType>;
|
|
23
|
+
rootEditor: RealmNode<LexicalEditor | null>;
|
|
24
|
+
createRootEditorSubscription: RealmNode<EditorSubscription>;
|
|
25
|
+
createActiveEditorSubscription: RealmNode<EditorSubscription>;
|
|
26
|
+
importVisitors: RealmNode<MdastImportVisitor<Content>[]>;
|
|
27
|
+
syntaxExtensions: RealmNode<Extension[]>;
|
|
28
|
+
mdastExtensions: RealmNode<(Partial<Config> | Partial<Config>[])[] | null | undefined>;
|
|
29
|
+
usedLexicalNodes: RealmNode<Klass<LexicalNode>[]>;
|
|
30
|
+
addImportVisitor: RealmNode<MdastImportVisitor<Content>>;
|
|
31
|
+
addLexicalNode: RealmNode<Klass<LexicalNode>>;
|
|
32
|
+
addSyntaxExtension: RealmNode<Extension>;
|
|
33
|
+
addMdastExtension: RealmNode<Partial<Config> | Partial<Config>[]>;
|
|
34
|
+
toMarkdownExtensions: RealmNode<Options[]>;
|
|
35
|
+
toMarkdownOptions: RealmNode<Options>;
|
|
36
|
+
addToMarkdownExtension: RealmNode<Options>;
|
|
37
|
+
addExportVisitor: RealmNode<LexicalVisitor>;
|
|
38
|
+
exportVisitors: RealmNode<LexicalVisitor[]>;
|
|
39
|
+
initialMarkdown: RealmNode<string>;
|
|
40
|
+
setMarkdown: RealmNode<string>;
|
|
41
|
+
markdown: RealmNode<string>;
|
|
42
|
+
editorRootElementRef: RealmNode<React.RefObject<HTMLDivElement> | null>;
|
|
43
|
+
contentEditableClassName: RealmNode<string>;
|
|
44
|
+
placeholder: RealmNode<React.ReactNode>;
|
|
45
|
+
autoFocus: RealmNode<boolean | {
|
|
46
|
+
defaultSelection?: "rootStart" | "rootEnd" | undefined;
|
|
47
|
+
preventScroll?: boolean | undefined;
|
|
48
|
+
}>;
|
|
49
|
+
readOnly: RealmNode<boolean>;
|
|
50
|
+
composerChildren: RealmNode<React.ComponentType<{}>[]>;
|
|
51
|
+
addComposerChild: RealmNode<React.ComponentType<{}>>;
|
|
52
|
+
topAreaChildren: RealmNode<React.ComponentType<{}>[]>;
|
|
53
|
+
addTopAreaChild: RealmNode<React.ComponentType<{}>>;
|
|
54
|
+
nestedEditorChildren: RealmNode<React.ComponentType<{}>[]>;
|
|
55
|
+
addNestedEditorChild: RealmNode<React.ComponentType<{}>>;
|
|
56
|
+
editorWrappers: RealmNode<React.ComponentType<{
|
|
57
|
+
children: React.ReactNode;
|
|
58
|
+
}>[]>;
|
|
59
|
+
addEditorWrapper: RealmNode<React.ComponentType<{
|
|
60
|
+
children: React.ReactNode;
|
|
61
|
+
}>>;
|
|
62
|
+
currentFormat: RealmNode<number>;
|
|
63
|
+
editorInFocus: RealmNode<EditorInFocus | null>;
|
|
64
|
+
applyFormat: RealmNode<TextFormatType>;
|
|
65
|
+
currentBlockType: RealmNode<BlockType>;
|
|
66
|
+
applyBlockType: RealmNode<BlockType>;
|
|
67
|
+
convertSelectionToNode: RealmNode<() => ElementNode>;
|
|
68
|
+
insertDecoratorNode: RealmNode<() => DecoratorNode<unknown>>;
|
|
69
|
+
onBlur: RealmNode<FocusEvent>;
|
|
70
|
+
iconComponentFor: RealmNode<(name: IconKey) => React.ReactNode>;
|
|
71
|
+
}>], (_: Realm) => {}>, object>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { QUOTE, LINK, ORDERED_LIST, UNORDERED_LIST, CHECK_LIST, CODE, BOLD_ITALIC_STAR, BOLD_ITALIC_UNDERSCORE, BOLD_STAR, BOLD_UNDERSCORE, INLINE_CODE, ITALIC_STAR, ITALIC_UNDERSCORE } from "@lexical/markdown";
|
|
2
|
+
import { MarkdownShortcutPlugin } from "@lexical/react/LexicalMarkdownShortcutPlugin.js";
|
|
3
|
+
import React__default from "react";
|
|
4
|
+
import { CodeBlockNode, $createCodeBlockNode } from "../codeblock/CodeBlockNode.js";
|
|
5
|
+
import { coreSystem } from "../core/index.js";
|
|
6
|
+
import { HeadingNode, $isHeadingNode, $createHeadingNode } from "@lexical/rich-text";
|
|
7
|
+
import { realmPlugin } from "../../gurx/react.js";
|
|
8
|
+
import { system } from "../../gurx/realmFactory.js";
|
|
9
|
+
const [markdownShortcutPlugin] = realmPlugin({
|
|
10
|
+
id: "markdown-shortcut",
|
|
11
|
+
dependencies: [],
|
|
12
|
+
systemSpec: system((_) => ({}), [coreSystem]),
|
|
13
|
+
init: (realm, _, pluginIds) => {
|
|
14
|
+
const allowedHeadingLevels = pluginIds.includes("headings") ? (
|
|
15
|
+
// @ts-expect-error we query the realm for the allowed heading levels
|
|
16
|
+
realm.getKeyValue("allowedHeadingLevels")
|
|
17
|
+
) : [];
|
|
18
|
+
const transformers = pickTransformersForActivePlugins(pluginIds, allowedHeadingLevels);
|
|
19
|
+
realm.pubKey("addComposerChild", () => /* @__PURE__ */ React__default.createElement(MarkdownShortcutPlugin, { transformers }));
|
|
20
|
+
realm.pubKey("addNestedEditorChild", () => /* @__PURE__ */ React__default.createElement(MarkdownShortcutPlugin, { transformers }));
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const createBlockNode = (createNode) => {
|
|
24
|
+
return (parentNode, children, match) => {
|
|
25
|
+
const node = createNode(match);
|
|
26
|
+
node.append(...children);
|
|
27
|
+
parentNode.replace(node);
|
|
28
|
+
node.select(0, 0);
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
function pickTransformersForActivePlugins(pluginIds, allowedHeadingLevels) {
|
|
32
|
+
const transformers = [
|
|
33
|
+
BOLD_ITALIC_STAR,
|
|
34
|
+
BOLD_ITALIC_UNDERSCORE,
|
|
35
|
+
BOLD_STAR,
|
|
36
|
+
BOLD_UNDERSCORE,
|
|
37
|
+
INLINE_CODE,
|
|
38
|
+
ITALIC_STAR,
|
|
39
|
+
ITALIC_UNDERSCORE
|
|
40
|
+
// HIGHLIGHT,
|
|
41
|
+
// STRIKETHROUGH
|
|
42
|
+
];
|
|
43
|
+
if (pluginIds.includes("headings")) {
|
|
44
|
+
const minHeadingLevel = Math.min(...allowedHeadingLevels);
|
|
45
|
+
const maxHeadingLevel = Math.max(...allowedHeadingLevels);
|
|
46
|
+
const headingRegExp = new RegExp(`^(#{${minHeadingLevel},${maxHeadingLevel}})\\s`);
|
|
47
|
+
const HEADING = {
|
|
48
|
+
dependencies: [HeadingNode],
|
|
49
|
+
export: (node, exportChildren) => {
|
|
50
|
+
if (!$isHeadingNode(node)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const level = Number(node.getTag().slice(1));
|
|
54
|
+
return "#".repeat(level) + " " + exportChildren(node);
|
|
55
|
+
},
|
|
56
|
+
regExp: headingRegExp,
|
|
57
|
+
replace: createBlockNode((match) => {
|
|
58
|
+
const tag = `h${match[1].length}`;
|
|
59
|
+
return $createHeadingNode(tag);
|
|
60
|
+
}),
|
|
61
|
+
type: "element"
|
|
62
|
+
};
|
|
63
|
+
transformers.push(HEADING);
|
|
64
|
+
}
|
|
65
|
+
if (pluginIds.includes("quote")) {
|
|
66
|
+
transformers.push(QUOTE);
|
|
67
|
+
}
|
|
68
|
+
if (pluginIds.includes("link")) {
|
|
69
|
+
transformers.push(LINK);
|
|
70
|
+
}
|
|
71
|
+
if (pluginIds.includes("lists")) {
|
|
72
|
+
transformers.push(ORDERED_LIST, UNORDERED_LIST, CHECK_LIST);
|
|
73
|
+
}
|
|
74
|
+
if (pluginIds.includes("codeblock")) {
|
|
75
|
+
const codeTransformerCopy = {
|
|
76
|
+
...CODE,
|
|
77
|
+
dependencies: [CodeBlockNode],
|
|
78
|
+
replace: (parentNode, _children, match) => {
|
|
79
|
+
const codeBlockNode = $createCodeBlockNode({ code: "", language: match ? match[1] : "", meta: "" });
|
|
80
|
+
parentNode.replace(codeBlockNode);
|
|
81
|
+
setTimeout(() => codeBlockNode.select(), 80);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
transformers.push(codeTransformerCopy);
|
|
85
|
+
}
|
|
86
|
+
return transformers;
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
markdownShortcutPlugin
|
|
90
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { $isQuoteNode } from "@lexical/rich-text";
|
|
2
|
+
const LexicalQuoteVisitor = {
|
|
3
|
+
testLexicalNode: $isQuoteNode,
|
|
4
|
+
visitLexicalNode: ({ lexicalNode, mdastParent, actions }) => {
|
|
5
|
+
const paragraph = { type: "paragraph", children: [] };
|
|
6
|
+
actions.appendToParent(mdastParent, { type: "blockquote", children: [paragraph] });
|
|
7
|
+
actions.visitChildren(lexicalNode, paragraph);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
LexicalQuoteVisitor
|
|
12
|
+
};
|